The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(webapp): the launch scope bound for 'profile: default' keeps process-env credentials
Tekniumf2cc013158ce
diff --git a/tests/tui_gateway/test_legacy_fallback_launch_explicit_profile.py b/tests/tui_gateway/test_legacy_fallback_launch_explicit_profile.pyindex d60b50dd5a6..729d4a707dc 100644--- a/tests/tui_gateway/test_legacy_fallback_launch_explicit_profile.py+++ b/tests/tui_gateway/test_legacy_fallback_launch_explicit_profile.py@@ -28,6 +28,7 @@ def homes(tmp_path, monkeypatch):(home / "config.yaml").write_text("{}\n")monkeypatch.setenv("HERMES_HOME", str(launch))monkeypatch.setenv("HERMES_PORTAL_BASE_URL", LAUNCH_PORTAL) # the launch process loaded its own .env+ monkeypatch.setenv("LAUNCH_ENV_ONLY_KEY", "from-process-env") # systemd / Docker / ``op run`` onlymonkeypatch.setattr(server, "_hermes_home", launch)monkeypatch.setattr(server, "_served_profile_homes", set())monkeypatch.setattr(launch_profile_policy, "_snapshot", None)@@ -78,17 +79,25 @@ def test_explicit_profile_that_does_not_resolve_is_refused_before_the_handler(hoassert seen == []-def test_a_secondary_socket_naming_the_launch_profile_runs_in_the_launch_scope(homes):+def test_a_secondary_socket_naming_the_launch_profile_runs_in_the_launch_scope(homes, monkeypatch):"""Reverse direction: a profile-bound socket runs in that profile's scope, so a verb naming thelaunch profile must not keep the secondary's secrets and home."""from gateway.runtime_bootstrap import _PURPOSE_CAPABILITIESfrom tui_gateway.ws_legacy_fallback import dispatch_legacyserver, launch, bee, seen = homes+ env_only = []++ def probe(rid, params):+ from agent.secret_scope import get_secret+ env_only.append(get_secret("LAUNCH_ENV_ONLY_KEY"))+ return server._methods["probe.portal"](rid, params)+ monkeypatch.setitem(server._methods, "probe.env", probe)actor = types.SimpleNamespace(profile_id=str(bee), capabilities=frozenset(_PURPOSE_CAPABILITIES["interactive"]))written, done = [], threading.Event()transport = types.SimpleNamespace(write=lambda frame: written.append(frame) or done.set() or True)with server._session_profile_runtime_scope({"profile_home": str(bee)}):- reply = dispatch_legacy(server, {"jsonrpc": "2.0", "id": 1, "method": "probe.portal",+ reply = dispatch_legacy(server, {"jsonrpc": "2.0", "id": 1, "method": "probe.env","params": {"profile": "default"}}, transport, actor)assert "result" in (reply if reply is not None else (done.wait(10) and written[0]))assert seen == [(launch.resolve(), LAUNCH_PORTAL)]+ assert env_only == ["from-process-env"]diff --git a/tui_gateway/ws_legacy_fallback.py b/tui_gateway/ws_legacy_fallback.pyindex e75000f872d..dab451676fe 100644--- a/tui_gateway/ws_legacy_fallback.py+++ b/tui_gateway/ws_legacy_fallback.py@@ -166,9 +166,9 @@ def dispatch_legacy(server: Any, req: dict, transport: Any, actor: Any) -> dictif target is None:return req# "" = an explicit ``profile`` naming the launch home: the socket runs in the ticket's- # scope (``chat_ws.gateway_ws``), so bind the launch scope or a handler that ignores- # ``profile`` would read and write the secondary profile's state.- scope = server._session_profile_runtime_scope({"profile_home": target or server._launch_home()})+ # scope (``chat_ws.gateway_ws``), so bind the launch scope (``None`` selects it, process env+ # credentials included) or a handler that ignores ``profile`` would use the secondary's.+ scope = server._session_profile_runtime_scope({"profile_home": target or None})elif (req.get("method") not in _SESSION_FALLBACK_ALLOWEDand (explicit := _explicit_profile_request(server, req)) is not None):# A launch-profile socket runs in the launch scope (``chat_ws.gateway_ws``), so a verb that