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
This commit is contained in:
Teknium committed 2026-10-23 01:42:57 -07:00
1 parent fc50f3db83
commit 8dac3f319b
2 files changed
+28 -1

No files matched your search

+27
View File
@@ -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)
+1 -1
View File
@@ -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")