The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(browser): a timed-out sandbox exec no longer crashes the browser start or stop
Teknium60706f14c97a
diff --git a/tests/tools/test_browser_cleanup.py b/tests/tools/test_browser_cleanup.pyindex c9e5d34e26d..764e657de3f 100644--- a/tests/tools/test_browser_cleanup.py+++ b/tests/tools/test_browser_cleanup.py@@ -380,6 +380,22 @@ class TestSandboxBrowserOwnership:assert fake_sandbox.killed == [4242]assert browser_session_sandbox._launched == {}+ def test_a_timed_out_port_wait_is_a_readiness_failure(self, fake_sandbox, monkeypatch):+ from tools import browser_session_sandbox+ from tools.browser_session_sandbox import create_sandbox_session+ fake_sandbox.timeouts.add("cat")+ monkeypatch.setattr(browser_session_sandbox, "_LAUNCH_TIMEOUT_S", 0.01)+ with pytest.raises(RuntimeError, match="did not expose a DevTools endpoint"):+ create_sandbox_session("task-A")+ assert fake_sandbox.killed == [4242]++ def test_a_timed_out_stop_does_not_crash_the_teardown(self, fake_sandbox, isolated_sessions):+ from tools.browser_session_sandbox import create_sandbox_session+ isolated_sessions["task-A"] = create_sandbox_session("task-A")+ fake_sandbox.timeouts.add("kill")+ lifecycle.cleanup_single_session("task-A")+ assert "task-A" not in isolated_sessions+def test_sessions_racing_onto_one_container_launch_one_browser(self, fake_sandbox):from tools.browser_session_sandbox import create_sandbox_sessionfake_sandbox.probe_barrier = threading.Barrier(2)diff --git a/tools/browser_session_sandbox.py b/tools/browser_session_sandbox.pyindex fa007d32fb8..2d8bc135ea2 100644--- a/tools/browser_session_sandbox.py+++ b/tools/browser_session_sandbox.py@@ -113,7 +113,10 @@ def _start_chromium(env, user, exe: str, udd: str, child_env: dict) -> int:def _wait_for_port(env, user, udd: str) -> tuple[int, str]:deadline = time.monotonic() + _LAUNCH_TIMEOUT_Swhile time.monotonic() < deadline:- found = _read_devtools(env, user, udd)+ try:+ found = _read_devtools(env, user, udd)+ except subprocess.TimeoutExpired:+ found = None # one slow exec is another not-ready answer; the deadline decides readinessif found:return foundtime.sleep(0.5)@@ -227,5 +230,5 @@ def _stop_launched(key: str) -> None:env, pid = launchedtry:streams.run_in(env, ["kill", "-TERM", str(int(pid))], user=sandbox_host._user_for(env), timeout=15)- except (OSError, RuntimeError) as exc:+ except (OSError, RuntimeError, subprocess.TimeoutExpired) as exc:logger.debug("sandbox browser stop for pid %s failed: %s", pid, exc)