The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-relay): launch-home fallback only under multiplex; test pins a literal home
kshitijk4poor5403a3015529
diff --git a/tests/tools/test_bot_relay.py b/tests/tools/test_bot_relay.pyindex bb2dbb477b0..e65ca0b8376 100644--- a/tests/tools/test_bot_relay.py+++ b/tests/tools/test_bot_relay.py@@ -708,32 +708,35 @@ def test_delivery_env_carries_only_the_given_author(monkeypatch):assert env["HERMES_SESSION_STALL_TIMEOUT"] == "97"-def test_delivery_env_resolves_the_launch_home_instead_of_failing_closed():- """A relayed DM into the LAUNCH profile's Bot Chat must spawn its turn.-- ``_profile_home`` answers None for the launch profile *by design* ("already the launch profile,- no override needed"), and a relay RPC is sessionless so it binds no secret scope. That- combination left ``served_profile_child_env`` failing closed under multiplex, so every relayed- DM into a *default* profile died with "Hermes could not read this profile's API key" while- deliveries to named secondary profiles — which do resolve a home — kept working.- """- from agent.secret_scope import (- current_secret_scope, reset_secret_scope, set_multiplex_active, set_secret_scope)- from hermes_constants import get_hermes_home_override, get_routing_process_hermes_home-- assert get_hermes_home_override() is None, "precondition: no host home override in this process"- assert current_secret_scope() is None, "precondition: no scope bound on a sessionless relay RPC"-- set_multiplex_active(True)+def test_delivery_env_under_multiplex_names_the_pinned_launch_home(tmp_path, monkeypatch):+ """A relayed DM into the launch profile spawns with the launch home and its secrets, even after a+ host mirrors another home into HERMES_HOME; a bound scope still wins over the fallback."""+ from agent.secret_scope import reset_secret_scope, set_multiplex_active, set_secret_scope++ launch, mirrored = tmp_path / "launch", tmp_path / "mirrored"+ launch.mkdir()+ mirrored.mkdir()+ (launch / ".env").write_text("OPENROUTER_API_KEY=sk-launch\n", encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(launch))+ monkeypatch.delenv("OPENROUTER_API_KEY", raising=False)+ set_multiplex_active(True) # pins the launch home+ monkeypatch.setenv("HERMES_HOME", str(mirrored))++ env = bot_relay.delivery_env(None, None)+ assert env["HERMES_HOME"] == str(launch)+ assert env["OPENROUTER_API_KEY"] == "sk-launch"++ token = set_secret_scope({"OPENROUTER_API_KEY": "sk-bound"})try:- env = bot_relay.delivery_env(None, None)- assert Path(env["HERMES_HOME"]).resolve() == Path(get_routing_process_hermes_home()).resolve()-- # A bound scope is still the truth when one exists: it must win over the launch-home fallback.- token = set_secret_scope({"OPENROUTER_API_KEY": "sentinel-value"})- try:- assert bot_relay.delivery_env(None, None)["OPENROUTER_API_KEY"] == "sentinel-value"- finally:- reset_secret_scope(token)+ assert bot_relay.delivery_env(None, None)["OPENROUTER_API_KEY"] == "sk-bound"finally:- set_multiplex_active(False)+ reset_secret_scope(token)+++def test_delivery_env_single_profile_host_passes_the_process_env_through(tmp_path, monkeypatch):+ """Without multiplex nothing is pinned or overlaid: the child sees the process env as before."""+ (tmp_path / ".env").write_text("OPENROUTER_API_KEY=from-dotenv\n", encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ monkeypatch.setenv("OPENROUTER_API_KEY", "from-shell")++ assert bot_relay.delivery_env(None, None)["OPENROUTER_API_KEY"] == "from-shell"diff --git a/tools/bot_relay.py b/tools/bot_relay.pyindex 15265a47a94..9ce746ff675 100644--- a/tools/bot_relay.py+++ b/tools/bot_relay.py@@ -586,23 +586,20 @@ def delivery_env(author: Optional[dict], profile_home: "str | Path | None" = Nonprofile's Bot Chat turn, so it starts from THAT profile's env (``served_profile_child_env``: launchprofile ``.env`` / TERMINAL_* residue dropped, target secrets overlaid), never the multiplexer's raw``os.environ``; ``-p`` alone only pinned HERMES_HOME. ``profile_home`` is the target's home when the- caller knows it (relay RPC, roster); otherwise the active override, and failing that the launch- home — never empty, which ``served_profile_child_env`` fails closed on under multiplex."""- from agent.secret_scope import current_secret_scope+ caller knows it (relay RPC, roster); otherwise the active override, and under multiplex the launch+ home."""+ from agent.secret_scope import current_secret_scope, is_multiplex_activefrom agent.turn_author import TURN_AUTHOR_ENV, turn_author_envfrom hermes_constants import get_hermes_home_override, get_routing_process_hermes_homefrom tools.environments.local import served_profile_child_env- # ``served_profile_child_env`` resolves an empty target as override -> bound scope -> and then,- # under multiplex, FAILS CLOSED. That last step is wrong for this lane: a relay RPC is- # sessionless (no scope) and ``_profile_home`` answers None for the LAUNCH profile *by design*- # ("already the launch profile, no override needed"), so "no home known" here means the launch- # profile, not "unknown". Leaving it empty broke every relayed DM into a *default* profile- # ("Hermes could not read this profile's API key") while deliveries to named secondary profiles- # — which do resolve a home — kept working. Supply the launch home only when the other two- # tiers are genuinely absent, so a bound scope still wins.+ # ``_profile_home`` answers None for the launch profile by design and a relay RPC binds no scope,+ # so under multiplex an empty target means the launch profile, not "unknown" (the fail-closed+ # raise). Same shape as the slash-worker spawn (#115427); a bound scope or override still wins,+ # and a single-profile host keeps its pass-through env.target_home = profile_home- if not target_home and not get_hermes_home_override() and current_secret_scope() is None:+ if (not target_home and is_multiplex_active() and not get_hermes_home_override()+ and current_secret_scope() is None):target_home = get_routing_process_hermes_home()env = served_profile_child_env(base=os.environ, target_home=target_home, inherit_credentials=True)env.pop(TURN_AUTHOR_ENV, None)