Skip to content

The agent that grows with you

fix(desktop): run the Desktop's boot work for the launch profile

alt-glitch9a45bec840b5
diff --git a/tests/gateway/test_local_desktop_identity.py b/tests/gateway/test_local_desktop_identity.py
index ec1d820dc86..89ee372e6e7 100644
--- a/tests/gateway/test_local_desktop_identity.py
+++ b/tests/gateway/test_local_desktop_identity.py
@@ -215,3 +215,30 @@ async def test_the_first_local_desktop_connection_runs_the_desktop_boot_work(tmp
finally:
await conn.connection.close()
free_tier_bootstrap.reset_for_tests()
+
+
+def test_the_desktop_boot_work_runs_for_the_launch_profile_whichever_profile_connects_first(tmp_path, monkeypatch):
+ """The setup record and the first-install latch belong to the launch profile. On a multiplexing
+ gateway a Desktop connection runs in its own profile's scope, so a first connection for another
+ profile must not build the launch record from that profile's home."""
+ from agent import secret_scope
+ from hermes_cli import free_tier_bootstrap, onboarding_run
+ from hermes_constants import get_hermes_home, get_process_hermes_home, set_hermes_home_override
+ from tui_gateway import server
+ launch = get_process_hermes_home()
+ secondary = tmp_path / "profiles" / "work"
+ secondary.mkdir(parents=True)
+ seen = []
+ monkeypatch.setattr(onboarding_run, "latch_first_install", lambda: seen.append(get_hermes_home()))
+ monkeypatch.setattr(server, "_local_desktop_boot_started", False)
+ monkeypatch.setattr(secret_scope, "_MULTIPLEX_ACTIVE", True)
+ free_tier_bootstrap.reset_for_tests()
+ token = set_hermes_home_override(secondary)
+ try:
+ server.begin_local_desktop_boot()
+ assert free_tier_bootstrap.wait_for_record(timeout=20) is not None
+ finally:
+ from hermes_constants import reset_hermes_home_override
+ reset_hermes_home_override(token)
+ free_tier_bootstrap.reset_for_tests()
+ assert seen == [launch]
diff --git a/tui_gateway/methods_onboarding.py b/tui_gateway/methods_onboarding.py
index b89fb23694b..babdf88f338 100644
--- a/tui_gateway/methods_onboarding.py
+++ b/tui_gateway/methods_onboarding.py
@@ -115,12 +115,14 @@ def begin_local_desktop_boot() -> None:
global _local_desktop_boot_started
from hermes_cli import free_tier_bootstrap
from hermes_cli.process_identity import serving_local_desktop
+ from tui_gateway.launch_profile_policy import launch_profile_scope_if_multiplexed
with _local_desktop_boot_lock:
if _local_desktop_boot_started:
return
_local_desktop_boot_started = True
- with serving_local_desktop(True): # the threads below copy this context
+ # The record and the latch are the launch profile's; the connecting profile may be another one.
+ with launch_profile_scope_if_multiplexed(), serving_local_desktop(True): # threads copy this context
free_tier_bootstrap.start_background_bootstrap()
start_due_boot()