Skip to content

The agent that grows with you

fix(kanban): scope the stop nudge to the dispatcher-owned worker

jerryhjones2bd0f1c59e59
diff --git a/agent/kanban_stop.py b/agent/kanban_stop.py
index 5f4669bdb85..029fbe103c8 100644
--- a/agent/kanban_stop.py
+++ b/agent/kanban_stop.py
@@ -9,6 +9,8 @@ from __future__ import annotations
import os
from typing import Any, Iterable, Optional
+from agent.delegation_context import is_dispatcher_owned_worker_context
+
_TERMINAL_KANBAN_TOOLS = frozenset({"kanban_complete", "kanban_block"})
@@ -16,10 +18,12 @@ _DEFAULT_MAX_ATTEMPTS = 2
def kanban_stop_nudge_enabled() -> bool:
- """On when ``HERMES_KANBAN_TASK`` is set, unless ``HERMES_KANBAN_STOP_NUDGE`` disables it."""
+ """On when ``HERMES_KANBAN_TASK`` is set for the dispatcher-owned worker, unless
+ ``HERMES_KANBAN_STOP_NUDGE`` disables it. In-process delegate_task children and cron runs
+ 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())
+ return bool((os.environ.get("HERMES_KANBAN_TASK") or "").strip()) and is_dispatcher_owned_worker_context()
def _tool_call_name(tc: Any) -> str:
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]
new file mode 100644
index 00000000000..9070324d6c5
--- /dev/null
+++ b/contributors/emails/[email protected]
@@ -0,0 +1,2 @@
+webdevfrancisco
+# PR #80023 credit
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]
new file mode 100644
index 00000000000..8f797c83d58
--- /dev/null
+++ b/contributors/emails/[email protected]
@@ -0,0 +1,2 @@
+jerryhjones
+# PR #84656 salvage
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]
new file mode 100644
index 00000000000..18a16c5c492
--- /dev/null
+++ b/contributors/emails/[email protected]
@@ -0,0 +1,2 @@
+Moep90
+# PR #109735 salvage
diff --git a/tests/agent/test_kanban_stop.py b/tests/agent/test_kanban_stop.py
index dbe371dd841..9dbe9c11f7e 100644
--- a/tests/agent/test_kanban_stop.py
+++ b/tests/agent/test_kanban_stop.py
@@ -29,6 +29,30 @@ def test_env_can_disable(clear_kanban_env):
assert build_kanban_stop_nudge(messages=[]) is None
+def test_nudge_disabled_inside_delegated_child(clear_kanban_env):
+ from agent.delegation_context import delegated_child_context
+
+ clear_kanban_env.setenv("HERMES_KANBAN_TASK", "t_parent")
+
+ assert kanban_stop_nudge_enabled() is True
+ with delegated_child_context():
+ assert kanban_stop_nudge_enabled() is False
+ assert build_kanban_stop_nudge(messages=[]) is None
+ assert kanban_stop_nudge_enabled() is True
+
+
+def test_nudge_disabled_inside_non_dispatcher_context(clear_kanban_env):
+ from agent.delegation_context import non_dispatcher_owned_context
+
+ clear_kanban_env.setenv("HERMES_KANBAN_TASK", "t_parent")
+
+ assert kanban_stop_nudge_enabled() is True
+ with non_dispatcher_owned_context():
+ assert kanban_stop_nudge_enabled() is False
+ assert build_kanban_stop_nudge(messages=[]) is None
+ assert kanban_stop_nudge_enabled() is True
+
+
def test_nudge_when_no_terminal_tool(clear_kanban_env):
clear_kanban_env.setenv("HERMES_KANBAN_TASK", "t_46be8aa5")
messages = [