Skip to content

The agent that grows with you

fix(kanban): the dead-interpreter override applies only after a local kill

Teknium6f0bf3717c58
diff --git a/hermes_cli/kanban_db.py b/hermes_cli/kanban_db.py
index fe890c6861b..4279503ff55 100644
--- a/hermes_cli/kanban_db.py
+++ b/hermes_cli/kanban_db.py
@@ -2380,7 +2380,7 @@ def release_stale_claims(
with write_txn(conn):
# Again under the write lock: an interpreter that bound since the check above
# changes neither claim_lock nor worker_pid, so the CAS below cannot see it.
- if owner_reclaim_blocked_after_kill(conn, row["id"]):
+ if owner_reclaim_blocked_after_kill(conn, row["id"], signalled=bool(termination.get("termination_attempted"))):
continue
retry_status = _retry_status_for_run(conn, row["id"])
cur = conn.execute(
diff --git a/hermes_cli/kanban_db_dispatch.py b/hermes_cli/kanban_db_dispatch.py
index e1ab0bb5a94..e25346e58dd 100644
--- a/hermes_cli/kanban_db_dispatch.py
+++ b/hermes_cli/kanban_db_dispatch.py
@@ -703,8 +703,8 @@ def enforce_max_runtime(conn: sqlite3.Connection, *, signal_fn=None) -> list[str
error = f"elapsed {int(elapsed)}s > limit {limit}s"
with _kb.write_txn(conn):
# Again under the write lock, after the kill wait: an interpreter that bound
- # meanwhile is invisible to the pid/claim CAS below.
- if owner_reclaim_blocked_after_kill(conn, tid):
+ # meanwhile is invisible to the pid/claim CAS below. Host-local by the filter above.
+ if owner_reclaim_blocked_after_kill(conn, tid, signalled=True):
continue
retry_status = _kb._retry_status_for_run(conn, tid)
cur = conn.execute(
@@ -812,7 +812,7 @@ def detect_stale_running(
with _kb.write_txn(conn):
# Again under the write lock, after the termination wait (see enforce_max_runtime).
- if owner_reclaim_blocked_after_kill(conn, tid):
+ if owner_reclaim_blocked_after_kill(conn, tid, signalled=bool(termination.get("termination_attempted"))):
continue
retry_status = _kb._retry_status_for_run(conn, tid)
cur = conn.execute(
diff --git a/hermes_cli/kanban_owner_recovery.py b/hermes_cli/kanban_owner_recovery.py
index dc02ea918cd..90b51bd61c4 100644
--- a/hermes_cli/kanban_owner_recovery.py
+++ b/hermes_cli/kanban_owner_recovery.py
@@ -162,16 +162,17 @@ def owner_reclaim_blocked(conn, task_id, *, crash_sweep=False) -> bool:
return not owner_attempt_provably_over(conn, task_id)
-def owner_reclaim_blocked_after_kill(conn, task_id) -> bool:
- """The under-lock re-check for a reclaim path that has just signalled the run's worker.
-
- Killing the worker takes its bound interpreter down with it (``_watch_submitter``), and the
- owner then settles the admission ``unknown``: a pause this path caused itself, which would
- leave a timed-out run for the crash sweep to misbook ``crashed``. Only an interpreter that is
- still LIVE (one that bound after the first look) keeps the claim; a dead bound interpreter is
- the one this path just stopped.
+def owner_reclaim_blocked_after_kill(conn, task_id, *, signalled: bool) -> bool:
+ """The under-lock re-check for a reclaim path, after its termination step.
+
+ When this host just signalled the run's worker (``signalled``), killing it takes its bound
+ interpreter down too (``_watch_submitter``) and the owner settles the admission ``unknown``:
+ a pause this path caused itself, which would leave a timed-out run for the crash sweep to
+ misbook ``crashed``. Only an interpreter still LIVE (one that bound after the first look)
+ keeps the claim. Without a local signal (a foreign-host claim) the bound interpreter's pid
+ means nothing here, so a "dead" reading is no proof and the plain gate applies.
"""
- return owner_reclaim_blocked(conn, task_id, crash_sweep=True)
+ return owner_reclaim_blocked(conn, task_id, crash_sweep=signalled)
def managed_run_exit_code(conn, task_id, worker_pid, claim_lock):
diff --git a/tests/hermes_cli/test_kanban_owner_receipt_reclaim.py b/tests/hermes_cli/test_kanban_owner_receipt_reclaim.py
index 280581cca00..ea9c67cdb92 100644
--- a/tests/hermes_cli/test_kanban_owner_receipt_reclaim.py
+++ b/tests/hermes_cli/test_kanban_owner_receipt_reclaim.py
@@ -234,6 +234,29 @@ def test_an_interpreter_bound_after_the_gate_keeps_its_claim(board, monkeypatch,
assert (row["status"], row["current_run_id"]) == ("running", run)
+
[email protected]("path", ["ttl", "stale"])
+def test_a_foreign_host_interpreter_bound_after_the_gate_keeps_its_claim(board, monkeypatch, path):
+ """No local signal was sent for a foreign-host claim, so its bound interpreter's pid says
+ nothing here: an absent local pid is no proof that the remote attempt ended."""
+ run = board.dead_attempt("t_remote", lock_host="some-other-host", admission=("terminal", "completed"))
+ real_gate, calls = owner_reclaim_blocked, []
+
+ def gate_then_remote_bind(conn, task_id, **kwargs):
+ verdict = real_gate(conn, task_id, **kwargs)
+ if not calls: # the remote owner admits and binds an interpreter right after the first look
+ board.event(task_id, run, "worker_bound", {"pid": _absent_pid(base=3_700_000)}, NOW)
+ board.conn.commit()
+ with sqlite3.connect(board.ledger) as store:
+ store.execute("UPDATE session_admissions SET status = 'unknown', outcome = NULL")
+ calls.append(verdict)
+ return verdict
+
+ monkeypatch.setattr(kanban_owner_recovery, "owner_reclaim_blocked", gate_then_remote_bind)
+ assert not _RECLAIM_PATHS[path](board.conn)
+ row = board.state("t_remote")
+ assert (row["status"], row["current_run_id"]) == ("running", run)
+
@pytest.mark.platforms("linux", "macos")
def test_a_timed_out_managed_run_is_booked_timed_out_not_left_for_the_crash_sweep(board):
"""Killing a managed run's worker takes its bound interpreter down with it, and the owner