Skip to content

fix(interactive_browser): close remote browsers when the server shuts down - #5982

Merged
ananthsub merged 2 commits into
mainfrom
ananthsub/interactive-browser-shutdown
Nov 13, 2026
Merged

ananthsub merged 2 commits into
mainfrom
ananthsub/interactive-browser-shutdown

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Fixes #5979.

interactive_browser had no shutdown hook. When the server process exited, the browsers it held stayed open. For the remote_cdp backend with the lexmount provider, that means remote browsers kept running until the provider ended them. The server requires num_workers: 1, so the case is the single server process stopping.

  • setup_webserver now wraps app.router.lifespan_context, the same way swebench_pro and officeqa stop their sandboxes, and calls a new shutdown() when the server stops.
  • shutdown() closes every browser the process still holds, local and remote, all at once. Each close goes through the existing release path, which logs a failed close instead of raising, so one failure does not stop the others.
  • Each step of a close now has its own limit: 10 seconds for each of the page, context and browser closes over CDP and for stopping Playwright. A dead CDP endpoint used to be able to hang the close, and with it verify, a re-seed or shutdown, before the provider release ran. The provider release keeps its own limits; Lexmount allows 30 seconds for each of its two calls.
  • No limit covers a whole close. A limit around the provider release could cancel it after session.close and before sessions.delete, the call that ends the Lexmount session, which would bring the leak back exactly when the service is slow.
  • Gym's launcher sends SIGINT and kills the server after server_shutdown_timeout_seconds, which defaults to 1 second. A remote close can take up to about 100 seconds when the provider is slow. The README now explains this and gives an example value for remote backends, and the module docstring points to it.

Validation

  • New tests stop the server through its lifespan:
    • a held remote CDP browser with a fake provider is ended at the provider;
    • a provider release slower than any short limit still finishes for every held browser;
    • a browser whose close fails is logged and does not keep the other browser open.
  • A new backend test checks that a CDP close step that never returns is cut off and the provider session is still released.
  • Each new test fails against the code it guards: the shutdown tests without the lifespan hook, the slow-release test with a short limit around the whole close, and the hung-step test without the per-step limit.
  • One existing MCP test read server state after its test client had shut the server down. Its assertions now run while the server is still up.
  • The server's full test suite passes in its own venv (uv sync in resources_servers/interactive_browser, then pytest tests).
  • pre-commit run --files passes on the changed files.

Rollout evidence

N/A: this change only adds cleanup when the server shuts down and limits on teardown steps. It does not touch the agent, the tools or how episodes are scored.

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 11, 2026 00:01
@ananthsub ananthsub changed the title fix(interactive_browser): close remote browsers when a worker shuts down fix(interactive_browser): close remote browsers when the server shuts down Nov 11, 2026
@yaoyu-33
yaoyu-33 requested a review from Glorf November 11, 2026 00:31
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 12, 2026
The server had no shutdown hook, so a process that exited, or one uvicorn
worker that stopped, left the remote browsers it held open until the
provider ended them. Chain a lifespan in setup_webserver that closes every
browser the process still holds, local and remote. Browsers close
concurrently, each bounded by a timeout; a failed or stuck close is logged
and does not stop the others.

Closes #5979

Signed-off-by: Ananth Subramaniam <[email protected]>
…e close

A limit around the whole close could cancel the provider release partway,
so a slow Lexmount close skipped the delete that ends the session. Bound
each CDP teardown step instead, which also keeps a dead endpoint from
hanging verify or a re-seed, and let the provider release run under its
own limits.

Document that Gym's launcher kills a server one second after SIGINT by
default, and how long to allow a remote browser to close.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/interactive-browser-shutdown branch from f0a9c89 to d0e58f9 Compare November 13, 2026 18:28
@ananthsub
ananthsub merged commit b4f6a0d into main Nov 13, 2026
61 checks passed
@ananthsub
ananthsub deleted the ananthsub/interactive-browser-shutdown branch November 13, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(interactive_browser): close remote browsers when a worker shuts down

1 participant