Skip to content

The agent that grows with you

fix(bot-mode): strip canonical session env names, keep HERMES_SESSION_* knobs

kshitijk4poord328adf61136
diff --git a/tests/tools/test_bot_relay.py b/tests/tools/test_bot_relay.py
index 19aaa4bbe34..4758defd633 100644
--- a/tests/tools/test_bot_relay.py
+++ b/tests/tools/test_bot_relay.py
@@ -617,6 +617,9 @@ def test_delivery_env_carries_only_the_given_author(monkeypatch):
monkeypatch.setenv("HERMES_SESSION_KEY", "session-A")
monkeypatch.setenv("HERMES_UI_SESSION_ID", "ui-A")
monkeypatch.setenv("HERMES_SESSION_ID", "session-A")
+ monkeypatch.setenv("HERMES_SESSION_PROFILE", "profile-A")
+ # A session-* knob, not identity: stripping it would break the child's watcher tuning.
+ monkeypatch.setenv("HERMES_SESSION_STALL_TIMEOUT", "97")
assert TURN_AUTHOR_ENV not in bot_relay.delivery_env(None)
env = bot_relay.delivery_env(bot_relay.delivery_turn_author("ops", "ops"))
@@ -625,3 +628,5 @@ def test_delivery_env_carries_only_the_given_author(monkeypatch):
assert "HERMES_SESSION_KEY" not in env
assert "HERMES_UI_SESSION_ID" not in env
assert "HERMES_SESSION_ID" not in env
+ assert "HERMES_SESSION_PROFILE" not in env
+ assert env["HERMES_SESSION_STALL_TIMEOUT"] == "97"
diff --git a/tools/bot_relay.py b/tools/bot_relay.py
index bb5f34d9a7d..eb8f2fd2b75 100644
--- a/tools/bot_relay.py
+++ b/tools/bot_relay.py
@@ -404,19 +404,29 @@ def delivery_turn_author(from_profile: Any, from_handle: Any, from_connection: A
"is_bot": True}
+def _delivery_child_session_env_names() -> "tuple[str, ...]":
+ """Session-bound env names to strip from a delivery child, from ``gateway.session_context``.
+
+ Synced with the session binding surface as vars are added; deliberately NOT a
+ ``HERMES_SESSION_*`` prefix match, which would also strip non-identity knobs
+ (e.g. ``HERMES_SESSION_STALL_TIMEOUT``)."""
+ from gateway.session_context import _VAR_MAP
+
+ return tuple(_VAR_MAP)
+
+
def delivery_env(author: Optional[dict]) -> dict[str, str]:
"""Environment for one delivery turn's ``hermes`` child. The dispatcher's own HERMES_TURN_AUTHOR is
dropped first so a delivery without an author never inherits the author of the turn that sent it.
- Dispatcher session identity (``HERMES_SESSION_*``, ``HERMES_UI_SESSION_ID``) is dropped too: a
- nested recipient that ``message_agent``s onward must not stamp that grandchild notify with the
- grandparent's key, or the live recipient never resumes."""
+ Dispatcher session identity (the canonical ``gateway.session_context`` session env names) is
+ dropped too: a nested recipient that ``message_agent``s onward must not stamp that grandchild
+ notify with the grandparent's key, or the live recipient never resumes."""
from agent.turn_author import TURN_AUTHOR_ENV, turn_author_env
env = dict(os.environ)
env.pop(TURN_AUTHOR_ENV, None)
- for key in list(env):
- if key.startswith("HERMES_SESSION_") or key == "HERMES_UI_SESSION_ID":
- env.pop(key, None)
+ for name in _delivery_child_session_env_names():
+ env.pop(name, None)
if author:
env.update(turn_author_env(author))
return env