Skip to content

The agent that grows with you

fix(kanban): treat review-handoff tools as terminal in the stop guard

wuli66642500bf0cba4
diff --git a/agent/kanban_stop.py b/agent/kanban_stop.py
index ec6aab2e359..eaade9ac300 100644
--- a/agent/kanban_stop.py
+++ b/agent/kanban_stop.py
@@ -1,7 +1,9 @@
-"""Turn-end guard for kanban workers, which must end with ``kanban_complete`` or
-``kanban_block``. Some models narrate the next step and stop with no tool calls;
-Hermes treats that as a clean exit → ``rc=0`` → dispatcher ``protocol_violation``.
-Policy-only: return a bounded synthetic nudge so the loop continues instead of exiting.
+"""Turn-end guard for kanban workers, which must end with a terminal board tool that hands
+the card to whoever owns it next (``kanban_complete``, ``kanban_block``,
+``kanban_request_review``, ``kanban_request_changes``). Some models narrate the next step
+and stop with no tool calls; Hermes treats that as a clean exit → ``rc=0`` → dispatcher
+``protocol_violation``. Policy-only: return a bounded synthetic nudge so the loop continues
+instead of exiting.
"""
from __future__ import annotations
@@ -12,7 +14,17 @@ from typing import Any, Iterable, Optional
from agent.delegation_context import owned_kanban_task
-_TERMINAL_KANBAN_TOOLS = frozenset({"kanban_complete", "kanban_block"})
+# Every tool that ends this worker's responsibility for the card, not just the two that
+# close it out: ``kanban_request_review`` moves it to ``review`` (goals.py's continuation /
+# finalize prompts tell builders to call it) and ``kanban_request_changes`` returns it to
+# ``ready`` (the sdlc-review skill tells reviewers to). Nudging after either asks a worker
+# that did the right thing to ``kanban_complete`` a card it must not close.
+_TERMINAL_KANBAN_TOOLS = frozenset({
+ "kanban_complete",
+ "kanban_block",
+ "kanban_request_review",
+ "kanban_request_changes",
+})
_DEFAULT_MAX_ATTEMPTS = 2
diff --git a/tests/agent/test_kanban_stop.py b/tests/agent/test_kanban_stop.py
index 9dbe9c11f7e..d8acd6cf1e6 100644
--- a/tests/agent/test_kanban_stop.py
+++ b/tests/agent/test_kanban_stop.py
@@ -112,3 +112,59 @@ def test_no_nudge_after_kanban_complete(clear_kanban_env):
+
+
+ "tool_name,who",
+ [
+ ("kanban_request_review", "build worker handing off for same-card review"),
+ ("kanban_request_changes", "review agent sending the card back"),
+ ],
+)
+def test_no_nudge_after_handoff_tool(clear_kanban_env, tool_name, who):
+ """Handoff tools end the worker's turn just like complete/block.
+
+ Both move the card out of ``running``, and the worker is told to call
+ them — goals.py's continuation/finalize prompts name
+ ``kanban_request_review``; the force-loaded sdlc-review skill names
+ ``kanban_request_changes``. Nudging afterwards asks a worker that did
+ the right thing to close a card it must not close.
+ """
+ clear_kanban_env.setenv("HERMES_KANBAN_TASK", "t_handoff")
+ messages = [
+ {
+ "role": "assistant",
+ "content": "",
+ "tool_calls": [
+ {
+ "id": "1",
+ "type": "function",
+ "function": {"name": tool_name, "arguments": "{}"},
+ }
+ ],
+ },
+ {"role": "tool", "name": tool_name, "tool_call_id": "1", "content": "ok"},
+ ]
+ assert session_called_kanban_terminal(messages) is True, who
+ assert build_kanban_stop_nudge(messages=messages) is None
+
+
+def test_nudge_still_fires_for_non_terminal_kanban_tool(clear_kanban_env):
+ """Widening the set must not swallow the case the guard exists for."""
+ clear_kanban_env.setenv("HERMES_KANBAN_TASK", "t_abc")
+ messages = [
+ {
+ "role": "assistant",
+ "content": "Let me open the review next.",
+ "tool_calls": [
+ {
+ "id": "1",
+ "type": "function",
+ "function": {"name": "kanban_comment", "arguments": "{}"},
+ }
+ ],
+ },
+ {"role": "tool", "name": "kanban_comment", "tool_call_id": "1", "content": "ok"},
+ ]
+ assert session_called_kanban_terminal(messages) is False
+ assert build_kanban_stop_nudge(messages=messages) is not None