The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(env): skip a launch-home dotenv load inside a foreign routed turn (#125530)
teknium1b6a1be64f786
diff --git a/hermes_cli/env_loader.py b/hermes_cli/env_loader.pyindex 3875582b6a4..69bf48572a5 100644--- a/hermes_cli/env_loader.py+++ b/hermes_cli/env_loader.py@@ -405,13 +405,16 @@ def load_hermes_dotenv(# into os.environ would expose its credentials to sibling turns and every spawned child. The launch# home's own .env is process configuration and still loads: the launch profile's scoped bodies bind# an override naming the launch home too, and skipping it hid launch-only credentials such as a- # fallback_providers key from the process env (#125530). External sources still refresh against- # the profile mapping.+ # fallback_providers key from the process env (#125530). Both the load's target AND the active+ # home must be the launch home: a launch-targeted load inside a FOREIGN turn re-bridges terminal.*+ # from the config the override resolves to, i.e. the routed profile's cwd into the shared env.+ # External sources still refresh against the profile mapping.from agent.secret_scope import is_multiplex_active- from hermes_constants import get_hermes_home_override+ from hermes_constants import get_hermes_home, get_hermes_home_override+ launch_home = _process_hermes_home().resolve()if (is_multiplex_active() and get_hermes_home_override() is not None- and home_path.resolve() != _process_hermes_home().resolve()):+ and (home_path.resolve() != launch_home or get_hermes_home().resolve() != launch_home)):home_key = str(home_path.resolve())if home_key not in _SCOPED_SKIP_LOGGED:_SCOPED_SKIP_LOGGED.add(home_key)diff --git a/tests/agent/test_skip_background_review.py b/tests/agent/test_skip_background_review.pyindex 9cb22b2a82b..1079b976f67 100644--- a/tests/agent/test_skip_background_review.py+++ b/tests/agent/test_skip_background_review.py@@ -110,7 +110,11 @@ def test_persistence_failure_error_fallback_is_pinned_and_leaves_final_response_memory sync and the background-review gate still see the turn as having produced nothing."""from hermes_constants import profile_cli_selector- monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes" / "profiles" / "research"))+ # A named profile home must exist before an agent is built inside it: setup_logging() now+ # opens agent.log under the ACTIVE home and refuses to materialize a missing profile.+ profile_home = tmp_path / ".hermes" / "profiles" / "research"+ profile_home.mkdir(parents=True)+ monkeypatch.setenv("HERMES_HOME", str(profile_home))selector = profile_cli_selector()assert selector.strip()agent = _make_agent()diff --git a/tests/gateway/test_multiplex_credential_isolation.py b/tests/gateway/test_multiplex_credential_isolation.pyindex a835b4e12e2..798440cc24f 100644--- a/tests/gateway/test_multiplex_credential_isolation.py+++ b/tests/gateway/test_multiplex_credential_isolation.py@@ -173,6 +173,36 @@ def test_launch_home_dotenv_still_loads_under_multiplex(tmp_path, monkeypatch):assert os.environ["LAUNCH_ONLY_FALLBACK_KEY"] == "launch-key"+def test_launch_home_load_inside_foreign_turn_keeps_routed_cwd_out_of_process_env(tmp_path, monkeypatch):+ """A launch-targeted load while a FOREIGN profile is routed is still skipped: its terminal+ bridge reads config through the override, so it would copy the routed profile's ``terminal.cwd``+ into the shared ``TERMINAL_CWD`` that the launch profile's own turns and cron jobs read."""+ import os++ from hermes_cli.env_loader import load_hermes_dotenv+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override++ launch = tmp_path / "launch"+ routed = tmp_path / "profiles" / "routed"+ launch_work = tmp_path / "work-launch"+ routed_work = tmp_path / "work-routed"+ for d in (launch, routed, launch_work, routed_work):+ d.mkdir(parents=True)+ (launch / ".env").write_text("LAUNCH_ONLY_FALLBACK_KEY=launch-key\n", encoding="utf-8")+ (launch / "config.yaml").write_text(f"terminal:\n backend: local\n cwd: {launch_work}\n", encoding="utf-8")+ (routed / "config.yaml").write_text(f"terminal:\n backend: local\n cwd: {routed_work}\n", encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(launch))+ monkeypatch.setenv("TERMINAL_CWD", str(launch_work))+ ss.set_multiplex_active(True)++ token = set_hermes_home_override(str(routed))+ try:+ assert load_hermes_dotenv(hermes_home=launch) == []+ finally:+ reset_hermes_home_override(token)+ assert os.environ["TERMINAL_CWD"] == str(launch_work)++def test_cold_profile_hydrates_external_source_without_global_env(tmp_path, monkeypatch):