The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): discharge an unreadable-create_time manual-serve row once its pid is provably dead
liuhao1024989da7d5e7a1
diff --git a/hermes_cli/update_serve_obligations.py b/hermes_cli/update_serve_obligations.pyindex 3b513a5e16c..8c8fd6fcab1 100644--- a/hermes_cli/update_serve_obligations.py+++ b/hermes_cli/update_serve_obligations.py@@ -24,8 +24,13 @@ def defer_manual_serve(runtime: dict, *, require_alive: bool = False) -> bool:if not isinstance(detail, dict):return Falsecreated = detail.get("create_time")- if type(pid) is not int or pid <= 0 or type(created) not in (int, float) or not math.isfinite(created) or created <= 0:+ if type(pid) is not int or pid <= 0:return False+ identified = type(created) in (int, float) and math.isfinite(created) and created > 0+ if not identified:+ # Without a recorded creation time no durable reminder can be filed (#116507);+ # only a provably dead pid discharges the row, anything less stays pending.+ return not require_alive and _pid_alive_matches(pid, None) is Falsetry:alive = _pid_alive_matches(pid, created)if require_alive and alive is not True:@@ -77,7 +82,12 @@ def warn_pending_manual_serves(*, startup: bool = False, pending_manual: list[dipending_manual = retain_receipt_manual_serves(read_latest_receipt() or {})for row in pending_manual:print(f" ⚠ {row['kind']} [{row.get('profile', 'unknown')}] pid {row.get('pid', 'unknown')}: manual restart reminder could not be saved; restart remains pending in the update receipt.", file=stream)- print(" Ask its owner to relaunch `hermes serve` / `hermes dashboard`; check reminder storage permissions and free space.", file=stream)+ detail = row.get("detail") if isinstance(row.get("detail"), dict) else {}+ if type(detail.get("create_time")) in (int, float):+ print(" Ask its owner to relaunch `hermes serve` / `hermes dashboard`; check reminder storage permissions and free space.", file=stream)+ else:+ # No usable creation time means identity, not storage, blocked the durable reminder.+ print(" This host could not read the process creation time, so no durable reminder could be filed; ask its owner to relaunch `hermes serve` / `hermes dashboard`, and the warning clears once the pid is confirmed gone.", file=stream)directory = get_hermes_home() / "serve_restart_pending"for path in sorted(directory.glob("*.json")):try:diff --git a/tests/hermes_cli/test_manual_serve_deferral.py b/tests/hermes_cli/test_manual_serve_deferral.pyindex b91eee2b56b..f0e55573f7c 100644--- a/tests/hermes_cli/test_manual_serve_deferral.py+++ b/tests/hermes_cli/test_manual_serve_deferral.py@@ -9,6 +9,7 @@ from hermes_cli import process_identityfrom hermes_cli import update_cmd_fleet as fleetfrom hermes_cli import update_receiptfrom hermes_cli.update_inventory import RuntimeRecord, UpdatePlan+from hermes_cli.update_serve_obligations import defer_manual_serve, retain_receipt_manual_serves, warn_pending_manual_servesfrom hermes_constants import get_hermes_home@@ -190,3 +191,32 @@ def test_historical_retention_failure_warns_and_survives_rotation(monkeypatch, cmonkeypatch.setattr(process_identity, "_pid_alive_matches", lambda *a: False)fleet._warn_pending_fleet_restart_on_startup()assert "900" not in capsys.readouterr().err++[email protected]("kind", ["serve", "dashboard"])[email protected]("alive", [True, None, False])+def test_unreadable_create_time_discharges_only_a_proven_dead_pid(monkeypatch, kind, alive):+ runtime = asdict(RuntimeRecord(kind=kind, profile="work", pid=900, supervisor="manual-serve", restart_via="respawn-argv", detail={"create_time": None}))+ monkeypatch.setattr(process_identity, "_pid_alive_matches", lambda *a: alive)+ pending = retain_receipt_manual_serves({"plan": {"runtimes": [runtime]}})+ if alive is False:+ assert pending == []+ else:+ assert pending == [runtime]+++def test_unreadable_create_time_warning_names_identity_not_storage(monkeypatch, capsys):+ runtime = asdict(RuntimeRecord(kind="serve", profile="work", pid=900, supervisor="manual-serve", restart_via="respawn-argv", detail={"create_time": None}))+ monkeypatch.setattr(process_identity, "_pid_alive_matches", lambda *a: True)+ warn_pending_manual_serves(pending_manual=[runtime])+ out = capsys.readouterr().out+ assert "could not read the process creation time" in out+ assert "storage permissions" not in out+ assert "relaunch" in out+++def test_unreadable_create_time_still_refuses_require_alive(monkeypatch):+ runtime = asdict(RuntimeRecord(kind="serve", profile="work", pid=900, supervisor="manual-serve", restart_via="respawn-argv", detail={"create_time": None}))+ monkeypatch.setattr(process_identity, "_pid_alive_matches", lambda *a: False)+ assert defer_manual_serve(runtime, require_alive=True) is False+ assert defer_manual_serve(runtime) is True