The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(compute-host): hydrate a routed profile's external secret sources before building its scope
teknium1a39efc94664a
diff --git a/tests/tui_gateway/test_compute_host_routed_secret_hydration.py b/tests/tui_gateway/test_compute_host_routed_secret_hydration.pynew file mode 100644index 00000000000..ec5c13d253f--- /dev/null+++ b/tests/tui_gateway/test_compute_host_routed_secret_hydration.py@@ -0,0 +1,68 @@+"""A routed compute-host session hydrates the profile's EXTERNAL secret sources before building its+scope (#119521): the isolated turn process never ran the launch dotenv path for that profile, so+without hydration a vault-only provider key is absent from the scope and the agent build fails closed."""++from __future__ import annotations++import io+import types+from pathlib import Path++import pytest++from tui_gateway import server+from tui_gateway.compute_host import ComputeHost++[email protected]_only+def test_routed_session_build_sees_the_profiles_external_secret_source(monkeypatch, tmp_path):+ """Two routed homes A→B→A, each with a ``secrets.command`` helper that is the ONLY holder of its+ provider key. Inside each build the scope resolves that profile's key and not the other's."""+ from agent.secret_scope import get_secret, set_multiplex_active+ from hermes_cli import env_loader++ launch = tmp_path / ".hermes"+ launch.mkdir()+ monkeypatch.setenv("HERMES_HOME", str(launch))+ monkeypatch.setenv("VAULT_ONLY_KEY", "from-launch-env")+ env_loader.reset_secret_source_cache()+ monkeypatch.setattr("agent.secret_scope._MULTIPLEX_ACTIVE", False)+ set_multiplex_active(True)++ homes = {}+ for name in ("a", "b"):+ home = launch / "profiles" / name+ home.mkdir(parents=True)+ (home / ".env").write_text(f"{name.upper()}_MARKER=1\n", encoding="utf-8")+ (home / "config.yaml").write_text(+ "secrets:\n command:\n enabled: true\n"+ f" command: \"printf 'VAULT_ONLY_KEY=vault-{name}\\\\n'\"\n",+ encoding="utf-8")+ homes[name] = home++ host = ComputeHost(stdout=io.StringIO(), heartbeat_secs=0)+ seen = []++ def fake_make_agent(sid, key, **kwargs):+ seen.append(get_secret("VAULT_ONLY_KEY"))+ return types.SimpleNamespace(session_id=key)++ def fake_init_session(sid, key, agent, history, **kwargs):+ monkeypatch.setitem(server._sessions, sid, {"agent": agent, "session_key": key})++ monkeypatch.setattr(server, "_make_agent", fake_make_agent)+ monkeypatch.setattr(server, "_transfer_db_to_agent", lambda agent, db: False)+ monkeypatch.setattr(server, "_init_session", fake_init_session)+ try:+ for name in ("a", "b", "a"):+ host._build_server_session(+ server, {"sid": f"s-{name}", "session_key": f"k-{name}", "history": [],+ "profile_home": str(homes[name])}, f"s-{name}")+ finally:+ host.close()+ env_loader.reset_secret_source_cache()+ for name in ("a", "b"):+ server._sessions.pop(f"s-{name}", None)+ # The wrong side is ABSENT: never the launch env, never the other profile's vault.+ assert seen == ["vault-a", "vault-b", "vault-a"]+ assert Path(homes["a"]).exists()diff --git a/tui_gateway/compute_host.py b/tui_gateway/compute_host.pyindex b9c221b8ec1..8e7c233cbe9 100644--- a/tui_gateway/compute_host.py+++ b/tui_gateway/compute_host.py@@ -320,8 +320,15 @@ class ComputeHost:if profile_home:from hermes_constants import set_hermes_home_overridefrom agent.secret_scope import build_profile_secret_scope, set_secret_scope+ from hermes_cli.env_loader import hydrate_profile_secret_sourcesfrom hermes_state_registry import acquirehome_token = set_hermes_home_override(profile_home)+ # External sources first (1Password / Bitwarden / secrets.command): this isolated+ # turn process never ran the launch dotenv path for the routed profile, so without+ # hydration the scope is built on an empty external snapshot and a vault-only+ # provider key fails closed. Same order as gateway/run.py::_load_profile_secret_scope+ # and tui_gateway/model_switch.py::_profile_runtime_scope_tokens (#119521).+ hydrate_profile_secret_sources(Path(profile_home))secret_token = set_secret_scope(build_profile_secret_scope(Path(profile_home)), profile_home=profile_home)# DEDICATED handle — ours only until _make_agent succeeds, then the agent owns