Skip to content

The agent that grows with you

fix(bot-screen): keep cloned browsers profile-isolated

Yags54838bee00b3
diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.py
index 2d19ee55a7c..5637562e50e 100644
--- a/hermes_cli/profiles.py
+++ b/hermes_cli/profiles.py
@@ -42,10 +42,14 @@ _CLONE_SUBDIR_FILES = ["memories/MEMORY.md", "memories/USER.md"]
_CLONE_ALL_STRIP: list[str] = [
"gateway.pid", "gateway_state.json", "processes.json",
# Bot Desktop runtime identity: pid + create_time of the SOURCE's launcher, its DISPLAY/XAUTHORITY and
- # lease. Copied verbatim, `screen stop` on the clone would kill the source's X server. The persistent
- # browser profile beside them is user data and stays.
+ # lease. Copied verbatim, `screen stop` on the clone would kill the source's X server. Browser user data
+ # stays, but Chromium's process markers must not let the clone attach to the source's live browser.
"bot-desktop/launcher.pid", "bot-desktop/env", "bot-desktop/rfb.sock",
"bot-desktop/lease.json", "bot-desktop/lease.lock",
+ "bot-desktop/browser-profile/DevToolsActivePort",
+ "bot-desktop/browser-profile/SingletonLock",
+ "bot-desktop/browser-profile/SingletonCookie",
+ "bot-desktop/browser-profile/SingletonSocket",
]
# Infrastructure excluded from --clone-all ONLY when the source is the default profile
diff --git a/tests/hermes_cli/test_profiles.py b/tests/hermes_cli/test_profiles.py
index b82c42dc4dd..f4db12280f0 100644
--- a/tests/hermes_cli/test_profiles.py
+++ b/tests/hermes_cli/test_profiles.py
@@ -9,6 +9,7 @@ import json
import io
import os
import shutil
+import socket
import sys
import tarfile
import types
@@ -261,24 +262,53 @@ class TestCreateProfile:
assert not any((profile_dir / "cron").iterdir())
assert yaml.safe_load((profile_dir / "config.yaml").read_text())["model"] == "test"
- def test_clone_all_does_not_inherit_the_source_screens_identity(self, profile_env):
- """launcher.pid / env / lease name the SOURCE's live X server; a clone that inherits them believes it
- owns that screen and `screen stop` on the clone kills the source's desktop. The browser profile
- beside them is user data (logins) and must come along."""
+ def test_clone_all_does_not_inherit_the_source_screen_or_browser_process_artifacts(self, profile_env):
+ """A clone keeps browser data, never the source's screen or Chromium runtime files."""
default_home = profile_env / ".hermes"
(default_home / "config.yaml").write_text("model: test")
bd = default_home / "bot-desktop"
- (bd / "browser-profile" / "Default").mkdir(parents=True)
- (bd / "browser-profile" / "Default" / "Cookies").write_text("jar")
+ browser_profile = bd / "browser-profile"
+ (browser_profile / "Default").mkdir(parents=True)
+ (browser_profile / "Default" / "Cookies").write_text("jar")
(bd / "launcher.pid").write_text("4242 1.5")
(bd / "env").write_text("DISPLAY=:21\nXAUTHORITY=/x\n")
(bd / "lease.json").write_text(json.dumps({"holder": "human", "viewer_id": "v", "epoch": 3}))
+ process_markers = ("DevToolsActivePort", "SingletonLock", "SingletonCookie", "SingletonSocket")
+ for process_marker in process_markers:
+ (browser_profile / process_marker).write_text("source-process")
profile_dir = create_profile("coder", clone_all=True, no_alias=True)
+ cloned_browser = profile_dir / "bot-desktop" / "browser-profile"
for runtime_file in ("launcher.pid", "env", "lease.json"):
assert not (profile_dir / "bot-desktop" / runtime_file).exists(), runtime_file
- assert (profile_dir / "bot-desktop" / "browser-profile" / "Default" / "Cookies").read_text() == "jar"
+ for process_marker in process_markers:
+ assert not (cloned_browser / process_marker).exists(), process_marker
+ assert (cloned_browser / "Default" / "Cookies").read_text() == "jar"
+
+ @pytest.mark.linux_only
+ def test_clone_all_does_not_attach_to_the_source_profiles_live_browser(self, profile_env):
+ """Copied Chromium markers must not route the clone through the source profile's CDP port."""
+ from tools.bot_desktop.browser import running_instance_cdp_port
+
+ default_home = profile_env / ".hermes"
+ (default_home / "config.yaml").write_text("model: test")
+ browser_profile = default_home / "bot-desktop" / "browser-profile"
+ browser_profile.mkdir(parents=True)
+
+ with socket.socket() as listener:
+ listener.bind(("127.0.0.1", 0))
+ listener.listen()
+ port = listener.getsockname()[1]
+ (browser_profile / "DevToolsActivePort").write_text(f"{port}\n/devtools/browser/source\n")
+ (browser_profile / "SingletonLock").symlink_to(f"host-{os.getpid()}")
+ assert running_instance_cdp_port(str(browser_profile)) == port
+
+ profile_dir = create_profile("coder", clone_all=True, no_alias=True)
+ cloned_browser = profile_dir / "bot-desktop" / "browser-profile"
+
+ assert running_instance_cdp_port(str(cloned_browser)) is None
+ assert running_instance_cdp_port(str(browser_profile)) == port
@pytest.mark.skipif(not hasattr(os, "mkfifo"), reason="special files need a POSIX filesystem")
def test_clone_all_skips_special_files(self, profile_env):