Skip to content

The agent that grows with you

fix(env): still load the launch home's .env under multiplex routing (#125530)

Yuan Li71e89162c2d3
diff --git a/hermes_cli/env_loader.py b/hermes_cli/env_loader.py
index 398b108bf4f..c35aea5d24c 100644
--- a/hermes_cli/env_loader.py
+++ b/hermes_cli/env_loader.py
@@ -388,6 +388,21 @@ def _sanitize_env_file_if_needed(path: Path) -> None:
pass # best-effort — don't block gateway startup
+def _is_launch_home_load(home_path: Path) -> bool:
+ """Is THIS load for the process's own (launch) profile rather than a routed one?
+
+ Same launch-home identity as ``_reapply_terminal_config_bridge``: the override being set only
+ proves SOME profile is routed — under multiplex the launch profile's own scoped bodies also
+ bind an override naming the launch home (``tui_gateway.model_switch
+ ._profile_runtime_scope_tokens(None)``), and its .env is process configuration, not a foreign
+ secret (#125530).
+ """
+ try:
+ return Path(home_path).resolve() == _process_hermes_home().resolve()
+ except OSError:
+ return False
+
+
def load_hermes_dotenv(
*,
hermes_home: str | os.PathLike | None = None,
@@ -401,13 +416,16 @@ def load_hermes_dotenv(
from hermes_constants import get_process_hermes_home
home_path = Path(hermes_home) if hermes_home else get_process_hermes_home()
- # Multiplex gateway: while a routed profile-home override is active, copying that profile's .env
- # into os.environ would expose its credentials to sibling turns and every spawned child. Unscoped
- # startup loads keep the normal path; external sources still refresh against the profile mapping.
+ # Multiplex gateway: while a routed profile-home override is active, copying THAT profile's .env
+ # into os.environ would expose its credentials to sibling turns and every spawned child. The
+ # PROCESS home's .env is different: it is the launch profile's own file, already shared process
+ # configuration, so it still loads (#125530) — skipping it silently hid launch-profile-only
+ # credentials (e.g. an OPENROUTER_API_KEY backing fallback_providers) from the process env. Only
+ # a load whose target is a FOREIGN (routed) profile home is skipped.
from agent.secret_scope import is_multiplex_active
from hermes_constants import get_hermes_home_override
- if is_multiplex_active() and get_hermes_home_override() is not None:
+ if is_multiplex_active() and get_hermes_home_override() is not None and not _is_launch_home_load(home_path):
home_key = str(home_path.resolve())
if home_key not in _SCOPED_SKIP_LOGGED:
_SCOPED_SKIP_LOGGED.add(home_key)