Skip to content

The agent that grows with you

fix(kanban): stale_running reads only the current attempt's pids

Teknium971a93860c9a
diff --git a/hermes_cli/kanban_diagnostics.py b/hermes_cli/kanban_diagnostics.py
index 87a300ab902..54626ea0a14 100644
--- a/hermes_cli/kanban_diagnostics.py
+++ b/hermes_cli/kanban_diagnostics.py
@@ -764,7 +764,12 @@ def _rule_stale_running(task, events, runs, now, cfg) -> list[Diagnostic]:
from hermes_cli.kanban_db_dispatch import _worker_alive
recorded = [(_task_field(task, "worker_pid", None),
_task_field(task, "worker_started_at", None))]
+ # Only this attempt's pids speak for it: an earlier run's worker that is still alive
+ # (or whose number was reused) says nothing about whether the current run is executing.
+ run_id = _task_field(task, "current_run_id", None)
for ev in events:
+ if run_id is not None and _task_field(ev, "run_id", None) != run_id:
+ continue
if _event_kind(ev) in {"spawned", "worker_bound"}:
payload = _parse_payload(ev)
recorded.append((payload.get("pid"), payload.get("started_at")))
diff --git a/tests/hermes_cli/test_kanban_owner_receipt_reclaim.py b/tests/hermes_cli/test_kanban_owner_receipt_reclaim.py
index 3a423f9e04a..da04ba80ff4 100644
--- a/tests/hermes_cli/test_kanban_owner_receipt_reclaim.py
+++ b/tests/hermes_cli/test_kanban_owner_receipt_reclaim.py
@@ -251,3 +251,10 @@ def test_an_exited_unreaped_owner_no_longer_holds_the_slot(board):
finally:
child.wait()
+
+def test_an_earlier_runs_live_pid_does_not_hide_the_current_dead_run(board):
+ """Only the current attempt's pids speak for it in the stale_running diagnostic."""
+ run = board.dead_attempt("t_ghost")
+ board.event("t_ghost", run - 1, "spawned", {"pid": os.getpid()}, NOW - 100_000)
+ board.conn.commit()
+ assert [d.kind for d in board.diagnostics("t_ghost") if d.kind == "stale_running"] == ["stale_running"]