Skip to content

The agent that grows with you

fix(update): Desktop-owned serve no longer fails the update or holds fleet_restart_pending

teknium17c6b8c7a8df4
diff --git a/hermes_cli/update_abort_recovery.py b/hermes_cli/update_abort_recovery.py
index 186053f259f..8dd22d5c722 100644
--- a/hermes_cli/update_abort_recovery.py
+++ b/hermes_cli/update_abort_recovery.py
@@ -233,6 +233,14 @@ def _warn_stale_serve_runtimes(rows) -> None:
" or by relaunching `hermes serve` / the Desktop app.")
+def _owed_stale_serve_rows(rows) -> list[dict]:
+ """Survivors the updater itself owes a restart for. A Desktop-supervised serve is excluded: the
+ recovery pass is forbidden to restart it (it hosts the live Desktop chats), so counting it keeps
+ ``fleet_restart_pending`` armed forever with nothing that could ever discharge it. It is still
+ named by :func:`_warn_stale_serve_runtimes` and recorded in the receipt. See #111494."""
+ return [row for row in (rows or []) if row.get("supervisor") != "desktop"]
+
+
def _abort_recovery_is_complete(
*, planned_gateway_profiles, covered_gateway_profiles, recovery_result, stale_runtime_rows
) -> bool:
@@ -246,4 +254,4 @@ def _abort_recovery_is_complete(
and set(planned_gateway_profiles) <= set(covered_gateway_profiles)
and not (result.get("failed") or result.get("relaunch_attempted"))
and not (result.get("serve_units") or {}).get("failed")
- and not stale_runtime_rows)
+ and not _owed_stale_serve_rows(stale_runtime_rows))
diff --git a/hermes_cli/update_cmd_fleet.py b/hermes_cli/update_cmd_fleet.py
index 5c3d95e8a90..be61bce4961 100644
--- a/hermes_cli/update_cmd_fleet.py
+++ b/hermes_cli/update_cmd_fleet.py
@@ -1200,6 +1200,7 @@ def _recover_after_restart_phase_abort(
e, _pre_update_plan, out: _GatewayRestartOutcome, *, gateway_mode, restarted_scoped_units
) -> None:
"""Phase-abort recovery: fresh-child restart + fail-closed verdict; updates ``out`` in place."""
+ from hermes_cli.update_abort_recovery import _owed_stale_serve_rows
from hermes_cli.update_cmd import (
_abort_recovery_is_complete, _recover_gateway_restart_after_abort, _surviving_pre_update_serve_runtimes,
_warn_stale_serve_runtimes, _write_gateway_update_exit_code,
@@ -1253,11 +1254,13 @@ def _recover_after_restart_phase_abort(
stale_runtime_rows=_stale_runtime_rows,
):
# Fresh child is terminal; the fleet-version matrix stays the authoritative
- # read-back before success is declared.
+ # read-back before success is declared. Desktop-owned survivors (the only rows
+ # that can remain here) are named, not owed. See #111494.
out.incomplete = False
+ _warn_stale_serve_runtimes(_stale_runtime_rows)
elif (
_restart_phase_failure_is_incomplete(_surviving, out.pre_restart_gateway_pids)
- or _stale_runtime_rows
+ or _owed_stale_serve_rows(_stale_runtime_rows)
or _serve_units_failed
):
out.incomplete = True
diff --git a/hermes_cli/update_inventory.py b/hermes_cli/update_inventory.py
index 757e570e4bd..17270cf2541 100644
--- a/hermes_cli/update_inventory.py
+++ b/hermes_cli/update_inventory.py
@@ -8,6 +8,7 @@ side-effect-free probe, so ``hermes update --plan`` is safe on a live fleet.
from __future__ import annotations
import logging
+import sys
from contextlib import contextmanager, suppress
from dataclasses import dataclass, field, asdict
from typing import Any, Callable, Optional
@@ -318,11 +319,15 @@ def match_runtime_outcomes(
The platform restart branches each re-discover their own targets, so a runtime the plan saw can
be missed with no signal. Returns one ``{kind, profile, pid, mechanism, outcome}`` row per
- planned runtime; outcome is ``restarted``, ``stopped``, ``failed`` or ``unaccounted`` (no
- bookkeeping mentions it — the blind-spot tripwire). Never raises. Serve/dashboard runtimes are
- reconciled in their OWN vocabulary and never borrow the gateway's outcome: with
- ``stale_serve_pids`` a pre-update serve whose incarnation is gone counts as ``restarted``, one
- still alive is ``unaccounted``; without the probe an untouched serve stays ``unaccounted``.
+ planned runtime; outcome is ``restarted``, ``stopped``, ``failed``, ``deferred`` or
+ ``unaccounted`` (no bookkeeping mentions it — the blind-spot tripwire). Never raises.
+ Serve/dashboard runtimes are reconciled in their OWN vocabulary and never borrow the gateway's
+ outcome: with ``stale_serve_pids`` a pre-update serve whose incarnation is gone counts as
+ ``restarted``, one still alive is ``unaccounted``; without the probe an untouched serve stays
+ ``unaccounted``. A Desktop-supervised serve still alive is ``deferred`` instead: 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 — never counted as a missed restart the updater could
+ have discharged. See #111494.
See #91277.
They never borrow the gateway's outcome: ``relaunched_profiles`` and ``hermes-gateway*`` name a
@@ -343,10 +348,16 @@ def match_runtime_outcomes(
return "stopped"
if any(_serve_unit_matches_profile(r.profile, u) for u in failed_set):
return "failed"
- if stale_serves is not None:
+ 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
- # dashboard cleanup respawn / the Desktop app) or it is still alive on pre-update code.
- return "unaccounted" if r.pid in stale_serves else "restarted"
+ # dashboard cleanup respawn / the Desktop app).
+ return "restarted"
+ if r.supervisor == "desktop":
+ # Still alive on pre-update code, but the Desktop app owns it and the restart phase
+ # must not kill it (_DESKTOP_SERVE_SKIP_REASON); only the app can pick up the new code.
+ return "deferred"
+ if stale_serves is not None:
+ return "unaccounted"
return "restarted" if any(_serve_unit_matches_profile(r.profile, s) for s in restarted_set) else "unaccounted"
if r.profile in relaunched:
return "restarted"
@@ -373,6 +384,14 @@ def report_unaccounted_runtimes(outcomes: list[dict[str, Any]]) -> bool:
STALE/DOWN fleet row (exit 1) — a promised restart silently missed is the class this phase
exists to kill.
"""
+ deferred = [o for o in outcomes if o.get("outcome") == "deferred"]
+ if deferred:
+ # Surfaced but not escalated: the updater has no authority over these, so holding
+ # ``fleet_restart_pending`` for them would never be discharged. See #111494.
+ print()
+ print(" ℹ Left to the Desktop app (still on pre-update code until it is relaunched):")
+ for o in deferred:
+ print(f" • {o['kind']} [{o['profile']}] pid {o['pid']} — relaunch the Desktop app to pick up the update")
missed = [o for o in outcomes if o.get("outcome") == "unaccounted"]
if not missed:
return False
@@ -387,8 +406,9 @@ def report_unaccounted_runtimes(outcomes: list[dict[str, Any]]) -> bool:
if any(o.get("kind") in _SERVE_KINDS for o in missed):
# A serve/dashboard is not reachable by any `gateway restart` command: name the process, not the wrong verb.
# See #100479.
- print(" systemctl --user restart hermes-serve.service # unit-managed serve")
- print(" relaunch `hermes serve` / `hermes dashboard` / the Desktop app")
+ if sys.platform == "linux":
+ print(" systemctl --user restart hermes-serve.service # unit-managed serve")
+ print(" relaunch `hermes serve` / `hermes dashboard`")
return True
diff --git a/tests/hermes_cli/test_update_fleet_restart_pending.py b/tests/hermes_cli/test_update_fleet_restart_pending.py
index e756b4edcf8..c73cc170e25 100644
--- a/tests/hermes_cli/test_update_fleet_restart_pending.py
+++ b/tests/hermes_cli/test_update_fleet_restart_pending.py
@@ -484,6 +484,71 @@ def test_clean_update_escalates_surviving_serve_as_unaccounted(
assert by_pid == {4444: "restarted", 5555: "unaccounted"}
+def test_clean_update_defers_desktop_owned_serve_and_clears_marker(
+ monkeypatch, tmp_path, capsys
+):
+ """#111494 end to end: the only survivor is the Desktop app's own ``serve``
+ backend. The restart phase is forbidden to restart it, so reconciliation must
+ not count it as a missed restart either — otherwise every update with the
+ Desktop open ends ``partial``/exit 1 and re-arms ``fleet_restart_pending``
+ with nothing that could ever discharge it. It is surfaced (``deferred``,
+ relaunch hint) rather than dropped."""
+ from hermes_cli.update_inventory import (
+ RuntimeRecord, UpdatePlan, _restart_mechanism,
+ )
+ import hermes_cli.update_inventory as ui
+ import hermes_cli.process_identity as pi
+
+ args = _update_args()
+ _patch_update_deps(monkeypatch, tmp_path, _make_head_moved_side_effect())
+
+ plan = UpdatePlan()
+ plan.runtimes = [
+ RuntimeRecord(kind="gateway", profile="default", pid=4444,
+ supervisor="systemd",
+ restart_via=_restart_mechanism("systemd", "default")),
+ RuntimeRecord(kind="serve", profile="default", pid=6161,
+ supervisor="desktop",
+ restart_via=_restart_mechanism("desktop", "default"),
+ detail={"create_time": 1000.0}),
+ ]
+ monkeypatch.setattr(ui, "collect_runtime_inventory", lambda: plan)
+ real_match = ui.match_runtime_outcomes
+
+ def _match(p, **kw):
+ kw["restarted_services"] = list(kw.get("restarted_services") or []) + [
+ "hermes-gateway.service"
+ ]
+ return real_match(p, **kw)
+
+ monkeypatch.setattr(ui, "match_runtime_outcomes", _match)
+ # The gateway leg is healthy on the new code; only the Desktop serve is left.
+ monkeypatch.setattr(
+ "hermes_cli.update_receipt.collect_fleet_versions",
+ lambda **_k: [{"profile": "default", "pid": 4444, "code_sha": "def456",
+ "code_version": "0.21.0", "state": "current"}],
+ )
+ # Same incarnation still alive: the Desktop serve genuinely survived on pre-update code.
+ monkeypatch.setattr(
+ pi, "ledger_entries",
+ lambda **_k: [{"pid": 6161, "purpose": "serve", "create_time": 1000.0}],
+ )
+
+ hermes_main.cmd_update(args) # no SystemExit(1)
+
+ out = capsys.readouterr().out
+ assert "pid 6161" in out and "pre-update code" in out
+ assert "relaunch the Desktop app" in out
+ assert "Planned runtimes the restart phase never touched" not in out
+ assert not update_cmd._fleet_restart_pending_marker_path().exists()
+
+ latest = get_hermes_home() / "logs" / "update_receipts" / "latest.json"
+ receipt = json.loads(latest.read_text(encoding="utf-8"))
+ assert receipt["outcome"] == "success"
+ by_pid = {o["pid"]: o["outcome"] for o in receipt["runtime_outcomes"]}
+ assert by_pid == {4444: "restarted", 6161: "deferred"}
+
+
def test_interrupt_between_pull_and_restart_leaves_marker(
monkeypatch, tmp_path
):
diff --git a/tests/hermes_cli/test_update_serve_generation_recovery.py b/tests/hermes_cli/test_update_serve_generation_recovery.py
index 36c6884bbda..4c277afce5d 100644
--- a/tests/hermes_cli/test_update_serve_generation_recovery.py
+++ b/tests/hermes_cli/test_update_serve_generation_recovery.py
@@ -78,6 +78,21 @@ def _gateway_only_success():
}
+def test_desktop_owned_serve_survivor_does_not_hold_the_flag():
+ """#111494: the recovery pass may not restart a Desktop-supervised serve, so it
+ cannot be the reason recovery stays incomplete; an operator-owned survivor
+ alongside it still blocks."""
+ desktop = {"pid": 6161, "kind": "serve", "profile": "default", "supervisor": "desktop"}
+ manual = {"pid": 4242, "kind": "serve", "profile": "default", "supervisor": "manual-serve"}
+ kwargs = dict(
+ planned_gateway_profiles={"default"},
+ covered_gateway_profiles={"default"},
+ recovery_result=_gateway_only_success(),
+ )
+ assert update_cmd._abort_recovery_is_complete(stale_runtime_rows=[desktop], **kwargs) is True
+ assert update_cmd._abort_recovery_is_complete(stale_runtime_rows=[desktop, manual], **kwargs) is False
+
+
def test_full_gateway_recovery_does_not_clear_the_flag_while_serve_is_stale():
"""The reported bug as a predicate: gateway green, serve still generation N."""
assert (