Skip to content

The agent that grows with you

fix(browser): fence the bot's browser by provenance, not by cdp_url

teknium1d1a1f9952d3c
diff --git a/tests/tools/test_bot_desktop_browser_fence.py b/tests/tools/test_bot_desktop_browser_fence.py
index f791ac2419f..743deec2de8 100644
--- a/tests/tools/test_bot_desktop_browser_fence.py
+++ b/tests/tools/test_bot_desktop_browser_fence.py
@@ -26,7 +26,7 @@ def _wire(monkeypatch, commands):
monkeypatch.setattr(browser, "_is_camofox_mode", lambda: False)
monkeypatch.setattr(browser, "_blocked_private_page_action", lambda *a: None)
monkeypatch.setattr(session, "_browser_command_preflight", lambda: {"browser_cmd": "agent-browser"})
- monkeypatch.setattr(session, "_get_session_info", lambda *a: {"session_name": "review"})
+ monkeypatch.setattr(session, "_get_session_info", lambda *a: {"session_name": "review", "cdp_url": None, "features": {"local": True}})
monkeypatch.setattr(session._cloud, "_get_browser_engine", lambda: "chrome")
monkeypatch.setattr(session._cloud, "_is_headed_mode", lambda: True)
@@ -59,3 +59,20 @@ def test_browser_result_crossing_a_takeover_is_discarded(monkeypatch):
monkeypatch.setattr(session, "_spawn_and_collect", spawn_then_takeover)
result = browser.browser_click("e1", task_id="review")
assert "WHAT-THE-HUMAN-TYPED" not in result
+
+
+def test_real_profile_local_browser_is_fenced_by_provenance_even_without_a_live_display(monkeypatch):
+ """A real-profile session attaches over a loopback cdp_url but is launched with the Bot Desktop
+ DISPLAY, so it IS the human's browser: the fence keys on the ``local`` feature, not on the
+ transport. And a stranded human lease with the screen already down must still fence (computer_use
+ does), not silently unfence the browser."""
+ commands: list = []
+ browser, session = _wire(monkeypatch, commands)
+ monkeypatch.setattr(session, "_get_session_info", lambda *a: {
+ "session_name": "rp_1", "cdp_url": "ws://127.0.0.1:9222/devtools/browser/x",
+ "features": {"local": True, "real_profile": True}})
+ monkeypatch.setattr(runtime, "published_env", lambda: {})
+ lease.acquire("human-viewer")
+ result = json.loads(browser.browser_click("e1", task_id="review"))
+ assert commands == [], f"human holds the lease, yet a real-profile browser command was dispatched: {commands}"
+ assert result.get("code") == "human_has_control"
diff --git a/tools/browser_tool_session.py b/tools/browser_tool_session.py
index 14fa7edceda..57449159234 100644
--- a/tools/browser_tool_session.py
+++ b/tools/browser_tool_session.py
@@ -594,12 +594,14 @@ def _run_browser_command(
def _shares_bot_desktop_browser(session_info: Dict[str, Any]) -> bool:
- """Local agent-browser session (no CDP url: the dispatcher runs it with ``--session``, i.e. on this
- host's display) while this profile's Bot Desktop screen is running."""
- if session_info.get("cdp_url"):
+ """Decided by provenance, not transport: every LOCAL session (plain ``--session``, real-profile CDP
+ attach, Lightpanda) is a browser Hermes launched with this profile's Bot Desktop DISPLAY, so it is the
+ screen a human who took over is typing into. Cloud / user-supplied CDP sessions are another browser.
+ A human lease with the screen already gone (dead Xvnc) still fences — computer_use does the same."""
+ if not (session_info.get("features") or {}).get("local"):
return False
- from tools.bot_desktop import runtime as _bd_runtime
- return bool(_bd_runtime.published_env().get("DISPLAY"))
+ from tools.bot_desktop import lease as _bd_lease, runtime as _bd_runtime
+ return bool(_bd_runtime.published_env().get("DISPLAY")) or _bd_lease.human_holds()
def _run_browser_command_unfenced(task_id: str, command: str, args: List[str], timeout: int,