Skip to content

The agent that grows with you

fix(kanban): pin the Hermes tree on a routed worker's PYTHONPATH

teknium1bad6cbe35bb1
diff --git a/hermes_cli/kanban_db_dispatch.py b/hermes_cli/kanban_db_dispatch.py
index 0aca56e31b6..3972eb52eda 100644
--- a/hermes_cli/kanban_db_dispatch.py
+++ b/hermes_cli/kanban_db_dispatch.py
@@ -2868,6 +2868,13 @@ def _default_spawn(task: Task, workspace: str, *, board: Optional[str] = None) -
env.pop("HERMES_TUI", None)
cmd = _worker_argv(task, profile_arg, env.get("HERMES_HOME"))
+ # The worker is `-m hermes_cli.kanban_worker_client`: Hermes itself, with no console-script
+ # bootstrap. The routed-profile scrub above strips Hermes-owned PYTHONPATH entries (user
+ # children must not see our tree), so a PYTHONPATH-launched dispatcher spawned a child that
+ # died on `No module named 'hermes_cli'` before it ever reached the owner. Same pin as cron's
+ # external worker (#112729): applied to the sanitized env, after every other decision stands.
+ from cron.scheduler_worker_env import pin_hermes_tree_on_pythonpath
+ env = pin_hermes_tree_on_pythonpath(env, Path(__file__).resolve().parent.parent)
# A worker spawned by a managed systemd gateway must leave the gateway's
# cgroup before startup; otherwise restarting the service kills the worker
# that is performing the handoff.
diff --git a/tests/hermes_cli/test_kanban_worker_terminal_scope.py b/tests/hermes_cli/test_kanban_worker_terminal_scope.py
index bec4f0748c2..88645b2d84a 100644
--- a/tests/hermes_cli/test_kanban_worker_terminal_scope.py
+++ b/tests/hermes_cli/test_kanban_worker_terminal_scope.py
@@ -7,6 +7,9 @@ The authority test is "does this worker act for a ROUTED home", exactly as ``ser
decides it. The secret scope bound around the env build is what supplies B's OWN values for the
dispatcher's declared ``terminal.env_passthrough`` names.
"""
+import os
+from pathlib import Path
+
import pytest
from hermes_cli import kanban_db_dispatch
@@ -101,3 +104,13 @@ def test_launch_profiles_own_worker_keeps_its_credentials(tmp_path, monkeypatch)
kanban_db_dispatch._default_spawn(task, str(tmp_path / "ws"))
assert captured and captured[0].get("OPENAI_API_KEY") == "dispatcher-launch-key"
+
+
+def test_worker_for_another_profile_can_still_import_hermes(profile_b, tmp_path, monkeypatch):
+ """The routed-profile scrub strips Hermes-owned PYTHONPATH entries, but the worker IS Hermes
+ (`-m hermes_cli.kanban_worker_client`): a PYTHONPATH-launched dispatcher must hand it a tree
+ it can import, or it dies on `No module named 'hermes_cli'` before reaching the owner."""
+ repo_root = Path(kanban_db_dispatch.__file__).resolve().parent.parent
+ monkeypatch.setenv("PYTHONPATH", str(repo_root))
+ env = _spawn_env_for_profile_b(monkeypatch, tmp_path)
+ assert str(repo_root) in env.get("PYTHONPATH", "").split(os.pathsep)