Skip to content

The agent that grows with you

fix(update): a credited unit saves the restart result once, after verification

Tekniumadd9d4f22cb7
diff --git a/hermes_cli/update_cmd_fleet_verify.py b/hermes_cli/update_cmd_fleet_verify.py
index f281188078c..256ec4ae018 100644
--- a/hermes_cli/update_cmd_fleet_verify.py
+++ b/hermes_cli/update_cmd_fleet_verify.py
@@ -160,7 +160,8 @@ def _settle_units_proven_current(restart, fleet_rows: list) -> bool:
minutes), so the restart phase's "failed" can be a gateway that came up on the new code moments
later. Proof is the unit's own process: a ``current`` row whose pid is the unit's MainPID and was
not running when the restart phase began. Another profile's current row never vouches for it.
- Returns True when a unit was credited; the phase's own incompleteness is then recomputed.
+ Returns True when a unit was credited; the phase's own incompleteness is then recomputed. The
+ caller saves the restart result once verification is done: a later check can still owe a restart.
"""
pre = restart.pre_restart_gateway_pids
if pre is None or not restart.failed_or_stale_units:
@@ -175,7 +176,6 @@ def _settle_units_proven_current(restart, fleet_rows: list) -> bool:
for unit in proven:
print(f" ✓ {unit} finished restarting onto the new code after the restart phase stopped waiting")
restart.incomplete = bool(restart.failed_or_stale_units or restart.phase_errors)
- restart.record_receipt()
if not restart.incomplete:
# The restart phase withheld this stamp; every other profile's CLI reads it.
from hermes_cli import update_cmd_fleet as fleet
@@ -356,6 +356,7 @@ def _verify_fleet_after_update(restart, *, _pre_update_plan, _windows_gateway_re
# instead of assuming the restart phase worked.
# Phase 1 (#91277): post-update fleet version verification.
_fleet_snapshot: list = []
+ _units_settled = False
with _best_effort('Fleet version verification failed: %s'):
from hermes_cli.update_receipt import print_fleet_version_matrix
# Cross-platform "rows expected" signal: (restarted_services or killed_pids)
@@ -370,7 +371,8 @@ def _verify_fleet_after_update(restart, *, _pre_update_plan, _windows_gateway_re
_pre_update_plan, _pre_restart, _windows_gateway_resume, restart.restarted_services, _killed,
)
_fleet_snapshot = _collect_fleet_snapshot(restart, _fleet_rows_expected)
- if _settle_units_proven_current(restart, _fleet_snapshot):
+ _units_settled = _settle_units_proven_current(restart, _fleet_snapshot)
+ if _units_settled:
_gateway_owed = _restart_phase_owes_gateway(restart)
restart.incomplete = restart.incomplete or bool(_dashboards_down)
if print_fleet_version_matrix(_fleet_snapshot):
@@ -472,6 +474,10 @@ def _verify_fleet_after_update(restart, *, _pre_update_plan, _windows_gateway_re
down_serves=set(_dashboards_down or ())))
with _best_effort('Fleet restart inventory not recorded: %s'):
_record_owed_gateway_inventory(_pre_update_plan, stopped)
+ if _units_settled:
+ # Credited units changed the restart result; save it with the final verdict so it agrees with
+ # the follow-up above.
+ restart.record_receipt()
with _best_effort('Update receipt finalize failed: %s'):
from hermes_cli.update_receipt import finalize_update_receipt
# A False ``update_complete`` (unsafe SQLite runtime, owed tail work) never fails the
diff --git a/tests/hermes_cli/test_update_failed_unit_proven_current.py b/tests/hermes_cli/test_update_failed_unit_proven_current.py
index 88bbf3f862f..0a54f63949f 100644
--- a/tests/hermes_cli/test_update_failed_unit_proven_current.py
+++ b/tests/hermes_cli/test_update_failed_unit_proven_current.py
@@ -35,6 +35,35 @@ OLD_PID, NEW_PID, OTHER_PID = 500, 626640, 777
)
def test_failed_unit_settles_only_on_its_own_fresh_current_gateway(
monkeypatch, capsys, main_pid, fleet_rows, settled):
+ out, receipt, cleared = _update_with_failed_unit(monkeypatch, capsys, main_pid, fleet_rows)
+ followups = [f["step"] for f in receipt.get("followups", [])]
+ if settled:
+ assert "Update incomplete" not in out
+ assert followups == []
+ assert receipt["gateway_restart"]["incomplete"] is False
+ assert receipt["gateway_restart"]["failed_units"] == []
+ assert cleared == [True]
+ else:
+ assert "Update incomplete — some units were not restarted" in out
+ assert " - hermes-gateway" in out
+ assert followups == ["gateway_restart"]
+ assert receipt["gateway_restart"]["incomplete"] is True
+ assert cleared == []
+
+
+def test_settled_unit_keeps_the_receipt_incomplete_while_a_dashboard_is_down(monkeypatch, capsys):
+ """Crediting the last failed unit must not save a complete restart while verification still owes
+ a ``gateway_restart`` follow-up (a dashboard it stopped did not come back)."""
+ out, receipt, cleared = _update_with_failed_unit(
+ monkeypatch, capsys, NEW_PID, [{"profile": "default", "pid": NEW_PID}], dashboards_down={4242})
+ assert "Update incomplete — some units were not restarted" not in out
+ assert [f["step"] for f in receipt.get("followups", [])] == ["gateway_restart"]
+ assert receipt["gateway_restart"]["failed_units"] == []
+ assert receipt["gateway_restart"]["incomplete"] is True
+ assert cleared == []
+
+
+def _update_with_failed_unit(monkeypatch, capsys, main_pid, fleet_rows, dashboards_down=None):
from hermes_cli import gateway, update_cmd, update_cmd_fleet as fleet, update_cmd_fleet_verify as verify
from hermes_cli import update_receipt
@@ -61,7 +90,7 @@ def test_failed_unit_settles_only_on_its_own_fresh_current_gateway(
monkeypatch.setattr(update_receipt, "collect_fleet_versions", lambda **kw: [dict(r) for r in rows])
monkeypatch.setattr(verify, "_time", types.SimpleNamespace(monotonic=lambda: 0.0, sleep=lambda s: None))
monkeypatch.setattr(verify, "_print_legacy_units_warning", lambda: None)
- monkeypatch.setattr("hermes_cli.update_cmd_maint._refresh_dashboard_after_update", lambda **kw: None)
+ monkeypatch.setattr("hermes_cli.update_cmd_maint._refresh_dashboard_after_update", lambda **kw: dashboards_down)
monkeypatch.setattr(update_cmd, "_surviving_pre_update_serve_runtimes", lambda plan: [])
monkeypatch.setattr("hermes_cli.gateway_migrate.maybe_auto_migrate_after_update", lambda: None)
cleared = []
@@ -74,18 +103,5 @@ def test_failed_unit_settles_only_on_its_own_fresh_current_gateway(
verify._verify_fleet_after_update(restart, _pre_update_plan=plan, _windows_gateway_resume=None,
update_complete=True)
- out = capsys.readouterr().out
receipt = json.loads((update_cmd.get_hermes_home() / "logs/update_receipts/latest.json").read_text())
- followups = [f["step"] for f in receipt.get("followups", [])]
- if settled:
- assert "Update incomplete" not in out
- assert followups == []
- assert receipt["gateway_restart"]["incomplete"] is False
- assert receipt["gateway_restart"]["failed_units"] == []
- assert cleared == [True]
- else:
- assert "Update incomplete — some units were not restarted" in out
- assert " - hermes-gateway" in out
- assert followups == ["gateway_restart"]
- assert receipt["gateway_restart"]["incomplete"] is True
- assert cleared == []
+ return capsys.readouterr().out, receipt, cleared