The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: keep fleet-restart marker while a receipt-owed gateway is down
teknium1127214a66bb1
diff --git a/hermes_cli/update_cmd_fleet.py b/hermes_cli/update_cmd_fleet.pyindex 43373a3aedd..2e4cf358a7f 100644--- a/hermes_cli/update_cmd_fleet.py+++ b/hermes_cli/update_cmd_fleet.py@@ -142,6 +142,30 @@ def _receipt_reports_stale_runtime(expected_sha: str | None = None) -> bool:)+def _receipt_owed_gateways() -> set[tuple[str, str]] | None:+ """``(kind, profile)`` identities ``latest.json`` owes a current successor.++ Empty when the receipt records no runtimes; ``None`` when any recorded runtime is one+ the gateway matrix cannot vouch for (serve/dashboard, unknown profile).+ """+ from hermes_cli.update_receipt import read_latest_receipt++ receipt = read_latest_receipt() or {}+ plan = receipt.get("plan") or {}+ entries: list[tuple[object, str | None]] = [(entry, None) for entry in plan.get("runtimes") or []]+ entries.extend((entry, "gateway") for entry in receipt.get("fleet") or [])+ owed: set[tuple[str, str]] = set()+ for entry, default_kind in entries:+ if not isinstance(entry, dict):+ return None+ kind = entry.get("kind", default_kind)+ profile = entry.get("profile")+ if kind != "gateway" or not profile or profile == "unknown":+ return None+ owed.add((kind, profile))+ return owed++def _live_fleet_covers_receipt(expected_sha: str | None) -> bool:"""Require current successors for every recorded runtime, not just any live row.@@ -151,24 +175,10 @@ def _live_fleet_covers_receipt(expected_sha: str | None) -> bool:"""if not expected_sha:return False- from hermes_cli.update_receipt import collect_fleet_versions, read_latest_receipt+ from hermes_cli.update_receipt import collect_fleet_versionstry:- receipt = read_latest_receipt() or {}- plan = receipt.get("plan") or {}- runtimes = plan.get("runtimes") or []- recorded_fleet = receipt.get("fleet") or []- owed = set()- entries: list[tuple[object, str | None]] = [(entry, None) for entry in runtimes]- entries.extend((entry, "gateway") for entry in recorded_fleet)- for entry, default_kind in entries:- if not isinstance(entry, dict):- return False- kind = entry.get("kind", default_kind)- profile = entry.get("profile")- if kind != "gateway" or not profile or profile == "unknown":- return False- owed.add((kind, profile))+ owed = _receipt_owed_gateways()if not owed:return Falsefleet = collect_fleet_versions()@@ -210,6 +220,12 @@ def _marker_only_restart_obsolete() -> bool:gateways cannot prove currency — same conservatism as the silent-failure class#88848/#74973), on a marker with no ``expected_sha``, when a newer pull moved thecheckout, and when the probe fails or answers empty.++ A gateway the restart phase stopped and never brought back yields NO row at startup+ (no ``pre_restart_pids`` → no ``down`` classification), so rows alone cannot prove the+ whole fleet is back. When ``latest.json`` names the gateways the update owed, every one+ of them must also be covered by a current row; the rows-only rule applies only when the+ receipt names none."""expected_sha = _read_fleet_marker_expected_sha()if not expected_sha:@@ -220,6 +236,7 @@ def _marker_only_restart_obsolete() -> bool:try:from hermes_cli.update_receipt import collect_fleet_versionsfleet = collect_fleet_versions()+ owed = _receipt_owed_gateways()except Exception as exc:logger.debug("Fleet probe failed; keeping fleet-restart-pending marker: %s", exc)return False@@ -233,6 +250,8 @@ def _marker_only_restart_obsolete() -> bool:return False # unidentified runtime: the matrix cannot vouch for itif row.get("state") != "current" or str(row.get("code_sha")) != expected_sha:return False # stale / down / unknown-identity row still owes the restart+ if owed is None or not owed <= {("gateway", row.get("profile")) for row in fleet}:+ return False # a gateway the receipt owes is absent (down) or unidentifiable_clear_fleet_restart_pending_marker()logger.debug("Fleet-restart-pending marker discharged: %d gateway(s) already serve %s",diff --git a/tests/hermes_cli/test_update_fleet_restart_pending.py b/tests/hermes_cli/test_update_fleet_restart_pending.pyindex cb303d03e68..d89d53d1190 100644--- a/tests/hermes_cli/test_update_fleet_restart_pending.py+++ b/tests/hermes_cli/test_update_fleet_restart_pending.py@@ -661,3 +661,37 @@ def test_startup_warn_kept_without_positive_evidence(monkeypatch, capsys, disk_sassert "did not restart running gateways" in capsys.readouterr().errassert update_cmd._fleet_restart_pending_marker_path().exists()+++def test_startup_warn_kept_when_receipt_owed_gateway_is_down(monkeypatch, capsys):+ """A sibling the restart phase killed yields NO startup row; the receipt still owes it."""+ disk_sha = "e" * 40+ update_cmd._write_fleet_restart_pending_marker(expected_sha=disk_sha)+ _patch_marker_sha(monkeypatch, disk_sha)+ receipt_dir = get_hermes_home() / "logs" / "update_receipts"+ receipt_dir.mkdir(parents=True)+ (receipt_dir / "latest.json").write_text(+ json.dumps(+ {+ "outcome": "partial",+ "exit_code": 1,+ "plan": {"runtimes": [{"kind": "gateway", "profile": p, "code_sha": "o" * 40, "pid": 1} for p in ("alpha", "beta")]},+ "fleet": [+ {"profile": "alpha", "pid": 42, "code_sha": disk_sha, "state": "current"},+ {"profile": "beta", "pid": 43, "code_sha": None, "state": "down"},+ ],+ }+ ),+ encoding="utf-8",+ )+ monkeypatch.setattr(+ "hermes_cli.update_receipt.collect_fleet_versions",+ lambda **kwargs: [+ {"profile": "alpha", "pid": 42, "code_sha": disk_sha, "code_version": "0.21.0", "state": "current"}+ ],+ )++ update_cmd._warn_pending_fleet_restart_on_startup()++ assert "did not restart running gateways" in capsys.readouterr().err+ assert update_cmd._fleet_restart_pending_marker_path().exists()