Skip to content

The agent that grows with you

fix(kanban): report the re-kinded dependency block on every surface, trim tests

teknium1b7e6acf4682a
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]
new file mode 100644
index 00000000000..7984c3150c0
--- /dev/null
+++ b/contributors/emails/[email protected]
@@ -0,0 +1 @@
+Roblmvp
diff --git a/hermes_cli/kanban.py b/hermes_cli/kanban.py
index 8361a74a379..94d8e323bc5 100644
--- a/hermes_cli/kanban.py
+++ b/hermes_cli/kanban.py
@@ -930,9 +930,12 @@ def _cmd_block(args: argparse.Namespace) -> int:
where = landed.status if landed else "blocked"
if where == "todo":
return f"{tid} → todo (dependency wait){suffix}"
+ if kind == "dependency" and where == "blocked":
+ return f"Blocked {tid} as needs_input (no open parent to wait on){suffix}"
if where == "triage":
# Only a typed owner-input block carries a question for a human.
- verdict = "needs a human decision" if kind == "needs_input" else "orchestration attention needed"
+ verdict = ("needs a human decision" if (landed.block_kind if landed else kind) == "needs_input"
+ else "orchestration attention needed")
return f"{tid} → triage (unblock loop detected — {verdict}){suffix}"
return f"Blocked {tid}{suffix}"
diff --git a/tests/hermes_cli/test_kanban_block_kinds.py b/tests/hermes_cli/test_kanban_block_kinds.py
index dbc19085ae6..6446465fff7 100644
--- a/tests/hermes_cli/test_kanban_block_kinds.py
+++ b/tests/hermes_cli/test_kanban_block_kinds.py
@@ -6,7 +6,9 @@ forever. The fix gives ``block_task`` a typed ``kind`` and a persistent
``block_recurrences`` counter:
* ``dependency`` blocks route to ``todo`` (parent-gated, auto-resumed) and
- never enter the human ``blocked`` bucket a cron would keep unblocking.
+ never enter the human ``blocked`` bucket a cron would keep unblocking —
+ unless no parent is open, in which case the wait can never be satisfied
+ and the block is recorded as ``needs_input`` (sticky, loop-counted).
* ``needs_input`` / ``capability`` / un-typed blocks land in ``blocked``;
each same-cause re-block after an unblock increments ``block_recurrences``,
and at ``BLOCK_RECURRENCE_LIMIT`` the task routes to ``triage`` for a human.
@@ -102,113 +104,43 @@ def test_dependency_then_parent_done_promotes(kanban_home: Path) -> None:
assert kb.get_task(conn, child).status == "ready"
-def test_dependency_block_with_no_open_parent_does_not_auto_promote(
- kanban_home: Path,
-) -> None:
- """A mislabelled ``kind='dependency'`` with no incomplete parent must
- not land in the auto-resume ``todo`` lane. ``recompute_ready`` would
- otherwise promote it on the next tick and a fresh worker would claim
- it with none of the prior context.
- """
- with kbc.connect_closing() as conn:
- tid = _running_task(conn, title="no-parent-refusal")
- assert kb.block_task(
- conn, tid,
- reason="The draft specification has failed review",
- kind="dependency",
- )
- parked = kb.get_task(conn, tid)
- assert parked is not None
- assert parked.status == "blocked"
- assert parked.block_kind == "needs_input"
- wait = [e for e in kb.list_events(conn, tid) if e.kind == "dependency_wait"]
- assert not wait, (
- "mislabelled dependency must not be recorded as dependency_wait; "
- f"got {[(e.kind, e.payload) for e in wait]}"
- )
- blocked = [e for e in kb.list_events(conn, tid) if e.kind == "blocked"]
- assert blocked, "re-kinded block must surface as a sticky blocked event"
- payload = blocked[-1].payload or {}
- assert payload.get("requested_kind") == "dependency"
- assert payload.get("rekind_reason") == "no_open_parent"
- assert payload.get("kind") == "needs_input"
- promoted = kb.recompute_ready(conn)
- assert promoted == 0
- after = kb.get_task(conn, tid)
- assert after is not None
- assert after.status == "blocked"
- assert after.status != "ready"
-
-
-def test_dependency_block_with_already_done_parent_does_not_auto_promote(
- kanban_home: Path,
-) -> None:
- """Incident shape: created with ``parents=[done_id]`` so there was never
- an open dependency, then blocked ``kind='dependency'``."""
+def test_dependency_block_with_terminal_parents_parks_then_escalates(kanban_home: Path) -> None:
+ """A ``dependency`` block whose parents are all terminal can never be
+ satisfied by ``recompute_ready``: it must park in ``blocked`` as
+ ``needs_input`` (no ``dependency_wait``, no re-promotion) and count toward
+ the loop breaker so a re-block after an unblock reaches ``triage``."""
with kbc.connect_closing() as conn:
parent = kb.create_task(conn, title="already-done-parent", assignee="worker")
with kb.write_txn(conn):
- conn.execute("UPDATE tasks SET status='ready' WHERE id=?", (parent,))
- kb.claim_task(conn, parent, claimer="worker")
- kb.complete_task(conn, parent, result="done")
- child = kb.create_task(
- conn, title="child-of-done", assignee="worker", parents=[parent],
- )
- claimed = kb.claim_task(conn, child, claimer="worker")
- assert claimed is not None
- assert kb.block_task(
- conn, child,
- reason="The draft specification has failed review",
- kind="dependency",
- )
+ conn.execute("UPDATE tasks SET status='done' WHERE id=?", (parent,))
+ child = _running_task(conn, title="child-of-done")
+ kb.link_tasks(conn, parent_id=parent, child_id=child)
+
+ assert kb.block_task(conn, child, reason="waiting on upstream", kind="dependency")
parked = kb.get_task(conn, child)
- assert parked is not None
- assert parked.status == "blocked"
- assert parked.block_kind == "needs_input"
+ assert (parked.status, parked.block_kind, parked.block_recurrences) == ("blocked", "needs_input", 1)
+ events = kb.list_events(conn, child)
+ assert not [e for e in events if e.kind == "dependency_wait"]
+ blocked = [e for e in events if e.kind == "blocked"][-1].payload
+ assert (blocked["requested_kind"], blocked["rekind_reason"]) == ("dependency", "no_open_parent")
assert kb.recompute_ready(conn) == 0
- after = kb.get_task(conn, child)
- assert after is not None
- assert after.status == "blocked"
-
-
-def test_mislabelled_dependency_block_is_not_reclaimed_on_next_dispatch_tick(
- kanban_home: Path, all_assignees_spawnable,
-) -> None:
- """Full tick: block kind=dependency with no open parent, then
- ``dispatch_once`` must not promote+spawn a second worker."""
- spawns: list[str] = []
+ assert kb.get_task(conn, child).status == "blocked"
- def fake_spawn(task, workspace, board=None):
- spawns.append(task.id)
- return 4242
-
- with kbc.connect() as conn:
- tid = kb.create_task(conn, title="refusal", assignee="alice")
- assert kb.claim_task(conn, tid, claimer="alice") is not None
- assert kb.block_task(
- conn, tid,
- reason="needs a human decision, filed as dependency",
- kind="dependency",
- )
- res = kbd.dispatch_once(conn, spawn_fn=fake_spawn)
- after = kb.get_task(conn, tid)
- assert after is not None
- spawned_ids = [row[0] for row in res.spawned]
- assert tid not in spawned_ids, (
- f"tick re-claimed the mislabelled card: spawned={res.spawned!r} "
- f"promoted={res.promoted} status={after.status!r}"
- )
- assert tid not in spawns
- assert res.promoted == 0
- assert after.status == "blocked"
- assert after.block_kind == "needs_input"
+ # A cron/human unblocks; the worker re-declares the same impossible wait.
+ assert kb.unblock_task(conn, child)
+ assert kb.claim_task(conn, child, claimer="worker") is not None
+ assert kb.block_task(conn, child, reason="still waiting", kind="dependency")
+ assert kb.get_task(conn, child).status == "triage"
+ loop = [e for e in kb.list_events(conn, child) if e.kind == "block_loop_detected"][-1].payload
+ assert loop["recurrences"] == kb.BLOCK_RECURRENCE_LIMIT
def test_dependency_block_with_open_parent_stays_parked_across_dispatch_tick(
kanban_home: Path, all_assignees_spawnable,
) -> None:
- """Legitimate fan-in: an incomplete parent must still park in todo and
- auto-resume only after that parent finishes."""
+ """Control: a genuine wait on an incomplete parent parks in ``todo``
+ without counting a recurrence, survives a dispatch tick unspawned, and
+ resumes once the parent finishes."""
spawns: list[str] = []
def fake_spawn(task, workspace, board=None):
@@ -217,32 +149,24 @@ def test_dependency_block_with_open_parent_stays_parked_across_dispatch_tick(
with kbc.connect() as conn:
parent = kb.create_task(conn, title="open-parent", assignee="alice")
- child = kb.create_task(conn, title="waiter", assignee="alice")
- with kb.write_txn(conn):
- conn.execute("UPDATE tasks SET status='ready' WHERE id=?", (child,))
- assert kb.claim_task(conn, child, claimer="alice") is not None
+ child = _running_task(conn, title="waiter")
kb.link_tasks(conn, parent_id=parent, child_id=child)
+ for _ in range(kb.BLOCK_RECURRENCE_LIMIT + 1):
+ assert kb.block_task(conn, child, reason="wait", kind="dependency")
+ parked = kb.get_task(conn, child)
+ assert (parked.status, parked.block_kind, parked.block_recurrences) == ("todo", "dependency", 0)
+ with kb.write_txn(conn):
+ conn.execute("UPDATE tasks SET status='running' WHERE id=?", (child,))
assert kb.block_task(conn, child, reason="wait", kind="dependency")
- parked = kb.get_task(conn, child)
- assert parked is not None
- assert parked.status == "todo"
- assert parked.block_kind == "dependency"
res = kbd.dispatch_once(conn, spawn_fn=fake_spawn)
- still = kb.get_task(conn, child)
- assert still is not None
- assert still.status == "todo"
+ assert kb.get_task(conn, child).status == "todo"
assert child not in spawns
- assert child not in [row[0] for row in res.spawned]
with kb.write_txn(conn):
conn.execute("UPDATE tasks SET status='ready' WHERE id=?", (parent,))
kb.claim_task(conn, parent, claimer="alice")
kb.complete_task(conn, parent, result="done")
res2 = kbd.dispatch_once(conn, spawn_fn=fake_spawn)
- resumed = kb.get_task(conn, child)
- assert resumed is not None
- assert child in [row[0] for row in res2.spawned] or resumed.status in (
- "ready", "running",
- )
+ assert child in [row[0] for row in res2.spawned]
# ---------------------------------------------------------------------------
diff --git a/tests/tools/test_kanban_tools.py b/tests/tools/test_kanban_tools.py
index b8d3a2df6af..0bb4241ae74 100644
--- a/tests/tools/test_kanban_tools.py
+++ b/tests/tools/test_kanban_tools.py
@@ -347,36 +347,14 @@ def test_block_goal_mode_rejects_disallowed_kind(monkeypatch, tmp_path):
def test_block_dependency_without_open_parent_is_rekinded(worker_env):
- """kind=dependency with no incomplete parent must not park in todo.
- The tool records needs_input and tells the worker why.
- """
+ """kind=dependency with no incomplete parent must not park in todo; the
+ tool reports the landed kind and tells the worker why."""
from tools import kanban_tools as kt
- from hermes_cli import kanban_db as kb
- from hermes_cli import kanban_db_connect as kbc
-
- out = kt._handle_block({
- "reason": "The draft specification has failed review",
- "kind": "dependency",
- })
- d = json.loads(out)
- assert d.get("ok") is True
- assert d.get("status") == "blocked"
- assert d.get("block_kind") == "needs_input"
- assert d.get("requested_kind") == "dependency"
- assert d.get("rekind_reason") == "no_open_parent"
- assert "incomplete parent" in (d.get("note") or "")
- conn = kbc.connect()
- try:
- task = kb.get_task(conn, worker_env)
- assert task is not None
- assert task.status == "blocked"
- assert task.block_kind == "needs_input"
- kinds = [e.kind for e in kb.list_events(conn, worker_env)]
- assert "dependency_wait" not in kinds
- assert "blocked" in kinds
- finally:
- conn.close()
+ d = json.loads(kt._handle_block({"reason": "upstream input is missing", "kind": "dependency"}))
+ assert (d["ok"], d["status"], d["block_kind"]) == (True, "blocked", "needs_input")
+ assert d["requested_kind"] == "dependency"
+ assert "no parent is open" in d["note"]
def test_heartbeat_extends_claim_expires(worker_env):
diff --git a/tools/kanban_tools.py b/tools/kanban_tools.py
index 88497ff5881..7192f4814d7 100644
--- a/tools/kanban_tools.py
+++ b/tools/kanban_tools.py
@@ -651,15 +651,15 @@ def _handle_block(args: dict, **kw) -> str:
f"the completion judge will evaluate it.")
ok = kb.block_task(conn, tid, reason=reason, kind=kind, expected_run_id=_worker_run_id(tid))
_check(ok, f"could not block {tid} (unknown id or not in running/ready)")
- landed = kb.get_task(conn, tid)
- extra: dict = {"block_kind": landed.block_kind if landed else kind}
- if kind == "dependency" and landed and landed.block_kind != "dependency":
+ landed_kind = kb.get_task(conn, tid).block_kind
+ extra: dict = {"block_kind": landed_kind}
+ if kind == "dependency" and landed_kind != kind:
+ # block_task re-kinds a dependency wait that no open parent can satisfy.
extra["requested_kind"] = kind
- extra["rekind_reason"] = "no_open_parent"
extra["note"] = (
- "kind='dependency' requires an incomplete parent; none were "
- "open, so this was recorded as needs_input (sticky until a "
- "human unblocks) instead of parking in todo."
+ "kind='dependency' only waits on an incomplete parent; no parent is open, "
+ "so this was recorded as needs_input (sticky until a human unblocks) "
+ "instead of parking in todo where the dispatcher would respawn it."
)
return _ok_landed(kb, conn, tid, "blocked", **extra)
diff --git a/website/docs/user-guide/features/kanban.md b/website/docs/user-guide/features/kanban.md
index 203a194dda8..5cff83e6559 100644
--- a/website/docs/user-guide/features/kanban.md
+++ b/website/docs/user-guide/features/kanban.md
@@ -398,7 +398,7 @@ Dispatcher-owned workers receive their task lifecycle tools automatically.
| `kanban_complete` | Finish with `summary` + `metadata` structured handoff. | at least one of `summary` / `result` |
| `kanban_request_review` | Start same-card review with a durable `summary`, optional `metadata`, and optional reviewer profile. The task moves to `review`; this is not a block. | `summary` |
| `kanban_request_changes` | Reviewer verdict from an active review run. Closes that run, reapplies parent gating, and routes the task to its original implementer without block-loop accounting. | `reason` |
-| `kanban_block` | Stop work and route by why: `kind=dependency` (waits in `todo`, auto-resumes), `needs_input`/`capability`/`transient` (surface to a human). Repeated same-kind re-blocks auto-escalate to `triage`. | `reason` |
+| `kanban_block` | Stop work and route by why: `kind=dependency` (waits in `todo`, auto-resumes when an incomplete parent finishes; with no open parent it is recorded as `needs_input` instead, since the wait could never be satisfied), `needs_input`/`capability`/`transient` (surface to a human). Repeated same-kind re-blocks auto-escalate to `triage`. | `reason` |
| `kanban_heartbeat` | Signal liveness during long operations. Pure side-effect. | — |
| `kanban_comment` | Append a durable note to the task thread. | `task_id`, `body` |
| `kanban_attach` | Attach a file to a task by passing its bytes inline (base64); stored under the task's attachments dir (25 MB cap). | file bytes + name |
@@ -1293,8 +1293,8 @@ Every transition appends a row to `task_events`. Each row carries an optional `r
| `promoted` | — | `todo → ready` because all parents hit `done`. `run_id` is `NULL`. |
| `claimed` | `{lock, expires, run_id}` | Dispatcher atomically claimed a `ready` task for spawn. |
| `completed` | `{result_len, summary?}` | Worker wrote `--result` / `--summary` and task hit `done`. `summary` is the first-line handoff (400-char cap); full version lives on the run row. If `complete_task` is called on a never-claimed task with handoff fields, a zero-duration run is synthesized so `run_id` still points at something. |
-| `blocked` | `{reason, kind, recurrences}` | Worker or human flipped the task to `blocked`. `kind` is the typed block reason (`needs_input`, `capability`, `transient`, or `null` for a generic block); `recurrences` is the unblock-loop counter. Synthesizes a zero-duration run when called on a never-claimed task with `--reason`. |
-| `dependency_wait` | `{reason, kind}` or `{reason: parent_not_done, demoted: true, parent}` | Worker blocked with `kind=dependency` — the task is only waiting on another task, so it routes to `todo` (parent-gated, auto-promoted) instead of `blocked`. No human needed. Also emitted when `link`/`kanban_link` puts a `ready` child under a parent that is not `done`: the child drops back to `todo` and this event records why (the `ready → running` claim re-checks parents, so nothing can run it until the parent completes or the link is removed with `hermes kanban unlink`). |
+| `blocked` | `{reason, kind, recurrences}` | Worker or human flipped the task to `blocked`. `kind` is the typed block reason (`needs_input`, `capability`, `transient`, or `null` for a generic block); `recurrences` is the unblock-loop counter. A `kind=dependency` block with no incomplete parent lands here as `needs_input` (payload adds `requested_kind: dependency`, `rekind_reason: no_open_parent`) because `todo` would only get it re-promoted and respawned on the next dispatch tick. Synthesizes a zero-duration run when called on a never-claimed task with `--reason`. |
+| `dependency_wait` | `{reason, kind}` or `{reason: parent_not_done, demoted: true, parent}` | Worker blocked with `kind=dependency` while at least one parent is still open — the task is only waiting on another task, so it routes to `todo` (parent-gated, auto-promoted) instead of `blocked` and no recurrence is counted. No human needed. Also emitted when `link`/`kanban_link` puts a `ready` child under a parent that is not `done`: the child drops back to `todo` and this event records why (the `ready → running` claim re-checks parents, so nothing can run it until the parent completes or the link is removed with `hermes kanban unlink`). |
| `block_loop_detected` | `{reason, kind, recurrences, limit}` | A task was unblocked and re-blocked for the same reason `BLOCK_RECURRENCE_LIMIT` times (default 2). Instead of landing in `blocked` again — where a cron would keep unblocking it — it routes to `triage` for orchestration attention, breaking the unblock↔re-block loop. |
| `unblocked` | — | `blocked → ready` (or `todo` if parents are still open), either manually or via `/unblock`. Resets the dispatcher's `consecutive_failures` but deliberately preserves `block_recurrences` so the loop breaker keeps its memory. `run_id` is `NULL`. |
| `archived` | — | Hidden from the default board. If the task was still running, carries the `run_id` of the run that was reclaimed as a side effect. |