Skip to content

The agent that grows with you

fix: kanban guidance and stop nudge resolve worker identity through one helper

teknium1474db5363aac
diff --git a/agent/agent_init.py b/agent/agent_init.py
index 9eab1eb5e3d..537013d77f6 100644
--- a/agent/agent_init.py
+++ b/agent/agent_init.py
@@ -1077,13 +1077,13 @@ def _load_tools(agent, enabled_toolsets, disabled_toolsets):
)
agent.valid_tool_names = {tool["function"]["name"] for tool in agent.tools} if agent.tools else set()
- # Kanban guidance is session-static for dispatcher workers only. Profiles may
- # expose kanban_show interactively without owning a task.
+ # Kanban guidance is session-static for the dispatcher-owned worker only. Profiles may
+ # expose kanban_show interactively, and children/cron runs inherit the env var, without
+ # owning a task.
+ from agent.delegation_context import owned_kanban_task
from agent.prompt_builder import KANBAN_GUIDANCE
agent._kanban_worker_guidance = (
- KANBAN_GUIDANCE
- if os.environ.get("HERMES_KANBAN_TASK") and "kanban_show" in agent.valid_tool_names
- else ""
+ KANBAN_GUIDANCE if owned_kanban_task() and "kanban_show" in agent.valid_tool_names else ""
)
if agent.quiet_mode:
return
diff --git a/agent/delegation_context.py b/agent/delegation_context.py
index 4ea7f895f0e..fac7fb638cb 100644
--- a/agent/delegation_context.py
+++ b/agent/delegation_context.py
@@ -73,6 +73,17 @@ def is_dispatcher_owned_worker_context() -> bool:
return not (is_delegated_child_process_context() or _NON_DISPATCHER_OWNED_CONTEXT.get())
+def owned_kanban_task() -> str:
+ """The board task this execution OWNS: ``HERMES_KANBAN_TASK`` for the dispatcher-owned
+ worker, ``""`` otherwise. Tool access is not worker identity — a profile can expose the
+ kanban toolset interactively, and children/cron runs inherit the env var — so every
+ reader that turns the task id into worker behaviour (guidance, stop nudge, terminal
+ outcomes) goes through this one helper."""
+ if not is_dispatcher_owned_worker_context():
+ return ""
+ return (os.environ.get("HERMES_KANBAN_TASK") or "").strip()
+
+
def is_delegated_child_process_context() -> bool:
"""Return True in this process or a subprocess spawned by a child."""
return bool(_DELEGATED_CHILD_CONTEXT.get()) or bool(os.environ.get(DELEGATED_CHILD_ENV_MARKER))
diff --git a/agent/kanban_stop.py b/agent/kanban_stop.py
index 029fbe103c8..ec6aab2e359 100644
--- a/agent/kanban_stop.py
+++ b/agent/kanban_stop.py
@@ -9,7 +9,7 @@ from __future__ import annotations
import os
from typing import Any, Iterable, Optional
-from agent.delegation_context import is_dispatcher_owned_worker_context
+from agent.delegation_context import owned_kanban_task
_TERMINAL_KANBAN_TOOLS = frozenset({"kanban_complete", "kanban_block"})
@@ -23,7 +23,7 @@ def kanban_stop_nudge_enabled() -> bool:
inherit the env var but own no board task and carry no kanban toolset."""
if (os.environ.get("HERMES_KANBAN_STOP_NUDGE") or "").strip().lower() in {"0", "false", "no", "off"}:
return False
- return bool((os.environ.get("HERMES_KANBAN_TASK") or "").strip()) and is_dispatcher_owned_worker_context()
+ return bool(owned_kanban_task())
def _tool_call_name(tc: Any) -> str:
diff --git a/agent/system_prompt.py b/agent/system_prompt.py
index 2f4cf7b7519..414928a58c3 100644
--- a/agent/system_prompt.py
+++ b/agent/system_prompt.py
@@ -17,6 +17,7 @@ import re
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple
+from agent.delegation_context import owned_kanban_task
from agent.prompt_builder import (
DEFAULT_AGENT_IDENTITY, EXECUTION_GUIDANCE_MODELS, GOOGLE_MODEL_OPERATIONAL_GUIDANCE,
HERMES_AGENT_HELP_GUIDANCE, HERMES_AGENT_HELP_GUIDANCE_NO_SKILLS, KANBAN_GUIDANCE,
@@ -285,7 +286,7 @@ def _tool_guidance_block(agent: Any) -> Optional[str]:
# Kanban lifecycle: resolved once at __init__ (_kanban_worker_guidance);
# fallback paths must also limit task protocol guidance to dispatcher workers.
_kanban_guidance = getattr(agent, "_kanban_worker_guidance", None)
- if _kanban_guidance is None and os.environ.get("HERMES_KANBAN_TASK") and "kanban_show" in names:
+ if _kanban_guidance is None and "kanban_show" in names and owned_kanban_task():
_kanban_guidance = KANBAN_GUIDANCE
tool_guidance = [
memory_guidance,
diff --git a/tests/agent/test_system_prompt.py b/tests/agent/test_system_prompt.py
index 3322eef0149..b0b9c22d97f 100644
--- a/tests/agent/test_system_prompt.py
+++ b/tests/agent/test_system_prompt.py
@@ -81,9 +81,17 @@ def test_kanban_guidance_requires_worker_task_at_agent_init(monkeypatch, task_id
assert (agent._kanban_worker_guidance == KANBAN_GUIDANCE) is expected
[email protected]("task_id, expected", [(None, False), ("t_worker", True)])
-def test_kanban_guidance_fallback_requires_worker_task(monkeypatch, task_id, expected):
- """Prompt fallback preserves the worker boundary when init was bypassed."""
[email protected]("task_id, owner, expected", [
+ (None, True, False), # interactive session with the kanban toolset enabled
+ ("t_worker", True, True), # the dispatcher-owned worker
+ ("t_worker", False, False), # cron run / delegate child inheriting the worker's env
+])
+def test_kanban_guidance_fallback_requires_owned_worker_task(monkeypatch, task_id, owner, expected):
+ """Prompt fallback preserves the worker boundary when init was bypassed: tool access
+ is not identity, and an inherited HERMES_KANBAN_TASK is not ownership (#112486)."""
+ from contextlib import nullcontext
+
+ from agent.delegation_context import non_dispatcher_owned_context
from agent.prompt_builder import KANBAN_GUIDANCE
from agent.system_prompt import _tool_guidance_block
@@ -94,7 +102,8 @@ def test_kanban_guidance_fallback_requires_worker_task(monkeypatch, task_id, exp
agent = _make_agent(valid_tool_names={"kanban_show"})
delattr(agent, "_kanban_worker_guidance")
- assert (_tool_guidance_block(agent) == KANBAN_GUIDANCE) is expected
+ with nullcontext() if owner else non_dispatcher_owned_context():
+ assert (_tool_guidance_block(agent) == KANBAN_GUIDANCE) is expected
@pytest.mark.parametrize("stores", [(True, True), (False, True), (True, False), (False, False)])