Skip to content

The agent that grows with you

refactor(update): one coverage helper for both pending-restart predicates

teknium1bb0c5c41985c
diff --git a/hermes_cli/update_cmd_fleet.py b/hermes_cli/update_cmd_fleet.py
index aa15026174e..b4a7cd51c21 100644
--- a/hermes_cli/update_cmd_fleet.py
+++ b/hermes_cli/update_cmd_fleet.py
@@ -171,26 +171,19 @@ def _receipt_owed_gateways(receipt: dict, pending_manual: list[dict]) -> set[tup
return None if unverified else owed
-def _fleet_row_covered_gateway_profiles(row: dict) -> set[str] | None:
- """Profiles a current, identity-verified fleet row can vouch for.
+def _fleet_covered_gateways(fleet: list) -> set[tuple[str, str]] | None:
+ """``(kind, profile)`` identities the live rows vouch for; ``None`` when any row is unidentified.
- A multiplexer writes its live ``served_profiles`` into the same runtime
- status record that supplied the row. Its default-profile row therefore
- covers every listed satellite profile too. Malformed entries are not
- evidence: callers retain the pending obligation rather than guessing.
+ A multiplexer's row carries the ``served_profiles`` its runtime status records (``_fleet_row``
+ keeps the field only when well-formed), so one live process covers every profile it serves.
"""
- profile = row.get("profile")
- if not isinstance(profile, str) or not profile or profile == "unknown":
- return None
- covered = {profile}
- served_profiles = row.get("served_profiles")
- if served_profiles is None:
- return covered
- if not isinstance(served_profiles, list) or not served_profiles:
- return None
- if any(not isinstance(name, str) or not name or name == "unknown" for name in served_profiles):
- return None
- covered.update(served_profiles)
+ covered: set[tuple[str, str]] = set()
+ for row in fleet:
+ profile = row.get("profile") if isinstance(row, dict) else None
+ if not profile or profile == "unknown":
+ return None # unidentified runtime: the matrix cannot vouch for it
+ covered.add(("gateway", profile))
+ covered.update(("gateway", served) for served in row.get("served_profiles") or [])
return covered
@@ -212,13 +205,8 @@ def _live_fleet_covers_receipt(expected_sha: str | None, receipt: dict, owed: se
for row in fleet
):
return False
- covered_profiles: set[str] = set()
- for row in fleet:
- covered = _fleet_row_covered_gateway_profiles(row)
- if covered is None:
- return False
- covered_profiles.update(covered)
- return owed <= {("gateway", profile) for profile in covered_profiles}
+ covered = _fleet_covered_gateways(fleet)
+ return covered is not None and owed <= covered
except Exception as exc:
logger.debug("Could not reconcile pending fleet identities: %s", exc)
return False
@@ -272,20 +260,13 @@ def _marker_only_restart_obsolete() -> bool:
return False
if not fleet:
return False # Absence cannot prove recovery of the recorded inventory.
+ covered = _fleet_covered_gateways(fleet)
+ if covered is None:
+ return False # unidentified runtime: the matrix cannot vouch for it
for row in fleet:
- if not isinstance(row, dict):
- return False
- if _fleet_row_covered_gateway_profiles(row) is None:
- return False # unidentified runtime: the matrix cannot vouch for it
if row.get("state") != "current" or str(row.get("code_sha")) != expected_sha:
return False # stale / down / unknown-identity row still owes the restart
- covered_profiles: set[str] = set()
- for row in fleet:
- covered = _fleet_row_covered_gateway_profiles(row)
- if covered is None:
- return False
- covered_profiles.update(covered)
- if not owed <= {("gateway", profile) for profile in covered_profiles}:
+ if not owed <= covered:
return False # A gateway this marker owns is absent (down) or unidentifiable.
_clear_fleet_restart_pending_marker()
logger.debug(