The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(browser): Windows still stops its harness daemons at exit; a known agent-browser pid is still a group leader
kshitijk4pooraae69cfaf41d
diff --git a/plugins/web/ddgs/provider.py b/plugins/web/ddgs/provider.pyindex c96061c85ff..63f6ee73534 100644--- a/plugins/web/ddgs/provider.py+++ b/plugins/web/ddgs/provider.py@@ -110,7 +110,7 @@ def _spawn_worker(env: dict[str, str]) -> subprocess.Popen:env["PYTHONPATH"] = path_entry + os.pathsep + child_pythonpath if child_pythonpath else path_entryworker_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "_search_worker.py")# Own process group/session so terminate/kill also reach a hung primp grandchild.- # detached-spawn: ok — awaited under a 30 s cap that kills its group; an owner killed mid-search leaves it to finish that one search+ # detached-spawn: ok — awaited under a 30 s cap that kills its group; an owner killed mid-search leaves it running until that search returns (unbounded if primp hangs)extra_kwargs: dict[str, Any] = {"creationflags": subprocess.CREATE_NEW_PROCESS_GROUP} if sys.platform == "win32" else {"start_new_session": True}# stdin/stdout/stderr stay explicit keyword args so scripts/check_subprocess_stdin.py sees them# (TUI gateway inherits stdin). stderr=DEVNULL: a chatty child would deadlock a stdout-only drain.diff --git a/tests/tools/test_browser_use_cli_owned_daemon.py b/tests/tools/test_browser_use_cli_owned_daemon.pyindex 4f33c4093da..c98525714d0 100644--- a/tests/tools/test_browser_use_cli_owned_daemon.py+++ b/tests/tools/test_browser_use_cli_owned_daemon.py@@ -22,7 +22,7 @@ from tools import browser_use_clidef _group_alive(pgid: int) -> bool:try:os.killpg(pgid, 0) # windows-footgun: ok — posix-marked test- except ProcessLookupError:+ except (ProcessLookupError, PermissionError): # macOS: EPERM for a group left with only zombiesreturn Falsereturn True@@ -92,10 +92,12 @@ def test_an_owned_harness_daemon_is_not_re_verified_and_a_replacement_releases_tbrowser_use_cli._own_harness_daemon(env) # steady state: one pid-file readassert registered == [("register", [proc.pid])]- browser_use_cli._owned_daemon_groups[browser_use_cli.daemon_identity(env)] = 4242 # an earlier daemon+ earlier = subprocess.Popen([sys.executable, "-c", ""], stdin=subprocess.DEVNULL, start_new_session=True)+ earlier.wait(timeout=10) # an earlier daemon of this identity, gone: its group is empty+ browser_use_cli._owned_daemon_groups[browser_use_cli.daemon_identity(env)] = earlier.pidmonkeypatch.setattr(browser_use_cli, "spawned_by_this_process", lambda pid: True)browser_use_cli._own_harness_daemon(env)- assert registered[1:] == [("register", [proc.pid]), ("unregister", [4242])]+ assert registered[1:] == [("register", [proc.pid]), ("unregister", [earlier.pid])]def test_a_pid_file_naming_something_else_is_never_registered(tmp_path, registered):@@ -148,7 +150,6 @@ def test_the_exit_path_stops_only_the_daemons_this_process_owns(monkeypatch, regmonkeypatch.setattr(browser_tool_lifecycle._real_profile, "_terminate_real_profile_chrome", lambda: None)browser_tool_lifecycle._emergency_cleanup_all_sessions() # the atexit handler-assert reloaded == ["ours"]assert browser_use_cli._driven_daemons == {theirs: "home"}@@ -188,7 +189,7 @@ def test_a_sigkilled_owner_takes_its_harness_daemon_with_it(tmp_path):if daemon_pid is not None:try:os.killpg(daemon_pid, 9) # windows-footgun: ok — posix-marked test- except ProcessLookupError:+ except (ProcessLookupError, PermissionError):passif owner.poll() is None:owner.kill()diff --git a/tests/tools/test_mcp_stdio_init_timeout.py b/tests/tools/test_mcp_stdio_init_timeout.pyindex ef5892924a5..bcdbe2de248 100644--- a/tests/tools/test_mcp_stdio_init_timeout.py+++ b/tests/tools/test_mcp_stdio_init_timeout.py@@ -75,7 +75,6 @@ class TestStdioInitializeTimeout:patch.object(mcp_tool, "ClientSession", _fake_client_session), \patch.object(_mcp_config, "_resolve_stdio_command", lambda c, e: (c, e)), \patch.object(_mcp_config, "_write_stderr_log_header", lambda *_a, **_k: None), \- patch.object(mcp_tool, "_get_mcp_stderr_log", lambda: None), \patch("tools.osv_check.check_package_for_malware",lambda *_a, **_k: None):start = time.monotonic()diff --git a/tools/browser_use_cli.py b/tools/browser_use_cli.pyindex 64368bd93ea..878f153b420 100644--- a/tools/browser_use_cli.py+++ b/tools/browser_use_cli.py@@ -637,8 +637,12 @@ def stop_harness_daemons(home_key: Optional[str] = None) -> None:def stop_owned_harness_daemons() -> None:"""Stop only the harness daemons this process owns (``_owned_daemon_groups``: started by its own- commands). The exit path uses this: a daemon another live Hermes started on the same name was- driven here too, but it is that Hermes's to stop."""+ commands). The exit handler uses this: a daemon another live Hermes started on the same name was+ driven here too, but it is that Hermes's to stop. Windows records no ownership (``_own_harness_daemon``+ is POSIX-only), so there every driven daemon is stopped, as before."""+ if os.name != "posix":+ stop_harness_daemons()+ returnwith _owned_daemon_groups_lock:owned = sorted(_owned_daemon_groups)with _driven_daemons_lock: