The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): an exited, unreaped owner no longer holds its slot
Tekniumb98191b63d75
diff --git a/hermes_cli/kanban_owner_recovery.py b/hermes_cli/kanban_owner_recovery.pyindex d6a6bd5cbfe..dfeaf633952 100644--- a/hermes_cli/kanban_owner_recovery.py+++ b/hermes_cli/kanban_owner_recovery.py@@ -69,13 +69,17 @@ def _owner_process_gone(receipt) -> bool:"""True when the receipt's own pid is gone, or its number now belongs to another process.The identity rule ``owner_reclaim_paused`` already applies: a live pid whose ``birth``- differs is a recycled number, not the owner. A live pid we cannot compare (no ``birth``+ differs is a recycled number, not the owner. A zombie keeps its birth until reaped but has+ already exited, so liveness goes through the dispatcher's zombie-aware ``_pid_alive``. A live pid we cannot compare (no ``birth``recorded) and an unreadable one are never proof of death."""try:pid = int(receipt['pid'])except (KeyError, TypeError, ValueError):return False+ from hermes_cli import kanban_db as kb+ if not kb._pid_alive(pid):+ return True # absent, or an exited zombie still waiting to be reapedtry:from hermes_cli.process_identity import process_birthcurrent = process_birth(psutil.Process(pid))diff --git a/tests/hermes_cli/test_kanban_owner_receipt_reclaim.py b/tests/hermes_cli/test_kanban_owner_receipt_reclaim.pyindex c252117cb5c..3a423f9e04a 100644--- a/tests/hermes_cli/test_kanban_owner_receipt_reclaim.py+++ b/tests/hermes_cli/test_kanban_owner_receipt_reclaim.py@@ -21,6 +21,8 @@ from __future__ import annotationsimport jsonimport osimport sqlite3+import subprocess+import sysimport timefrom pathlib import Path@@ -32,6 +34,7 @@ from hermes_cli import kanban_db_connect as kbcfrom hermes_cli import kanban_db_dispatch as kbdfrom hermes_cli import kanban_diagnostics as kdfrom hermes_cli import kanban_owner_recovery+from hermes_cli.process_identity import process_birthfrom hermes_cli.kanban_owner_recovery import (bound_interpreter_gone,owner_attempt_provably_over,@@ -230,3 +233,21 @@ def test_an_interpreter_bound_after_the_gate_keeps_its_claim(board, monkeypatch,row = board.state("t_ghost")assert (row["status"], row["current_run_id"]) == ("running", run)+[email protected]("linux", "macos")+def test_an_exited_unreaped_owner_no_longer_holds_the_slot(board):+ """A zombie keeps its birth until reaped, but it has exited: it cannot be executing anything."""+ child = subprocess.Popen([sys.executable, "-c", "input()"], stdin=subprocess.PIPE)+ try:+ birth = process_birth(psutil.Process(child.pid))+ child.stdin.close()+ deadline = time.time() + 10+ while psutil.Process(child.pid).status() != psutil.STATUS_ZOMBIE:+ assert time.time() < deadline, "child never exited"+ time.sleep(0.02)+ board.dead_attempt("t_ghost", owner_pid=child.pid, owner_birth=birth)+ assert kb.release_stale_claims(board.conn) == 1+ assert board.state("t_ghost")["status"] == "ready"+ finally:+ child.wait()+