The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): keep one launch's hook consent and worker pins out of the shared daemon
Teknium8baca8e3f7d0
diff --git a/hermes_cli/gateway_runtime_start.py b/hermes_cli/gateway_runtime_start.pyindex ecd7ac4990e..4e9515a7605 100644--- a/hermes_cli/gateway_runtime_start.py+++ b/hermes_cli/gateway_runtime_start.py@@ -10,6 +10,19 @@ from hermes_cli._subprocess_compat import windows_detach_popen_kwargs, _WINDOWS_from hermes_cli.gateway_runtime_service import RuntimeStartError, remaining+# One launch's policy and pins, never the shared daemon's: hook consent would become daemon-lifetime+# auto-approval for messaging/cron, and a Kanban worker's or terminal's pins would retarget every later+# session's board, cwd and source. HERMES_INFERENCE_* fallbacks stay (the daemon's own defaults).+DAEMON_STRIPPED_ENV = (+ "HERMES_PROFILE", "HERMES_YOLO_MODE", "HERMES_IGNORE_RULES", "HERMES_SAFE_MODE",+ "HERMES_IGNORE_USER_CONFIG", "HERMES_ACCEPT_HOOKS", "HERMES_SESSION_SOURCE", "TERMINAL_CWD",+ "HERMES_KANBAN_TASK", "HERMES_KANBAN_WORKSPACE", "HERMES_KANBAN_BRANCH", "HERMES_KANBAN_RUN_ID",+ "HERMES_KANBAN_CLAIM_LOCK", "HERMES_KANBAN_CLAIM_TTL_SECONDS", "HERMES_KANBAN_GOAL_MODE",+ "HERMES_KANBAN_GOAL_MAX_TURNS", "HERMES_KANBAN_DB", "HERMES_KANBAN_WORKSPACES_ROOT",+ "HERMES_KANBAN_BOARD",+)++def spawn_unmanaged_gateway(profile_home: Path, *, deadline: float, idle_exit: bool = False) -> subprocess.Popen:"""Request a daemon, not readiness. Refuse Windows no-breakaway fallback.@@ -38,11 +51,8 @@ def spawn_unmanaged_gateway(profile_home: Path, *, deadline: float, idle_exit: b# Profile selection is the explicit home, not the invoking client's display# name. Launch-only approval/context/config flags ride the launching session's frozen# policy, not the shared daemon or every later session.- env.pop("HERMES_PROFILE", None)- env.pop("HERMES_YOLO_MODE", None)- env.pop("HERMES_IGNORE_RULES", None)- env.pop("HERMES_SAFE_MODE", None)- env.pop("HERMES_IGNORE_USER_CONFIG", None)+ for key in DAEMON_STRIPPED_ENV:+ env.pop(key, None)remaining(deadline)logs = home / "logs"logs.mkdir(parents=True, exist_ok=True)diff --git a/tests/hermes_cli/test_daemon_launch_env_strip.py b/tests/hermes_cli/test_daemon_launch_env_strip.pynew file mode 100644index 00000000000..cf8db22fe25--- /dev/null+++ b/tests/hermes_cli/test_daemon_launch_env_strip.py@@ -0,0 +1,40 @@+"""One launch's hook consent and Kanban/terminal pins never reach the auto-started shared daemon."""+import json+import os+from pathlib import Path+import sys+import time++import pytest++LEAKS = {'HERMES_ACCEPT_HOOKS': '1', 'HERMES_KANBAN_TASK': 't_1', 'HERMES_KANBAN_BOARD': 'other',+ 'HERMES_KANBAN_DB': '/x/kanban.db', 'HERMES_SESSION_SOURCE': 'kanban', 'TERMINAL_CWD': '/x'}++[email protected]("linux")[email protected]_gateway_lookalike # stub interpreter records env then exits; reaped below+def test_daemon_does_not_inherit_hook_consent_or_worker_pins(tmp_path, monkeypatch):+ from hermes_cli import gateway_runtime_start as start+ home = tmp_path / 'home'+ home.mkdir(mode=0o700)+ witness = home / 'env.json'+ executable = tmp_path / 'owned-interpreter'+ executable.write_text(+ '#!' + sys.executable + '\nimport json, os\n'+ + f'open({str(witness)!r}, "w").write(json.dumps('+ + '{k: os.environ.get(k) for k in ' + repr([*LEAKS, 'HERMES_INFERENCE_MODEL']) + '}))\n',+ encoding='utf-8')+ executable.chmod(0o700)+ monkeypatch.setattr(sys, 'executable', str(executable))+ for key, value in {**LEAKS, 'HERMES_INFERENCE_MODEL': 'fallback'}.items():+ monkeypatch.setenv(key, value)+ child = start.spawn_unmanaged_gateway(home, deadline=time.monotonic() + 5)+ try:+ assert child.wait(timeout=10) == 0+ finally:+ if child.poll() is None:+ child.kill()+ child.wait(timeout=5)+ seen = json.loads(Path(witness).read_text())+ assert seen == {**dict.fromkeys(LEAKS), 'HERMES_INFERENCE_MODEL': 'fallback'}+ assert os.environ['HERMES_ACCEPT_HOOKS'] == '1' # the launching process keeps its own policy