The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(bot-relay): resolve the launch home so a relayed DM into a default profile can spawn
nicolajbjerregaard1996-pixel390155de5665
diff --git a/tests/tools/test_bot_relay.py b/tests/tools/test_bot_relay.pyindex a39f406b842..bb2dbb477b0 100644--- a/tests/tools/test_bot_relay.py+++ b/tests/tools/test_bot_relay.py@@ -706,3 +706,34 @@ def test_delivery_env_carries_only_the_given_author(monkeypatch):assert "HERMES_SESSION_ID" not in envassert "HERMES_SESSION_PROFILE" not in envassert 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)+ 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)+ finally:+ set_multiplex_active(False)diff --git a/tools/bot_relay.py b/tools/bot_relay.pyindex a9992ea8fce..15265a47a94 100644--- a/tools/bot_relay.py+++ b/tools/bot_relay.py@@ -586,11 +586,25 @@ 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."""+ 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_scopefrom agent.turn_author import TURN_AUTHOR_ENV, turn_author_env+ from hermes_constants import get_hermes_home_override, get_routing_process_hermes_homefrom tools.environments.local import served_profile_child_env- env = served_profile_child_env(base=os.environ, target_home=profile_home, inherit_credentials=True)+ # ``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.+ target_home = profile_home+ if not target_home 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)for name in _delivery_child_session_env_names():env.pop(name, None)