The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): re-kind parent-less dependency blocks as needs_input
axel-agent42a778ab4bca
diff --git a/hermes_cli/kanban_db.py b/hermes_cli/kanban_db.pyindex 03d7b1f2719..8fa12250404 100644--- a/hermes_cli/kanban_db.py+++ b/hermes_cli/kanban_db.py@@ -3069,8 +3069,11 @@ def block_task(kind: Optional[str] = None, expected_run_id: Optional[int] = None,) -> bool:"""``running``/``ready`` -> ``blocked`` (or ``todo`` / ``triage``, see- :func:`_route_block`). ``transient`` still counts toward the loop breaker- so a forever-flaky task escalates. True on any transition."""+ :func:`_route_block`). ``kind='dependency'`` with no incomplete parent is+ re-kinded to ``needs_input`` (sticky) so ``recompute_ready`` cannot+ promote it into a context-free respawn. ``transient`` still counts+ toward the loop breaker so a forever-flaky task escalates. True on any+ transition."""if kind is not None and kind not in VALID_BLOCK_KINDS:raise ValueError(f"block kind must be one of {sorted(VALID_BLOCK_KINDS)} or None")with write_txn(conn):@@ -3080,10 +3083,22 @@ def block_task(if cur_row is None:return Falsesource_status = _retry_status_for_run(conn, task_id) if cur_row["status"] == "running" else "ready"+ requested_kind = kind+ rekind_reason = None+ # ``dependency`` only waits on incomplete parents. A worker filing that+ # kind with none open would park in ``todo`` and ``recompute_ready``+ # would promote+respawn it context-free on the next tick. Re-kind to+ # ``needs_input`` so it is sticky until a human unblocks.+ if kind == "dependency" and _parents_satisfied(conn, task_id):+ kind = "needs_input"+ rekind_reason = "no_open_parent"new_status, event_kind, set_sql, params, payload = _route_block(kind, reason, source_status, prev_kind=_row_get(cur_row, "block_kind"),prev_recurrences=int(_row_get(cur_row, "block_recurrences") or 0),)+ if rekind_reason:+ payload["requested_kind"] = requested_kind+ payload["rekind_reason"] = rekind_reasonsql = f"""UPDATE tasksSET status = '{new_status}',@@ -3121,7 +3136,9 @@ def _route_block(``dependency`` never enters the human ``blocked`` bucket: it waits in``todo`` for ``recompute_ready``, so a cron never sees a dependency-wait- as something to "unblock". Every other kind counts unblock-loop+ as something to "unblock". Callers that pass ``dependency`` with no+ incomplete parent are re-kinded to ``needs_input`` before this runs+ (see :func:`block_task`). Every other kind counts unblock-looprecurrences: block_task only fires from running/ready (AFTER an unblockreturned the task to the pool), so a stored ``block_kind`` equal to theincoming one means blocked -> unblocked -> re-block for the same causediff --git a/tests/hermes_cli/test_kanban_block_kinds.py b/tests/hermes_cli/test_kanban_block_kinds.pyindex 4646efd9920..dbc19085ae6 100644--- a/tests/hermes_cli/test_kanban_block_kinds.py+++ b/tests/hermes_cli/test_kanban_block_kinds.py@@ -23,6 +23,7 @@ import pytestfrom hermes_cli import kanban_db as kbfrom hermes_cli import kanban_db_connect as kbc+from hermes_cli import kanban_db_dispatch as kbd@pytest.fixture@@ -101,6 +102,149 @@ 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'``."""+ 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",+ )+ parked = kb.get_task(conn, child)+ assert parked is not None+ assert parked.status == "blocked"+ assert parked.block_kind == "needs_input"+ 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] = []++ 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"+++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."""+ spawns: list[str] = []++ def fake_spawn(task, workspace, board=None):+ spawns.append(task.id)+ return 4242++ 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+ kb.link_tasks(conn, parent_id=parent, child_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 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",+ )++# ---------------------------------------------------------------------------# Completion resets loop memory# ---------------------------------------------------------------------------diff --git a/tests/tools/test_kanban_tools.py b/tests/tools/test_kanban_tools.pyindex 43de32de092..b8d3a2df6af 100644--- a/tests/tools/test_kanban_tools.py+++ b/tests/tools/test_kanban_tools.py@@ -346,6 +346,39 @@ def test_block_goal_mode_rejects_disallowed_kind(monkeypatch, tmp_path):conn.close()+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.+ """+ 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()++def test_heartbeat_extends_claim_expires(worker_env):"""The kanban_heartbeat tool MUST extend claim_expires, not justupdate last_heartbeat_at — otherwise long-running workers loop thediff --git a/tools/kanban_tools.py b/tools/kanban_tools.pyindex e847f0359c9..88497ff5881 100644--- a/tools/kanban_tools.py+++ b/tools/kanban_tools.py@@ -651,7 +651,17 @@ 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)")- return _ok_landed(kb, conn, tid, "blocked", block_kind=kind)+ 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":+ 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."+ )+ return _ok_landed(kb, conn, tid, "blocked", **extra)@_kanban_handler("kanban_request_review")diff --git a/tools/kanban_tools_schemas.py b/tools/kanban_tools_schemas.pyindex b6f4be7fb6d..dbe7312d021 100644--- a/tools/kanban_tools_schemas.py+++ b/tools/kanban_tools_schemas.py@@ -190,8 +190,9 @@ KANBAN_BLOCK_SCHEMA = _schema("enum": ["dependency", "needs_input", "capability", "transient"],"description": ("Why you're blocked. 'dependency' waits in todo and "- "resumes automatically; the others surface to a human. "- "Omit only if none apply."+ "resumes automatically when an incomplete parent finishes; "+ "if no parent is open it is recorded as needs_input instead. "+ "The others surface to a human. Omit only if none apply."),},},