The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): clear fleet restart warning for multiplexers
KoNit-Ke5fe22646ea3
diff --git a/hermes_cli/update_cmd_fleet.py b/hermes_cli/update_cmd_fleet.pyindex 7f6d5ad95f9..aa15026174e 100644--- a/hermes_cli/update_cmd_fleet.py+++ b/hermes_cli/update_cmd_fleet.py@@ -171,6 +171,29 @@ def _receipt_owed_gateways(receipt: dict, pending_manual: list[dict]) -> set[tupreturn 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.++ 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.+ """+ 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)+ return covered++def _live_fleet_covers_receipt(expected_sha: str | None, receipt: dict, owed: set[tuple[str, str]] | None, *, accept_states: tuple = ("current",)) -> bool:"""Require a successor at the expected SHA for every owed gateway identity."""if not expected_sha:@@ -189,7 +212,13 @@ def _live_fleet_covers_receipt(expected_sha: str | None, receipt: dict, owed: sefor row in fleet):return False- return owed <= {("gateway", row.get("profile")) for row in fleet}+ 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}except Exception as exc:logger.debug("Could not reconcile pending fleet identities: %s", exc)return False@@ -246,13 +275,18 @@ def _marker_only_restart_obsolete() -> bool:for row in fleet:if not isinstance(row, dict):return False- profile = row.get("profile")- if not profile or profile == "unknown":+ if _fleet_row_covered_gateway_profiles(row) is None: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 not owed <= {("gateway", row.get("profile")) for row in fleet}:- return False # A gateway this marker owns is absent.+ 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}:+ return False # A gateway this marker owns 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/hermes_cli/update_receipt.py b/hermes_cli/update_receipt.pyindex d649e7486b4..06d7ed86363 100644--- a/hermes_cli/update_receipt.py+++ b/hermes_cli/update_receipt.py@@ -295,14 +295,24 @@ def _socket_identity(home: Path) -> Optional[tuple[int, dict]]:def _fleet_row(- profile: str, pid: int, code_sha: Any, code_version: Any, expected_sha: Any, state: str = "unknown"+ profile: str, pid: int, code_sha: Any, code_version: Any, expected_sha: Any,+ state: str = "unknown", served_profiles: Any = None,) -> dict[str, Any]:if state == "unknown" and code_sha and expected_sha:state = "current" if str(code_sha) == str(expected_sha) else "stale"- return {+ row = {"profile": profile, "pid": pid, "code_sha": str(code_sha) if code_sha else None,"code_version": code_version, "state": state,}+ # A live, identity-verified multiplexer represents every profile in this+ # list. Keep the field only when its shape is usable: callers use it to+ # discharge per-profile restart obligations, so corrupt status must not+ # widen coverage.+ if isinstance(served_profiles, list) and served_profiles and all(+ isinstance(name, str) and name for name in served_profiles+ ):+ row["served_profiles"] = list(dict.fromkeys(served_profiles))+ return row# Runtime-status states that do not describe a gateway that should be running now — no down row.@@ -341,7 +351,10 @@ def collect_fleet_versions(*, pre_restart_pids: Optional[list[int]] = None) -> lsock = _socket_identity(home)if sock is not None:pid, identity = sock- row = _fleet_row(profile, pid, identity.get("code_sha"), identity.get("code_version"), expected_sha)+ row = _fleet_row(+ profile, pid, identity.get("code_sha"), identity.get("code_version"), expected_sha,+ served_profiles=identity.get("served_profiles"),+ )results.append({**row, "source": "socket"})continuerecord = read_runtime_status(home / "gateway_state.json")@@ -356,7 +369,10 @@ def collect_fleet_versions(*, pre_restart_pids: Optional[list[int]] = None) -> l# verifies that same live gateway.if live_gateway_pid_for_home(home) == pid:results.append(- _fleet_row(profile, pid, record.get("code_sha"), record.get("code_version"), expected_sha)+ _fleet_row(+ profile, pid, record.get("code_sha"), record.get("code_version"), expected_sha,+ served_profiles=record.get("served_profiles"),+ ))continue# A live non-gateway (or a gateway for another profile) can write adiff --git a/tests/hermes_cli/test_update_fleet_restart_pending.py b/tests/hermes_cli/test_update_fleet_restart_pending.pyindex 139f1b02fc5..8fbb906ed94 100644--- a/tests/hermes_cli/test_update_fleet_restart_pending.py+++ b/tests/hermes_cli/test_update_fleet_restart_pending.py@@ -719,6 +719,51 @@ def test_startup_warn_discharged_when_fleet_current(monkeypatch, capsys):assert not update_cmd._fleet_restart_pending_marker_path().exists()+def test_startup_warn_discharged_when_multiplexer_covers_owed_profiles(monkeypatch, capsys):+ """A current multiplexer discharges every profile named in its live record (#113350)."""+ 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": profile, "pid": pid}+ for profile, pid in (("default", 42), ("coder", 43))+ ]+ },+ }+ ),+ encoding="utf-8",+ )+ monkeypatch.setattr(+ "hermes_cli.update_receipt.collect_fleet_versions",+ lambda **kwargs: [+ {+ "profile": "default",+ "pid": 42,+ "code_sha": disk_sha,+ "code_version": "0.21.0",+ "state": "current",+ "served_profiles": ["default", "coder"],+ }+ ],+ )++ update_cmd._warn_pending_fleet_restart_on_startup()++ assert capsys.readouterr().err == ""+ assert not update_cmd._fleet_restart_pending_marker_path().exists()+ # The same live multiplexer coverage also discharges the receipt fallback+ # after an operator has already removed the marker.+ assert update_cmd._pending_fleet_restart_needed() is False++@pytest.mark.parametrize("disk_sha, fleet",[diff --git a/tests/hermes_cli/test_update_receipt.py b/tests/hermes_cli/test_update_receipt.pyindex 5a35785832c..664341c9408 100644--- a/tests/hermes_cli/test_update_receipt.py+++ b/tests/hermes_cli/test_update_receipt.py@@ -340,6 +340,23 @@ class TestFleetClassification:assert fleet[0]["state"] == "current"assert fleet[0]["pid"] == 4242+ def test_current_multiplexer_reports_its_served_profiles(self, monkeypatch, tmp_path):+ """One verified multiplexer is evidence for every profile it serves."""+ sha = "a" * 40+ fleet = self._fleet_with(+ monkeypatch,+ tmp_path,+ {+ "pid": 4242,+ "code_sha": sha,+ "code_version": "1.0",+ "served_profiles": ["default", "coder"],+ },+ expected_sha=sha,+ )++ assert fleet[0]["served_profiles"] == ["default", "coder"]+def test_stale_gateway(self, monkeypatch, tmp_path):fleet = self._fleet_with(monkeypatch, tmp_path,