The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
tui_gateway: resolve the launch home at call time for launch-profile secrets
ethernetfe1e5c263875
diff --git a/tests/tui_gateway/test_compute_host_turn_protocol.py b/tests/tui_gateway/test_compute_host_turn_protocol.pyindex a20586345cc..92e85bbd5bf 100644--- a/tests/tui_gateway/test_compute_host_turn_protocol.py+++ b/tests/tui_gateway/test_compute_host_turn_protocol.py@@ -25,7 +25,7 @@ def _frames(out: io.StringIO) -> list[dict]:return [json.loads(line) for line in out.getvalue().splitlines() if line.strip()]-def _wait(out: io.StringIO, predicate, timeout: float = 20.0) -> dict:+def _wait(out: io.StringIO, predicate, timeout: float = 5.0) -> dict:deadline = time.monotonic() + timeoutwhile time.monotonic() < deadline:for frame in _frames(out):diff --git a/tests/tui_gateway/test_launch_home_isolation.py b/tests/tui_gateway/test_launch_home_isolation.pynew file mode 100644index 00000000000..ff866020339--- /dev/null+++ b/tests/tui_gateway/test_launch_home_isolation.py@@ -0,0 +1,20 @@+"""The launch home the TUI server binds launch-profile turns to must follow the process home."""+import os+from pathlib import Path++# Imported at collection on purpose: that is when real test modules import the server,+# before any per-test fixture redirects HERMES_HOME, so ``_hermes_home`` freezes to the+# pre-fixture home exactly as it does for the rest of the suite.+from tui_gateway import server+from tui_gateway.launch_profile_policy import launch_secret_scope+++def test_launch_home_follows_the_process_home_redirected_after_import():+ """``server._hermes_home`` is get_hermes_home() at import — under a developer shell the+ honored custom HERMES_HOME, a guarded root. Launch-profile turns read ``<launch home>/.env``+ (``launch_secret_scope``), so the home they bind must be resolved at call time from the+ process env, like the launch ``state.db`` handle (#112692), never the import-time value."""+ sandbox = Path(os.environ["HERMES_HOME"])+ assert server._launch_home() == sandbox+ (sandbox / ".env").write_text("HERMES_LAUNCH_HOME_PROBE=from-sandbox\n", encoding="utf-8")+ assert launch_secret_scope(server._launch_home()).get("HERMES_LAUNCH_HOME_PROBE") == "from-sandbox"diff --git a/tui_gateway/model_switch.py b/tui_gateway/model_switch.pyindex 8e62abccdb6..917957dbaf0 100644--- a/tui_gateway/model_switch.py+++ b/tui_gateway/model_switch.py@@ -80,8 +80,10 @@ def _profile_runtime_scope_tokens(profile_home, *, hydrate_secrets: bool = True)else:# No home override: the launch home IS get_hermes_home() (``_profile_home`` answers None for# "already the launch profile"); only its secrets (+ terminal policy under multiplex) need binding.+ # Resolved at call time like the launch state.db handle: a harness that re-homes the process+ # after import must not have the import-time home's ``.env`` read on every turn.from tui_gateway.launch_profile_policy import launch_secret_scope, launch_terminal_env- home = Path(_hermes_home)+ home = _launch_home()secrets = launch_secret_scope(home)scopes.secret = set_secret_scope(secrets)if not is_multiplex_active():diff --git a/tui_gateway/server.py b/tui_gateway/server.pyindex 5d92ef124fd..21ac73688dc 100644--- a/tui_gateway/server.py+++ b/tui_gateway/server.py@@ -382,15 +382,21 @@ _start_idle_reaper()# ── Plumbing ──────────────────────────────────────────────────────────-def _launch_state_db_path() -> Path:- """Launch profile's ``state.db`` at call time: the patched ``_hermes_home`` when a test changed+def _launch_home() -> Path:+ """The launch profile's home at call time: the patched ``_hermes_home`` when a test changedit, else the live process home — resolved through :func:`get_process_hermes_home`, which honours``HERMES_HOME`` but ignores the context-local override. The desktop multiplex cron ticker sets- that override per profile at startup, and a first touch inside a foreign window would bind this- process-wide handle to another profile's ``state.db`` (#102526). Resolving here rather than at- import time lets a harness that redirects ``HERMES_HOME`` after import be honoured (#112692)."""+ that override per profile at startup, and a first touch inside a foreign window would bind+ process-wide launch state (the shared ``state.db`` handle, the launch ``.env`` secrets) to+ another profile (#102526). Resolving here rather than at import time lets a harness that+ redirects ``HERMES_HOME`` after import be honoured (#112692)."""home = _hermes_home if _hermes_home != _HERMES_HOME_AT_IMPORT else get_process_hermes_home()- return Path(home) / "state.db"+ return Path(home)+++def _launch_state_db_path() -> Path:+ """Launch profile's ``state.db`` (see :func:`_launch_home`)."""+ return _launch_home() / "state.db"def _get_db():