The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(browser): orphan reaper binds only on the full socket-dir path, never its basename
teknium1f2f70bed7afa
diff --git a/tests/tools/test_browser_orphan_reaper.py b/tests/tools/test_browser_orphan_reaper.pyindex 429863b7390..c0c2254905a 100644--- a/tests/tools/test_browser_orphan_reaper.py+++ b/tests/tools/test_browser_orphan_reaper.py@@ -371,6 +371,27 @@ class TestReaperIdentityGuard:)assert self._run(proc, socket_dir) is False+ def test_recycled_pid_carrying_only_socket_dir_basename_is_refused(self):+ """The socket-dir BASENAME anywhere in argv is not a binding (#116884).++ `agent-browser-<session>` is predictable, so a recycled PID whose argv merely+ mentions it (a grep, a shell) must not pass the binding gate; only the full+ normalized path as an argv token (or the environ match) binds.+ """+ socket_dir = "/tmp/agent-browser-h_sess123456"+ proc = self._FakeProc(+ name="bash",+ cmdline=["grep", "agent-browser-h_sess123456", "/var/log/syslog"],+ environ={},+ )+ assert self._run(proc, socket_dir) is False+ # Control: the full path as a `--flag=value` token still binds.+ bound = self._FakeProc(+ name="agent-browser",+ cmdline=["agent-browser", "daemon", f"--socket-dir={socket_dir}/"],+ )+ assert self._run(bound, socket_dir) is True+def test_planted_pid_survives_full_reaper_path(self, fake_tmpdir):"""End-to-end through the reaper: a planted non-browser PID is spared.diff --git a/tools/browser_tool_lifecycle.py b/tools/browser_tool_lifecycle.pyindex b8b2793bed4..af90d150578 100644--- a/tools/browser_tool_lifecycle.py+++ b/tools/browser_tool_lifecycle.py@@ -196,6 +196,13 @@ def _write_owner_pid(socket_dir: str, session_name: str) -> None:_bt.logger.debug("Could not write owner_pid file for %s: %s", session_name, exc)+def _argv_token_is_path(token: str, path: str) -> bool:+ """True when ``token`` (or its ``--flag=VALUE`` value) names exactly ``path``."""+ want = os.path.normpath(path).lower()+ candidate = token.split("=", 1)[1] if token.startswith("-") and "=" in token else token+ return bool(candidate) and os.path.normpath(candidate).lower() == want++def _verify_reapable_browser_daemon(daemon_pid: int, socket_dir: str,session_name: str) -> bool:"""Confirm a live PID is genuinely *this* session's agent-browser daemon (fail-closed).@@ -218,7 +225,8 @@ def _verify_reapable_browser_daemon(daemon_pid: int, socket_dir: str,try:proc = psutil.Process(daemon_pid)name = (proc.name() or "").lower()- cmdline = " ".join(proc.cmdline() or []).lower()+ argv = list(proc.cmdline() or [])+ cmdline = " ".join(argv).lower()except psutil.NoSuchProcess:return False # vanished between the liveness check and nowexcept (psutil.AccessDenied, OSError) as exc:@@ -227,9 +235,10 @@ def _verify_reapable_browser_daemon(daemon_pid: int, socket_dir: str,if "agent-browser" not in name and "agent-browser" not in cmdline:return refuse("not an agent-browser process (name=%r)", name)- socket_dir_l = socket_dir.lower()- socket_base_l = os.path.basename(socket_dir).lower()- bound = socket_dir_l in cmdline or (socket_base_l and socket_base_l in cmdline)+ # Binding must be the FULL socket-dir path as an argv token (bare or `--flag=path`),+ # never a substring: the dir basename is predictable (`agent-browser-<session>`), so a+ # recycled PID running e.g. `grep agent-browser-h_x ...` would pass a basename check.+ bound = any(_argv_token_is_path(tok, socket_dir) for tok in argv)if not bound:try:env_dir = (proc.environ() or {}).get("AGENT_BROWSER_SOCKET_DIR", "")