The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(browser): an unscoped thread on a multiplexed gateway never resolves the launch profile's live CDP endpoint
Tekniumbf9dbbe53b8e
diff --git a/tests/tools/test_browser_profile_scope_edges.py b/tests/tools/test_browser_profile_scope_edges.pynew file mode 100644index 00000000000..438f7b4543a--- /dev/null+++ b/tests/tools/test_browser_profile_scope_edges.py@@ -0,0 +1,51 @@+"""GW-23 (#134889): per-profile browser scope edges left after CLI-9.++A multiplexed gateway serves every profile from one process; a live ``/browser connect`` endpoint,+a harness daemon's runtime and tmp dirs, and a browser session belong to ONE profile.+"""+import threading++import pytest++from agent import secret_scope+from gateway.run import _profile_runtime_scope+from hermes_constants import get_hermes_home, hermes_home_key+from tools import browser_tool_cdp as bt_cdp+++def profiles(tmp_path, monkeypatch):+ a, b = tmp_path / "a", tmp_path / "b"+ a.mkdir()+ b.mkdir()+ monkeypatch.delenv("BROWSER_CDP_URL", raising=False)+ monkeypatch.setattr(bt_cdp, "_live_overrides", {})+ return a, b+++def _in_bare_thread(fn):+ """Run ``fn`` on a stdlib thread started WITHOUT the caller's copied context."""+ out = {}+ t = threading.Thread(target=lambda: out.setdefault("v", fn()))+ t.start()+ t.join(5)+ return out["v"]+++def test_a_bare_thread_on_a_multiplexed_gateway_never_resolves_the_launch_profiles_override(profiles, monkeypatch):+ """No profile scope bound on a multiplexed gateway: the launch profile's live endpoint is NOT the+ answer (``get_secret`` fails closed the same way). A bound scope still sees its own."""+ launch = get_hermes_home()+ with _profile_runtime_scope(launch, hydrate_secrets=False):+ bt_cdp.set_live_cdp_override("http://127.0.0.1:9401")+ monkeypatch.setattr(secret_scope, "_MULTIPLEX_ACTIVE", True)+ assert _in_bare_thread(bt_cdp.live_cdp_override) == ""+ assert _in_bare_thread(bt_cdp._get_cdp_override_raw) == ""+ with _profile_runtime_scope(launch, hydrate_secrets=False):+ assert bt_cdp.live_cdp_override() == "http://127.0.0.1:9401"+++def test_single_profile_bare_thread_keeps_the_process_override(profiles):+ bt_cdp.set_live_cdp_override("http://127.0.0.1:9402")+ assert _in_bare_thread(bt_cdp.live_cdp_override) == "http://127.0.0.1:9402"+ assert hermes_home_key() in bt_cdp._live_overridesdiff --git a/tools/browser_tool_cdp.py b/tools/browser_tool_cdp.pyindex c2f35729917..59c7bfd0b02 100644--- a/tools/browser_tool_cdp.py+++ b/tools/browser_tool_cdp.py@@ -56,8 +56,15 @@ _live_overrides_lock = threading.Lock()def live_cdp_override() -> str:- """The current profile's live ``/browser connect`` endpoint, or ""."""- from hermes_constants import hermes_home_key+ """The current profile's live ``/browser connect`` endpoint, or "".++ On a multiplexed gateway a context with no profile bound (a bare ``threading.Thread`` or stdlib+ executor that did not copy the caller's context) answers "" rather than the launch profile's+ endpoint, the way ``get_secret`` fails closed. Single-profile processes are unchanged."""+ from agent.secret_scope import is_multiplex_active+ from hermes_constants import get_hermes_home_override, hermes_home_key+ if get_hermes_home_override() is None and is_multiplex_active():+ return ""with _live_overrides_lock:return _live_overrides.get(hermes_home_key(), "")