Skip to content

The agent that grows with you

fix(kanban): skip guarded review reservations

KoNit-K937e13ee66b0
diff --git a/hermes_cli/kanban_db_dispatch.py b/hermes_cli/kanban_db_dispatch.py
index 78157fda4e0..b4227814ad0 100644
--- a/hermes_cli/kanban_db_dispatch.py
+++ b/hermes_cli/kanban_db_dispatch.py
@@ -2083,15 +2083,27 @@ def _lane_rows(conn: sqlite3.Connection, status: str) -> list[sqlite3.Row]:
).fetchall()
-def _any_spawnable_review(review_rows: list[sqlite3.Row]) -> bool:
- """Mirrors the review loop's own gate so human-pulled control-plane lanes
- don't tax ready throughput; assumes spawnable when profiles are unimportable."""
+def _any_spawnable_review(
+ conn: sqlite3.Connection, review_rows: list[sqlite3.Row],
+) -> bool:
+ """Mirror review dispatch gates before reserving ready-lane capacity.
+
+ Unavailable profile metadata retains the historic fail-open behavior. A
+ respawn-guarded review row cannot consume the reservation, however, so it
+ must not withhold capacity from an otherwise ready task.
+ """
if not review_rows:
return False
profile_exists = _profile_exists_fn()
- if profile_exists is None:
- return any(row["assignee"] for row in review_rows)
- return any(row["assignee"] and profile_exists(row["assignee"]) for row in review_rows)
+ for row in review_rows:
+ assignee = row["assignee"]
+ if not assignee:
+ continue
+ if profile_exists is not None and not profile_exists(assignee):
+ continue
+ if check_respawn_guard(conn, row["id"], lane="review") is None:
+ return True
+ return False
def _resolve_default_assignee(default_assignee: Optional[str]) -> Optional[str]:
@@ -2152,7 +2164,7 @@ def _dispatch_once_locked(
# backlog. When spawnable review work exists and there is any budget, hold
# one slot back.
ready_budget = spawn_budget
- if spawn_budget is not None and spawn_budget > 0 and _any_spawnable_review(review_rows):
+ if spawn_budget is not None and spawn_budget > 0 and _any_spawnable_review(conn, review_rows):
ready_budget = max(spawn_budget - 1, 0)
# Per-profile cap. Deferred tasks go to skipped_per_profile_capped, not
# skipped_unassigned — "busy, retry later" differs from "needs routing".
diff --git a/tests/hermes_cli/test_kanban_host_cap.py b/tests/hermes_cli/test_kanban_host_cap.py
index ad0633bea09..c3f28a73ddb 100644
--- a/tests/hermes_cli/test_kanban_host_cap.py
+++ b/tests/hermes_cli/test_kanban_host_cap.py
@@ -17,6 +17,7 @@ from __future__ import annotations
import sqlite3
import threading
+import time
from pathlib import Path
import pytest
@@ -242,6 +243,58 @@ def test_review_lane_gets_reserved_slot_under_ready_backlog(
assert review_id in spawned_ids
+def test_guarded_review_does_not_reserve_the_only_ready_slot(
+ kanban_home, all_assignees_spawnable, monkeypatch,
+):
+ """A review card in cooldown must not consume fairness reservation."""
+ import hermes_cli.config as cfgmod
+
+ monkeypatch.setattr(
+ cfgmod, "load_config",
+ lambda *a, **k: {"kanban": {"review_dispatch": True}},
+ )
+
+ spawns: list = []
+ with kbc.connect() as conn:
+ ready_id = kb.create_task(conn, title="ready-now", assignee="alice")
+ review_id = _park_in_review(conn, "review-cooldown", "reviewer")
+ now = int(time.time())
+ with kb.write_txn(conn):
+ conn.execute(
+ "INSERT INTO task_runs (task_id, profile, status, outcome, "
+ "started_at, ended_at) VALUES (?, 'reviewer', 'rate_limited', "
+ "'rate_limited', ?, ?)",
+ (review_id, now, now),
+ )
+ res = kbd.dispatch_once(
+ conn, spawn_fn=_fake_spawn_factory(spawns), max_in_progress=1,
+ )
+
+ assert [task_id for task_id, *_ in res.spawned] == [ready_id]
+
+
+def test_unguarded_review_reserves_the_only_ready_slot(
+ kanban_home, all_assignees_spawnable, monkeypatch,
+):
+ """A dispatchable review card still receives the single shared slot."""
+ import hermes_cli.config as cfgmod
+
+ monkeypatch.setattr(
+ cfgmod, "load_config",
+ lambda *a, **k: {"kanban": {"review_dispatch": True}},
+ )
+
+ spawns: list = []
+ with kbc.connect() as conn:
+ kb.create_task(conn, title="ready-now", assignee="alice")
+ review_id = _park_in_review(conn, "review-now", "reviewer")
+ res = kbd.dispatch_once(
+ conn, spawn_fn=_fake_spawn_factory(spawns), max_in_progress=1,
+ )
+
+ assert [task_id for task_id, *_ in res.spawned] == [review_id]
+
+
def test_review_reservation_released_when_no_review_work(
kanban_home, all_assignees_spawnable, monkeypatch,
):