The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tools): stop the terminal snapshot from persisting delegation markers
liuhao1024c44b423e5282
diff --git a/tests/tools/test_snapshot_session_id_leak.py b/tests/tools/test_snapshot_session_id_leak.pyindex 60b47614ea4..53e38ea4bb7 100644--- a/tests/tools/test_snapshot_session_id_leak.py+++ b/tests/tools/test_snapshot_session_id_leak.py@@ -107,3 +107,47 @@ def test_shared_snapshot_no_cross_session_leak(tmp_path):assert "HERMES_SESSION_ID" not in f.read()finally:env.cleanup()+++# ---------------------------------------------------------------------------+# #90782: scope-limited markers must not persist into the snapshot either.+# ---------------------------------------------------------------------------++def test_export_snippet_unsets_delegation_and_cron_session_markers():+ """The delegate_task child marker and the cron session bridge are+ injected into the SUBPROCESS env while their scope is live; a snapshot+ captured in that window must not persist them past the scope — otherwise+ every later ``source`` re-asserts them (e.g. locking kanban mutations+ out of the parent session)."""+ snippet = _export_dump_excluding_session_vars('"$__hermes_snap_tmp"')+ assert "HERMES_DELEGATED_CHILD_CONTEXT" in snippet+ assert "HERMES_CRON_SESSION" in snippet++[email protected](sys.platform == "win32", reason="POSIX bash snapshot path")+def test_snapshot_does_not_persist_delegated_child_marker(tmp_path):+ """End-to-end: a command run with the delegated-child marker in its env+ must not leave that marker in the snapshot file."""+ from tools.environments.local import LocalEnvironment++ env = LocalEnvironment(cwd=str(tmp_path), timeout=30)+ env.init_session()+ try:+ os.environ["HERMES_DELEGATED_CHILD_CONTEXT"] = "1"+ try:+ res = env.execute("echo marker-captured")+ finally:+ del os.environ["HERMES_DELEGATED_CHILD_CONTEXT"]+ assert "marker-captured" in res.get("output", "")++ snap = env._snapshot_path+ if os.path.exists(snap):+ with open(snap) as f:+ content = f.read()+ assert "HERMES_DELEGATED_CHILD_CONTEXT" not in content, (+ "the delegated-child marker leaked into the terminal "+ "snapshot — later commands would inherit it and kanban "+ "mutations would stay locked out of the parent (#90782)"+ )+ finally:+ env.cleanup()diff --git a/tools/environments/base_session_env.py b/tools/environments/base_session_env.pyindex 927b7de9669..535523caa06 100644--- a/tools/environments/base_session_env.py+++ b/tools/environments/base_session_env.py@@ -72,6 +72,14 @@ def _export_dump_excluding_session_vars(tmp_path: str, excluded_names: Iterable[# by every wrapper with ${VAR:-default} semantics; persisting them would# let the FIRST command's value override a later outer-harness value."AI_AGENT HERMES_AGENT "+ # HERMES_DELEGATED_CHILD_CONTEXT is scoped to the delegate_task child's+ # lifetime by the ContextVar, but scrub_kanban_env() injects it into the+ # SUBPROCESS env — if a snapshot is captured while that child runs, the+ # marker outlives the child and every later `source` re-asserts it,+ # locking kanban mutations out of the PARENT session (#90782).+ # HERMES_CRON_SESSION is the same shape: a per-scope bridge that must+ # not persist.+ "HERMES_DELEGATED_CHILD_CONTEXT HERMES_CRON_SESSION "f"HERMES_UI_SESSION_ID{extra_unset} 2>/dev/null; ""export -p; ) || true; } "f"> {tmp_path}")