Repository navigation
Conversation
92e630a to
05d91fa
Compare
05d91fa to
8626312
Compare
| half_started_context_manager = self._playwright_context_manager | ||
| self._playwright_context_manager = async_playwright() | ||
| try: | ||
| await half_started_context_manager.__aexit__(None, None, None) |
There was a problem hiding this comment.
Important: This stop has no time limit. The pool runs __aenter__ under asyncio.wait_for(..., operation_timeout), and wait_for can't raise until this rollback finishes. With a driver that doesn't exit when stdin closes, the pool entry now hangs. On v2 it logs "timed out, will be skipped" after operation_timeout (reproduced with a fake driver and a 1 s timeout). Could the stop get its own timeout, here and in StagehandBrowserPlugin.__aenter__?
✍️ Drafted by Claude Code
| self._playwright_context_manager = async_playwright() | ||
| try: | ||
| await half_started_context_manager.__aexit__(None, None, None) | ||
| except Exception: |
There was a problem hiding this comment.
Note: When the driver never spawned (a missing executable, or a cancel right after the start), __aexit__ fails with AttributeError: 'PipeTransport' object has no attribute '_output'. Users then get this warning and a second traceback next to the real error. In the early-cancel case the driver still starts later and keeps running. Maybe log this at DEBUG, and narrow the comment above, since the driver isn't always stopped.
✍️ Drafted by Claude Code
|
|
||
| try: | ||
| self._playwright = await self._playwright_context_manager.__aenter__() | ||
| except BaseException: |
There was a problem hiding this comment.
Suggestion: __aexit__ now always resets the state, so the rollback could be try: await self.__aexit__(None, None, None) except Exception: logger.warning(...). That removes the near copy in the Stagehand plugin, where the variable name already differs, and the timeout from the comment below would live in one place.
✍️ Drafted by Claude Code
| failures: list[BaseException] = [] | ||
| try: | ||
| try: | ||
| await self._stop_recurring_tasks() |
There was a problem hiding this comment.
Note: If _stop_recurring_tasks() is cancelled, no browser is closed, but the finally still clears both lists and marks the pool inactive. The browsers are then lost, with their persistent temp directories. Could the browser closes run in a finally after the task stop?
✍️ Drafted by Claude Code
| for plugin in self._plugins: | ||
| await plugin.__aexit__(exc_type, exc_value, exc_traceback) | ||
| try: | ||
| # Plugins left inactive by a timed-out entry have nothing to exit. |
There was a problem hiding this comment.
Nit: This also skips the plugins after a timed-out one, which were never entered, since the except TimeoutError ends the loop. Keeping entered_plugins on self and exiting exactly those would make this explicit.
✍️ Drafted by Claude Code
| ], | ||
| ) | ||
| async def test_failed_enter_stops_playwright(monkeypatch: pytest.MonkeyPatch, error: BaseException) -> None: | ||
| """A plugin whose Stagehand client fails to start stops Playwright and can be entered again.""" |
There was a problem hiding this comment.
Nit: The test covers the cancelled case too.
| """A plugin whose Stagehand client fails to start stops Playwright and can be entered again.""" | |
| """A plugin whose Stagehand client fails to start or is cancelled stops Playwright and can be entered again.""" |
✍️ Drafted by Claude Code
Description
BrowserPool,PlaywrightBrowserPluginorStagehandBrowserPluginleaves it inactive, so it can be entered again. A pool whose entry fails exits the plugins it already entered, and a plugin whose entry fails stops the Playwright driver it started.Issues
Testing
✍️ Drafted by Claude Code