The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tools): never ambient-bridge TERMINAL_* under a profile home override
infinitycrew39a5c801c8dcb1
diff --git a/tests/tools/test_terminal_env_bridge.py b/tests/tools/test_terminal_env_bridge.pyindex aa90c575975..92c5a88f566 100644--- a/tests/tools/test_terminal_env_bridge.py+++ b/tests/tools/test_terminal_env_bridge.py@@ -152,3 +152,56 @@ def test_bridge_config_failure_does_not_crash(monkeypatch):assert config["env_type"] == "ssh"assert config["ssh_host"] == "example.test"+++def test_secondary_home_override_does_not_latch_ambient_env(tmp_path, monkeypatch):+ """#107422: first bridge under a secondary profile must not poison os.environ.++ Multiplexed dashboard sets ``set_hermes_home_override`` for profile B. If+ ``_ensure_terminal_env_bridged`` ran there (no terminal scope yet), the+ one-shot latch used to write B's docker policy into process-global env and+ every later unscoped launch-profile tool call inherited it.+ """+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override++ launch_home = tmp_path / "launch"+ secondary_home = tmp_path / "profiles" / "docker-bee"+ launch_home.mkdir(parents=True)+ secondary_home.mkdir(parents=True)+ (launch_home / "config.yaml").write_text(+ "terminal:\n backend: local\n", encoding="utf-8"+ )+ (secondary_home / "config.yaml").write_text(+ "terminal:\n"+ " backend: docker\n"+ " docker_image: bee/local:1\n"+ ' docker_volumes:\n'+ ' - /bee/vol:/data\n',+ encoding="utf-8",+ )+ monkeypatch.setenv("HERMES_HOME", str(launch_home))+ # Clean ambient — the dashboard process starts without TERMINAL_ENV.+ for name in (+ "TERMINAL_ENV",+ "TERMINAL_DOCKER_IMAGE",+ "TERMINAL_DOCKER_VOLUMES",+ ):+ monkeypatch.delenv(name, raising=False)++ token = set_hermes_home_override(str(secondary_home))+ try:+ # Unscoped call under secondary home (the residual path).+ terminal_tool._ensure_terminal_env_bridged()+ finally:+ reset_hermes_home_override(token)++ assert "TERMINAL_ENV" not in os.environ+ assert "TERMINAL_DOCKER_IMAGE" not in os.environ+ assert "TERMINAL_DOCKER_VOLUMES" not in os.environ+ # Bridge must still be available for the real launch profile afterwards.+ assert terminal_tool._terminal_config_bridge_attempted is False++ config = terminal_tool._get_env_config()+ assert config["env_type"] == "local"+ assert os.environ["TERMINAL_ENV"] == "local"+ assert "bee/local:1" not in os.environ.get("TERMINAL_DOCKER_IMAGE", "")diff --git a/tools/terminal_tool.py b/tools/terminal_tool.pyindex 736e8e2ba0e..46ceeb586b9 100644--- a/tools/terminal_tool.py+++ b/tools/terminal_tool.py@@ -540,12 +540,25 @@ def _ensure_terminal_env_bridged() -> None:suppresses the bridge entirely: writing scope values into the process-globalenv would re-create the first-writer-wins cross-profile leak the scope fixes.+ Ambient ``os.environ`` is the *launch* profile's authority only. Under a+ context-local ``HERMES_HOME`` override (multiplexed dashboard / gateway+ secondary profile), this bridge is a no-op — otherwise the first unscoped+ call under that override would latch the secondary profile's ``terminal.*``+ into process-global env and poison later unscoped launch-profile turns+ (#107422 residual of #68559). Routed profiles must bind a terminal scope+ instead (same rule as ``env_loader._reapply_terminal_config_bridge``).+terminal_tool reads ALL terminal settings from os.environ (TERMINAL_*). See #61115, #65696."""from tools.terminal_scope import get_terminal_scopeif get_terminal_scope() is not None:return+ # Never write a secondary profile's terminal.* into process-global env.+ from hermes_constants import get_hermes_home_override++ if get_hermes_home_override() is not None:+ returnglobal _terminal_config_bridge_attemptedif _terminal_config_bridge_attempted:return