From 8dac3f319b3ce288b19606b300cd3b634314dc7e Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:53:59 -0700 Subject: [PATCH] fix(browser): an auto-started Bot Desktop screen is up before the browser profile is chosen With browser.headed and bot_desktop.auto_start on a headless host, the first local launch picked its target (no screen yet, so a throwaway profile) and only then started the screen. Chromium opened on the Bot Desktop with a different cookie jar from the dock's Browser icon. The screen now starts first, so the launch selects the shared Bot Desktop profile. Review: https://github.com/NousResearch/hermes-agent/pull/143146#discussion_r4351612954 --- tests/tools/test_browser_headed_mode.py | 27 +++++++++++++++++++++++++ tools/browser_session.py | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/tools/test_browser_headed_mode.py b/tests/tools/test_browser_headed_mode.py index 13696db788..15028a52b2 100644 --- a/tests/tools/test_browser_headed_mode.py +++ b/tests/tools/test_browser_headed_mode.py @@ -129,6 +129,33 @@ class TestHeadedLaunch: assert not any(arg.startswith("--headless") for arg in captured[0]) + def test_auto_started_screen_is_up_before_the_profile_is_chosen(self, monkeypatch): + """browser.headed + bot_desktop.auto_start on a headless host: the first local launch brings the screen + up and then uses the Bot Desktop profile (the dock Browser's cookie jar), not a throwaway one.""" + from tools.bot_desktop import browser as bd_browser, placement, runtime + screen = {} + monkeypatch.setattr(bs_cloud, "is_headed_mode", lambda: True) + monkeypatch.setattr(runtime, "tool_placement", lambda: placement.GATEWAY) + monkeypatch.setattr(runtime, "published_env", lambda: dict(screen)) + monkeypatch.setattr(runtime, "ensure_started_for_tool", lambda: screen.update(DISPLAY=":99")) + monkeypatch.setattr(bd_browser, "profile_dir", lambda: "/bot-desktop/browser-profile") + monkeypatch.setattr(bd_browser, "executable", lambda: "/usr/bin/chromium") + launches = [] + + def launch(key, **kwargs): + launches.append((key, kwargs)) + return SimpleNamespace(cdp_url="ws://127.0.0.1:9/devtools/browser/x", pid=1), None + + monkeypatch.setattr(launcher, "launch_chromium", launch) + + bs._create_chromium_session("task1") + + assert screen == {"DISPLAY": ":99"} + assert launches == [("profile:/bot-desktop/browser-profile", { + "executable": "/usr/bin/chromium", "user_data_dir": "/bot-desktop/browser-profile", "ephemeral": False, + "extra_args": bd_browser.SHARED_PROFILE_ARGS})] + + def test_headed_not_applied_in_cloud_mode(self, monkeypatch): """Cloud (CDP) sessions never launch a local (headed) Chromium: headed is a local-only knob.""" monkeypatch.setattr(bs_cloud, "is_headed_mode", lambda: True) diff --git a/tools/browser_session.py b/tools/browser_session.py index 73e82f6d5d..e0147056a1 100644 --- a/tools/browser_session.py +++ b/tools/browser_session.py @@ -198,8 +198,8 @@ def _create_chromium_session(cache_key: str) -> dict[str, Any]: from tools.browser_session_sandbox import create_sandbox_session return create_sandbox_session(cache_key) from tools.browser_launcher import launch_chromium + ensure_screen_for_headed_chromium() # first: an auto-started screen selects the Bot Desktop profile launcher_key, kwargs, shared = _launch_target(cache_key) - ensure_screen_for_headed_chromium() browser, err = launch_chromium(launcher_key, **kwargs) if browser is None: raise RuntimeError(err or "the local browser could not be started")