The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): a stopped-but-unreaped dashboard is no longer a pre-update survivor
kshitijk4poor06fbb71c26ae
diff --git a/hermes_cli/process_identity.py b/hermes_cli/process_identity.pyindex c1d95206439..d220b8a4eee 100644--- a/hermes_cli/process_identity.py+++ b/hermes_cli/process_identity.py@@ -192,7 +192,11 @@ def _pid_alive_matches(pid: int, create_time: Optional[float], *, strict: bool =if strict:return (create_time is not None and proc.create_time() == create_timeand proc.is_running() and proc.status() != psutil.STATUS_ZOMBIE)- return _same_incarnation(proc, create_time)+ # A zombie keeps its create_time until its parent reaps it, but it is already dead: the+ # dashboard stop check (``gateway.status._pid_exists``) books it stopped, so the ledger must+ # not report it as a live pre-update survivor. Windows has no zombies (and status() is slow there).+ return _same_incarnation(proc, create_time) and (+ os.name == "nt" or proc.status() != getattr(psutil, "STATUS_ZOMBIE", "zombie"))except psutil.NoSuchProcess:return Falseexcept Exception:diff --git a/tests/hermes_cli/test_process_identity.py b/tests/hermes_cli/test_process_identity.pyindex ad3c18dc70b..603a58dc7f7 100644--- a/tests/hermes_cli/test_process_identity.py+++ b/tests/hermes_cli/test_process_identity.py@@ -17,7 +17,9 @@ from __future__ import annotationsimport jsonimport osimport stat+import subprocessimport sys+import timeimport typesfrom pathlib import Pathfrom unittest.mock import MagicMock, patch@@ -228,6 +230,29 @@ def test_ledger_entries_filters_dead_reused_and_foreign(tmp_path):assert [e["pid"] for e in live] == [100][email protected]("posix")+def test_ledger_entries_excludes_a_killed_but_unreaped_process(tmp_path):+ """A zombie is dead even though it keeps its create_time until reaped: ``hermes update``+ books the stopped dashboard gone, then must not find it again as a pre-update survivor."""+ import psutil++ child = subprocess.Popen([sys.executable, "-c", "import time; time.sleep(60)"])+ try:+ created = psutil.Process(child.pid).create_time()+ child.terminate()+ deadline = time.monotonic() + 10+ while psutil.Process(child.pid).status() != psutil.STATUS_ZOMBIE:+ assert time.monotonic() < deadline, "child never became a zombie"+ time.sleep(0.05)+ ledger = tmp_path / "spawn-ledger.json"+ ledger.write_text(json.dumps([_entry(child.pid, created, purpose="dashboard")]), encoding="utf-8")+ with patch.object(pi, "_ledger_path", return_value=ledger):+ assert pi.ledger_entries(project_root=Path("/x/install")) == []+ finally:+ child.kill()+ child.wait()++def test_spawner_is_dead_tristate():fake = _fake_psutil({500: 5.0})with patch.dict(sys.modules, {"psutil": fake}):