Skip to content

The agent that grows with you

fix(bot-desktop): re-admit secret writes after a prompt; recover pre-marker dock launchers

teknium136e9ddeff23d
diff --git a/tests/tools/test_bot_desktop_browser_fence.py b/tests/tools/test_bot_desktop_browser_fence.py
index 0222165ecab..857b5cfbf9e 100644
--- a/tests/tools/test_bot_desktop_browser_fence.py
+++ b/tests/tools/test_bot_desktop_browser_fence.py
@@ -181,3 +181,26 @@ def test_vault_page_operations_respect_the_human_lease(monkeypatch):
assert touched == [], "no vault page access while the human holds the screen"
lease.release("human")
assert json.loads(vault._handle_vault_fill({"handle": "vault_x"}, task_id="default"))["success"] is True
+
+
+def test_secret_write_re_admits_after_a_takeover_during_the_code_prompt(monkeypatch):
+ """`enter_code` blocks on the user's code INSIDE the handler fence. A takeover during that wait must
+ refuse the write itself: the outer fence only discards the result afterwards, and by then the code is
+ already in the page the human is typing into."""
+ from tools import browser_tool as browser
+ from tools import browser_vault_tool as vault
+
+ browser._active_sessions["default"] = {"session_name": "review", "cdp_url": None, "features": {"local": True}}
+ evaluated = []
+
+ class Sup:
+ def evaluate_runtime(self, expr):
+ evaluated.append(expr)
+ return {"ok": True, "result": "{}"}
+
+ monkeypatch.setattr(vault, "_ensure_supervisor", lambda tid: Sup())
+ assert vault._eval_js_secret("default", "fill()")["success"] is True # agent holds: writes
+ lease.acquire("human") # takeover while the prompt was open
+ res = vault._eval_js_secret("default", "fill()")
+ assert res["success"] is False and res["error_type"] == "human_has_control"
+ assert evaluated == ["fill()"], "the credential must not reach the page under a human lease"
diff --git a/tests/tools/test_bot_desktop_launcher_seed.py b/tests/tools/test_bot_desktop_launcher_seed.py
index 347a568ffa4..eab0685b3c9 100644
--- a/tests/tools/test_bot_desktop_launcher_seed.py
+++ b/tests/tools/test_bot_desktop_launcher_seed.py
@@ -73,6 +73,22 @@ def test_browser_launcher_follows_the_profile_without_reseeding_the_panel(tmp_pa
assert panel_xml.read_text(encoding="utf-8") == layout_before
+def test_browser_launcher_seeded_before_the_marker_still_follows_a_rename(tmp_path):
+ """Profiles seeded by an earlier launcher have the Browser entry but no `.hermes-browser-launcher`;
+ a rename must still reach their Exec= (the marker is recovered from our own entry), not leave them
+ opening the old profile's empty cookie jar forever."""
+ chrome = tmp_path / "bin" / "chrome"
+ cfg = _seed(tmp_path, ["xfce4-terminal", "chrome"], browser_exec=str(chrome), profile_dir="/old name/bp")
+ (cfg / "xfce4/panel/.hermes-browser-launcher").unlink()
+ shutil.rmtree(tmp_path / "bin")
+ _seed(tmp_path, ["xfce4-terminal", "chrome"], browser_exec=str(chrome), profile_dir="/new name/bp")
+ execs = [
+ line for d in (cfg / "xfce4/panel").glob("launcher-*/hermes.desktop")
+ for line in d.read_text(encoding="utf-8").splitlines() if line.startswith("Exec=") and "user-data-dir" in line
+ ]
+ assert execs == [f"Exec={chrome} --user-data-dir=/new name/bp"]
+
+
def test_look_is_seeded_with_wallpaper_and_theme(tmp_path):
cfg = _seed(tmp_path, ["xfce4-terminal"])
desktop = (cfg / "xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml").read_text(encoding="utf-8")
diff --git a/tools/bot_desktop/launcher.sh b/tools/bot_desktop/launcher.sh
index 4e90ee3eed4..c96d850f4ac 100755
--- a/tools/bot_desktop/launcher.sh
+++ b/tools/bot_desktop/launcher.sh
@@ -227,6 +227,19 @@ done
# seeded once (the human may have rearranged it), but this one line is ours and must follow the profile:
# after `hermes profile rename` the old path would open a browser with an empty, unshared cookie jar.
L="$XDG_CONFIG_HOME/xfce4/panel"
+# Profiles seeded before the marker existed have the launcher but no `.hermes-browser-launcher`; recover
+# it from our own Browser entry (hermes.desktop is ours by name) so their Exec= follows a rename too.
+if [[ -n "${HERMES_BD_BROWSER_EXEC:-}" && -n "${HERMES_BD_BROWSER_EXEC_LINE:-}" && ! -r "$L/.hermes-browser-launcher" ]]; then
+ for d in "$L"/launcher-*/hermes.desktop; do
+ [[ -f "$d" ]] || continue
+ while IFS= read -r line; do
+ if [[ "$line" == "Name=Browser" ]]; then
+ bn="${d%/hermes.desktop}"; bn="${bn##*/launcher-}"
+ printf '%s\n' "$bn" > "$L/.hermes-browser-launcher"; break 2
+ fi
+ done < "$d"
+ done
+fi
if [[ -n "${HERMES_BD_BROWSER_EXEC:-}" && -n "${HERMES_BD_BROWSER_EXEC_LINE:-}" && -r "$L/.hermes-browser-launcher" ]]; then
bn="$(cat "$L/.hermes-browser-launcher")"
d="$L/launcher-$bn/hermes.desktop"
diff --git a/tools/browser_vault_tool.py b/tools/browser_vault_tool.py
index 3ec71b9c943..4aebc673e0e 100644
--- a/tools/browser_vault_tool.py
+++ b/tools/browser_vault_tool.py
@@ -144,6 +144,17 @@ def _eval_js_secret(task_id: str, expression: str) -> Dict[str, Any]:
),
}
+ # Re-admit at the WRITE. The handler-level fence (_fenced_page_op) admitted before a possibly
+ # human-length prompt (enter_code waits for the user's code); a takeover during that wait must
+ # refuse here, before the credential lands in a page the human is now typing into. The outer
+ # epoch check only discards the result, and a fill is a side effect, not a result.
+ if _bot_desktop_browser_session(task_id):
+ from tools.bot_desktop import lease as _bd_lease
+ try:
+ _bd_lease.assert_agent_may_act()
+ except _bd_lease.HumanHasControl as exc:
+ return {"success": False, "error_type": "human_has_control", "error": str(exc)}
+
sup = supervisor.evaluate_runtime(expression)
if sup.get("ok"):
return {"success": True, "result": sup.get("result")}
@@ -668,6 +679,12 @@ BROWSER_VAULT_ENTER_CODE_SCHEMA = {
}
+def _bot_desktop_browser_session(task_id: Optional[str]) -> bool:
+ from tools.browser_tool import _active_sessions, _last_session_key
+ from tools.browser_tool_session import _shares_bot_desktop_browser
+ return _shares_bot_desktop_browser(_active_sessions.get(_last_session_key(task_id or "default")) or {})
+
+
def _fenced_page_op(task_id: Optional[str], fn) -> str:
"""Vault operations focus, inspect and fill the page over the supervisor socket, bypassing
``_run_browser_command``; they must honour the Bot Desktop lease like every other page access,
diff --git a/website/docs/user-guide/features/bot-screen.md b/website/docs/user-guide/features/bot-screen.md
index dddb0032273..3e257809516 100644
--- a/website/docs/user-guide/features/bot-screen.md
+++ b/website/docs/user-guide/features/bot-screen.md
@@ -23,8 +23,12 @@ and the control-lease file all belong to the gateway's OS user. Any process
running as that user — another bot on the same host, and the bot's own
`terminal` tool included — can reach them directly, bypassing the pane and the
lease. The lease is a tool-level fence on `computer_use` and the browser tools,
-not an OS one. Running each bot as its own OS user is out of scope; if that
-isolation matters to you, put the bots on separate hosts. Two timing details
+not an OS one. One boundary is wider than the OS user: Chromium's DevTools
+port (the dock's Browser and every agent-browser launch advertise one on
+loopback so the agent can attach) is reachable by **any** local user on the
+host, and Chromium offers no per-user restriction for it. Running each bot as
+its own OS user is out of scope; if that isolation matters to you, or the host
+has untrusted local users, put the bots on separate hosts. Two timing details
worth knowing: the WebSocket bridge caches its lease decision for up to 250 ms
between re-reads of the lease file, so a takeover made by another process is
enforced within that window (the bot's tool results are voided by the lease