Skip to content

The agent that grows with you

fix(update): record a failed dashboard respawn as "failed" in the receipt

liuhao1024cc64e36ff9f6
diff --git a/hermes_cli/update_cmd_fleet.py b/hermes_cli/update_cmd_fleet.py
index be7047b6a57..8602b7695c6 100644
--- a/hermes_cli/update_cmd_fleet.py
+++ b/hermes_cli/update_cmd_fleet.py
@@ -1913,7 +1913,10 @@ def _verify_fleet_after_update(restart, *, _pre_update_plan, _windows_gateway_re
# Restart a managed dashboard via systemd or stop stale manual ones (raw-killing
# a systemd-owned PID reads as clean stop and leaves the Cloudflare origin dead).
# Already-restarted units aren't redone.
- _refresh_dashboard_after_update(already_restarted_units=set(restart.restarted_services))
+ # A dashboard it stopped and could not bring back is a promised restart that did not happen.
+ _dashboards_down = _refresh_dashboard_after_update(already_restarted_units=set(restart.restarted_services))
+ if _dashboards_down:
+ restart.incomplete = True
# Success-path twin of the abort-recovery probe: the restart phase only touches
# units, so a unit-less `hermes serve` keeps stale sys.modules. Runs AFTER
@@ -1996,6 +1999,7 @@ def _verify_fleet_after_update(restart, *, _pre_update_plan, _windows_gateway_re
if _stale_serve_rows is not None
else None
),
+ failed_respawn_pids=_dashboards_down,
)
from dataclasses import asdict
from hermes_cli.update_serve_obligations import defer_manual_serve
diff --git a/hermes_cli/update_cmd_maint.py b/hermes_cli/update_cmd_maint.py
index 8869b2d0d6a..675fa9b1296 100644
--- a/hermes_cli/update_cmd_maint.py
+++ b/hermes_cli/update_cmd_maint.py
@@ -268,8 +268,9 @@ def _finish_dashboard_update_cleanup(
stop_for_relaunch()
-def _refresh_dashboard_after_update(*, already_restarted_units: set[str] | None = None) -> None:
- """Refresh managed dashboards or stop stale manual ones after an update.
+def _refresh_dashboard_after_update(*, already_restarted_units: set[str] | None = None) -> set[int]:
+ """Refresh managed dashboards or stop stale manual ones after an update; returns the PIDs it
+ stopped and could not bring back, so the receipt records them ``failed`` (#109290).
*already_restarted_units*: systemd unit names (no ``.service``) the fleet-restart loop
already restarted, so a Serve-only install isn't restarted a second time here.
@@ -295,14 +296,16 @@ def _refresh_dashboard_after_update(*, already_restarted_units: set[str] | None
print(f"⚠ Could not refresh running dashboard/serve process(es): {exc}")
print(" If one is still running, restart it so it serves the updated code:")
print(" hermes dashboard --port <port> (or: systemctl --user restart hermes-dashboard)")
- return
- if not stop_result.get("unrecovered"):
- return
+ return set()
+ unrecovered = {int(pid) for pid in stop_result.get("unrecovered") or ()}
+ if not unrecovered:
+ return unrecovered
print()
print("⚠ A web dashboard/serve process was stopped during update and could not be auto-restarted.")
print(" Re-launch it when you want the web UI back:")
print(" hermes dashboard --port <port>")
+ return unrecovered
def _print_update_completion(message: str) -> None:
diff --git a/hermes_cli/update_inventory.py b/hermes_cli/update_inventory.py
index df6a0e622a7..4f28c53c175 100644
--- a/hermes_cli/update_inventory.py
+++ b/hermes_cli/update_inventory.py
@@ -387,7 +387,7 @@ def _gateway_named_in(r: RuntimeRecord, names: set) -> bool:
def match_runtime_outcomes(
plan: "UpdatePlan", *, restarted_services: list, relaunched_profiles: list,
externally_supervised_profiles: list, killed_pids: set, failed_units: list,
- stale_serve_pids: "set | None" = None,
+ stale_serve_pids: "set | None" = None, failed_respawn_pids: "set | None" = None,
) -> list[dict[str, Any]]:
"""Reconcile the plan's runtimes against what the restart phase DID.
@@ -402,7 +402,9 @@ def match_runtime_outcomes(
and still lists its pid: the restart phase is forbidden to restart it out from under the app (it
hosts the live Desktop chats), so it is handed back to its supervisor and surfaced. Without a
probe result it remains ``unaccounted``, rather than claiming the app owns an unknown
- incarnation. The probe itself fails closed (unreadable ledger -> every planned serve is listed as
+ incarnation. ``failed_respawn_pids`` (serves the dashboard cleanup stopped and could not bring
+ back) read ``failed`` before the probe, whose "gone" is exactly what a failed respawn looks like
+ (#109290). The probe itself fails closed (unreadable ledger -> every planned serve is listed as
surviving), so ``deferred`` means "not shown to be gone", not "observed alive". See #111494.
See #91277.
@@ -416,13 +418,14 @@ def match_runtime_outcomes(
relaunched = set(relaunched_profiles or []) | set(externally_supervised_profiles or [])
killed = {int(p) for p in (killed_pids or set())}
stale_serves = {int(p) for p in stale_serve_pids} if stale_serve_pids is not None else None
+ failed_respawns = {int(p) for p in (failed_respawn_pids or set())}
def _outcome(r: RuntimeRecord) -> str:
killed_here = r.pid is not None and r.pid in killed
if r.kind in _SERVE_KINDS:
if killed_here:
return "stopped"
- if any(_serve_unit_matches_profile(r.profile, u) for u in failed_set):
+ if r.pid in failed_respawns or any(_serve_unit_matches_profile(r.profile, u) for u in failed_set):
return "failed"
if stale_serves is not None and r.pid not in stale_serves:
# Incarnation-verified: the pre-update process is gone (replaced by its unit / the
diff --git a/tests/hermes_cli/test_restart_plan_reconciliation.py b/tests/hermes_cli/test_restart_plan_reconciliation.py
index c47b613e937..017a47e4bae 100644
--- a/tests/hermes_cli/test_restart_plan_reconciliation.py
+++ b/tests/hermes_cli/test_restart_plan_reconciliation.py
@@ -296,6 +296,19 @@ def test_serve_reconciles_against_its_own_unit_vocabulary():
assert outcomes[0]["outcome"] == "unaccounted"
+def test_failed_respawn_outranks_incarnation_probe():
+ """A dashboard the cleanup stopped and could not bring back is ``failed``: the probe sees its
+ pre-update pid gone, which is exactly what a failed respawn looks like. See #109290."""
+ plan = _plan(_serve("default", 900), _serve("default", 901, kind="dashboard"))
+ outcomes = match_runtime_outcomes(
+ plan, restarted_services=[], relaunched_profiles=[],
+ externally_supervised_profiles=[], killed_pids=set(), failed_units=[],
+ stale_serve_pids=set(), failed_respawn_pids={901},
+ )
+ by_pid = {o["pid"]: o["outcome"] for o in outcomes}
+ assert by_pid == {900: "restarted", 901: "failed"}
+
+
def test_serve_outcome_follows_incarnation_probe_when_provided():
"""With the (pid, create_time) survivor probe result, liveness decides:
a pre-update serve that is gone was replaced (restarted); one still