The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(env_loader): log routed-scope dotenv skip once per home; port single-profile control test
Teknium0a6aa7cce1be
diff --git a/hermes_cli/env_loader.py b/hermes_cli/env_loader.pyindex 7afca4229b2..a0e1fbfd95a 100644--- a/hermes_cli/env_loader.py+++ b/hermes_cli/env_loader.py@@ -51,6 +51,10 @@ _SECRET_SOURCE_VALUES_BY_HOME: dict[str, dict[str, str]] = {}_APPLIED_HOMES: set[str] = set()_SECRET_SOURCE_CACHE_LOCK = threading.RLock()+# Routed profile homes whose dotenv load was skipped under multiplex, so the+# skip is logged once per home rather than on every lazy import mid-turn.+_SCOPED_SKIP_LOGGED: set[str] = set()+def _known_hermes_env_keys() -> set[str]:"""Return the combined set of known Hermes env-var keys.@@ -501,6 +505,16 @@ def load_hermes_dotenv(from hermes_constants import get_hermes_home_overrideif is_multiplex_active() and get_hermes_home_override() is not None:+ home_key = str(home_path.resolve())+ if home_key not in _SCOPED_SKIP_LOGGED:+ _SCOPED_SKIP_LOGGED.add(home_key)+ import logging++ logging.getLogger(__name__).debug(+ "multiplex: skipping process-global dotenv load for routed "+ "profile home %s (credentials resolve via the profile scope)",+ home_path,+ )if load_external_secrets:from hermes_cli import _early_recoverydiff --git a/tests/test_env_loader_secret_sources.py b/tests/test_env_loader_secret_sources.pyindex 065270458bf..c2959144c99 100644--- a/tests/test_env_loader_secret_sources.py+++ b/tests/test_env_loader_secret_sources.py@@ -174,6 +174,36 @@ def test_cold_profile_bitwarden_uses_profile_bootstrap_without_global_env(assert os.environ.get("ANTHROPIC_API_KEY") is None+def test_single_profile_scoped_load_keeps_override_behavior(tmp_path, monkeypatch):+ """Without multiplex, a scoped load keeps its historical override behaviour.++ Ported from #77970 (@DonShelly): the guard must key on the multiplex flag,+ not on the home override alone -- single-profile ``-p`` runs still load.+ """+ from agent import secret_scope+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override++ monkeypatch.delenv("HERMES_TEST_SHARED_ADAPTER_CONFIG", raising=False)+ other_home = tmp_path / "other"+ other_home.mkdir()+ (other_home / ".env").write_text("HERMES_TEST_SHARED_ADAPTER_CONFIG=second\n")++ was_active = secret_scope.is_multiplex_active()+ secret_scope.set_multiplex_active(False)+ home_token = set_hermes_home_override(other_home)+ try:+ loaded = env_loader.load_hermes_dotenv(hermes_home=other_home)+ finally:+ secret_scope.set_multiplex_active(was_active)+ reset_hermes_home_override(home_token)++ try:+ assert os.environ.get("HERMES_TEST_SHARED_ADAPTER_CONFIG") == "second"+ assert (other_home / ".env") in loaded+ finally:+ os.environ.pop("HERMES_TEST_SHARED_ADAPTER_CONFIG", None)++def test_multiplex_dotenv_load_hydrates_sources_without_global_env(tmp_path, monkeypatch):