The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): only a breaker trip stamped sticky holds the card past recompute_ready
teknium184c6e5033989
diff --git a/hermes_cli/kanban_db.py b/hermes_cli/kanban_db.pyindex 1565f9babf2..38396ade79c 100644--- a/hermes_cli/kanban_db.py+++ b/hermes_cli/kanban_db.py@@ -2064,12 +2064,14 @@ def _synthesize_ended_run(def _has_sticky_block(conn: sqlite3.Connection, task_id: str) -> bool:"""True when the newest ``blocked``/``unblocked``/``gave_up`` event says theblock must wait for an operator: an explicit ``kanban_block`` (#28712), or a- breaker trip that exhausted the clean-exit protocol-violation budget. The- violation budget is a run-history streak independent of- ``consecutive_failures``, so ``recompute_ready``'s counter check cannot see- it — without this the trip is promoted back to ``ready`` in the same tick and- the card respawns forever. A plain (unified-budget) ``gave_up`` is judged by- the counter, and a task with no such event at all (direct DB edit) auto-recovers.+ breaker trip ``_record_task_failure`` stamped ``sticky`` — the clean-exit+ protocol-violation budget or a systemic same-error wave. Those trip on a+ policy independent of ``consecutive_failures``, so ``recompute_ready``'s+ counter check cannot see them — without this the trip is promoted back to+ ``ready`` in the same tick and the card respawns forever. A plain+ (unified-budget) ``gave_up`` carries no marker and is judged by the counter,+ so raising ``failure_limit`` or ``assign_task`` to a fresh profile still+ releases it; a task with no such event at all (direct DB edit) auto-recovers."""row = conn.execute("SELECT kind FROM task_events "@@ -2084,15 +2086,7 @@ def _has_sticky_block(conn: sqlite3.Connection, task_id: str) -> bool:" (SELECT MAX(id) FROM task_events WHERE task_id = ? AND kind = 'unblocked'), 0) ""ORDER BY id DESC LIMIT 1", (task_id, task_id),).fetchone()- if not trip:- return False- verdict = _json_dict(trip["payload"])- # The breaker's own verdict: a violation-streak trip, or a trip whose limit- # was not the caller's ``failure_limit`` (systemic same-error crashes trip at 1).- return "protocol_violation_limit" in verdict or (- "effective_limit" in verdict- and int(verdict.get("failures") or 0) >= int(verdict["effective_limit"])- )+ return bool(trip) and bool(_json_dict(trip["payload"]).get("sticky"))def _latest_event(diff --git a/hermes_cli/kanban_db_dispatch.py b/hermes_cli/kanban_db_dispatch.pyindex 3c195ff61ee..5f30da9ef08 100644--- a/hermes_cli/kanban_db_dispatch.py+++ b/hermes_cli/kanban_db_dispatch.py@@ -1229,6 +1229,10 @@ def _account_crashes(conn: sqlite3.Connection, crash_details: list) -> list[str])else:is_systemic = fp_counts.get(_error_fingerprint(error_text), 0) >= 3+ extra = {"pid": pid, "claimer": claimer}+ if is_systemic:+ # Trips at 1, below any ``failure_limit``: hold it for an operator.+ extra["sticky"] = Truetripped = _record_task_failure(conn, tid,error=error_text,@@ -1236,7 +1240,7 @@ def _account_crashes(conn: sqlite3.Connection, crash_details: list) -> list[str]failure_limit=1 if is_systemic else None,release_claim=False,end_run=False,- event_payload_extra={"pid": pid, "claimer": claimer},+ event_payload_extra=extra,)if tripped:auto_blocked.append(tid)@@ -1405,6 +1409,10 @@ def _record_task_failure("retry_status": retry_status,},)+ if force_trip:+ # The caller applied its own bounded policy, so the counter cannot+ # judge this block: ``recompute_ready`` holds it for an operator.+ payload["sticky"] = Trueif event_payload_extra:payload.update(event_payload_extra)_kb._append_event(conn, task_id, "gave_up", payload, run_id=run_id)diff --git a/tests/hermes_cli/test_kanban_worker_exit_trailer.py b/tests/hermes_cli/test_kanban_worker_exit_trailer.pyindex 8162bf64c90..85a86b18578 100644--- a/tests/hermes_cli/test_kanban_worker_exit_trailer.py+++ b/tests/hermes_cli/test_kanban_worker_exit_trailer.py@@ -72,6 +72,9 @@ def test_fresh_process_sweep_books_the_logged_exit_code(kanban_home, rc, event,assert "not alive" not in (run["error"] or "")assert task.status == "ready"assert task.consecutive_failures == (1 if failure_counted else 0)+ # The decoded rc lands in the run row so quota (75) vs crash stays tellable after+ # the fact even though the worker_output tail is trimmed (#113611).+ assert kb._json_dict(run["metadata"]).get("exit_code") == rcif rc == 0:assert kb._json_dict(run["metadata"]).get("protocol_violation") is Trueassert kbd._protocol_violation_streak(conn, tid) == 1@@ -100,6 +103,35 @@ def test_violation_budget_trip_holds_until_operator_unblock(kanban_home):assert kb.get_task(conn, tid).status == "ready"+def test_plain_budget_trip_still_auto_recovers(kanban_home):+ """A unified-budget trip carries no ``sticky`` marker, so the two recovery paths on main+ survive: raising the dispatcher ``failure_limit`` past the counter promotes the card, and+ ``assign_task`` to a fresh profile (counter reset by design) promotes it too."""+ with kbc.connect() as conn:+ tids = [kb.create_task(conn, title=t, assignee="a") for t in ("raise-limit", "reassign")]+ for tid in tids:+ for i in range(2):+ kbd._record_task_failure(+ conn, tid, error=f"boom{i}", outcome="crashed", failure_limit=2,+ release_claim=False, end_run=False,+ )+ assert kb.get_task(conn, tid).status == "blocked"+ assert kb.recompute_ready(conn, failure_limit=2) == 0++ assert kb.recompute_ready(conn, failure_limit=5) == 2+ assert kb.get_task(conn, tids[0]).status == "ready"++ for i in range(2):+ kbd._record_task_failure(+ conn, tids[1], error=f"again{i}", outcome="crashed", failure_limit=2,+ release_claim=False, end_run=False,+ )+ assert kb.get_task(conn, tids[1]).status == "blocked"+ kb.assign_task(conn, tids[1], "other-profile")+ assert kb.recompute_ready(conn, failure_limit=2) == 1+ assert kb.get_task(conn, tids[1]).status == "ready"++def test_exit_single_query_writes_trailer_only_for_kanban_workers(monkeypatch, capsys):monkeypatch.delenv("HERMES_KANBAN_TASK", raising=False)with pytest.raises(SystemExit) as exc: