Skip to content

The agent that grows with you

fix(update): each update stage names itself where it starts, so a failed build still shows the restart

Teknium4b90de5022fe
diff --git a/hermes_cli/source_build.py b/hermes_cli/source_build.py
index 5731cf8990a..7a725dd9bce 100644
--- a/hermes_cli/source_build.py
+++ b/hermes_cli/source_build.py
@@ -159,6 +159,7 @@ def build_update_products(project_root: Path, *, desktop: bool) -> None:
from hermes_cli.update_stage import publish_stage
failures: list[tuple[str, BaseException]] = []
+ publish_stage("Building the apps")
def attempt(name: str, step) -> bool:
try:
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 95ecd69211b..764bd4d69b8 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -788,6 +788,8 @@ def _complete_source_update(request: dict | None) -> None:
from copy import deepcopy
_completion_receipt.record_stage(
"apply", "skipped" if request.get("completion_message") else "success", mode=request.get("apply_mode", "git"))
+ from hermes_cli.update_stage import publish_stage
+ publish_stage("Updating dependencies") # the completion below starts with the dependency sync
current = _completion_receipt._current.get()
if current is not None:
request["receipt"] = deepcopy(current.data)
@@ -1840,6 +1842,8 @@ def _cmd_update_impl(args, gateway_mode: bool):
pre_update_snapshot_id = _m()._run_pre_update_backup(args)
_record_pre_update_backup_outcome(args, pre_update_snapshot_id)
_record_snapshot_stage(args, pre_update_snapshot_id)
+ from hermes_cli.update_stage import publish_stage
+ publish_stage("Downloading updates") # a failed backup never stops the update
_windows_gateway_resume = _pause_gateways_for_update(opts)
if _windows_gateway_resume:
diff --git a/hermes_cli/update_cmd_fleet.py b/hermes_cli/update_cmd_fleet.py
index 2019b5b00e2..3c7ced0de8d 100644
--- a/hermes_cli/update_cmd_fleet.py
+++ b/hermes_cli/update_cmd_fleet.py
@@ -1692,6 +1692,9 @@ def _restart_gateway_fleet_after_update(_pre_update_plan, gateway_mode: bool):
every planned gateway is verifiably covered.
"""
from hermes_cli.update_cmd import _m
+ from hermes_cli.update_stage import publish_stage
+
+ publish_stage("Restarting Hermes services") # also after a failed build: the code is committed
# All bookkeeping is declared before the try so abort recovery and fleet reconciliation
# can read it even if the phase raises early. ``pre_restart_gateway_pids`` stays empty
# until we are about to stop/drain, so an early exception has nothing to fail closed on,
diff --git a/hermes_cli/update_receipt.py b/hermes_cli/update_receipt.py
index c80a374f54d..97748b90366 100644
--- a/hermes_cli/update_receipt.py
+++ b/hermes_cli/update_receipt.py
@@ -501,26 +501,11 @@ def record_skip(name: str, reason: str) -> None:
_record("skip", f"update skip {name}", name, reason)
-# The stage a pipeline mark hands over to, as the Desktop hand-off window names it. Without these
-# the window read "Updating code and dependencies" for a whole 20-60 min run (#139952, #135363).
-_NEXT_STAGE_LABEL = {
- "snapshot": "Downloading updates",
- "apply": "Updating dependencies",
- "deps": "Building the apps",
- "build": "Restarting Hermes services",
-}
-
-
def record_stage(name: str, outcome: str, **facts: str) -> None:
"""Mark the END of a pipeline stage (``success``/``failed``/``skipped``) with a timestamp."""
_record("stage", f"update stage {name}", name, outcome, **facts)
# Each stage boundary refreshes the durable running record (a kill names its last stage).
persist_running_receipt()
- # A failed backup does not stop the update; any other failed stage ends it.
- if name in _NEXT_STAGE_LABEL and (outcome != "failed" or name == "snapshot"):
- from hermes_cli.update_stage import publish_stage
-
- publish_stage(_NEXT_STAGE_LABEL[name])
def record_fact(key: str, value: Any) -> None:
diff --git a/tests/hermes_cli/test_update_stage_relay.py b/tests/hermes_cli/test_update_stage_relay.py
index 7b04a57e88a..0e80525111b 100644
--- a/tests/hermes_cli/test_update_stage_relay.py
+++ b/tests/hermes_cli/test_update_stage_relay.py
@@ -1,11 +1,21 @@
-"""Each update pipeline stage mark names the next stage to a watching Desktop hand-off window."""
+"""The Desktop hand-off window names the update stage that is actually running."""
from __future__ import annotations
import json
+import pytest
-def test_stage_marks_publish_the_next_stage_to_the_handoff_window(tmp_path, monkeypatch):
- from hermes_cli import update_receipt
+
+class _StopBeforeAnyGateway(BaseException):
+ """Escapes the restart phase's recovery (it catches Exception) before any gateway is probed."""
+
+
+def test_restart_after_a_failed_build_names_the_restart(tmp_path, monkeypatch):
+ """A failed build does not end the update (the code is committed): the fleet restart still
+ runs, and the window must say so instead of the build message it last showed."""
+ from hermes_cli import update_cmd, update_cmd_fleet
+ from hermes_cli.update_finish import finish_update
+ from hermes_cli.update_stage import publish_stage
status = tmp_path / "hermes-update-status.1"
monkeypatch.setenv("HERMES_UPDATE_STATUS_FILE", str(status))
@@ -13,9 +23,24 @@ def test_stage_marks_publish_the_next_stage_to_the_handoff_window(tmp_path, monk
def shown() -> str:
return json.loads(status.read_text(encoding="utf-8"))["message"] if status.exists() else ""
- update_receipt.record_stage("snapshot", "failed") # a failed backup does not stop the update
- assert shown() == "Downloading updates"
- update_receipt.record_stage("apply", "success")
- assert shown() == "Updating dependencies"
- update_receipt.record_stage("deps", "failed") # the update ends here: nothing new to announce
- assert shown() == "Updating dependencies"
+ def failed_build(*, followups, **_kwargs):
+ publish_stage("Building the desktop app")
+ followups.append(("build", "desktop app build failed"))
+ return True
+
+ during_restart = []
+
+ def restart_phase_starts():
+ during_restart.append(shown())
+ raise _StopBeforeAnyGateway
+
+ monkeypatch.setattr(update_cmd, "_run_post_update_maintenance", failed_build)
+ # The real restart phase runs up to its first step; nothing past it touches a gateway.
+ monkeypatch.setattr(update_cmd_fleet, "_gateway_drain_budget", restart_phase_starts)
+
+ with pytest.raises(_StopBeforeAnyGateway):
+ finish_update(root=tmp_path, assume_yes=True, gateway_mode=False, pre_update_snapshot_id=None,
+ had_desktop_app_before_update=False, pre_update_version=None, plan=None,
+ windows_resume=None)
+
+ assert during_restart == ["Restarting Hermes services"]
diff --git a/tests/scripts/desktop_update/test_desktop_update_windows_child_stage.py b/tests/scripts/desktop_update/test_desktop_update_windows_child_stage.py
index 2e5253bb3ab..c4489c72e5a 100644
--- a/tests/scripts/desktop_update/test_desktop_update_windows_child_stage.py
+++ b/tests/scripts/desktop_update/test_desktop_update_windows_child_stage.py
@@ -10,17 +10,17 @@ from __future__ import annotations
import os
from pathlib import Path
import subprocess
-import time
import pytest
from tests.installation_launcher_fixture import publish_fixture_launcher
from tests.scripts.desktop_update.windows_handoff_support import _log
+from tests.waiting import wait_until
ROOT = Path(__file__).resolve().parent.parent.parent.parent
SCRIPT = ROOT / "scripts/desktop-update/windows.ps1"
STAGE_CLI = """
-import os, sys, time
+import os, sys
from pathlib import Path
def main():
if '--version' in sys.argv:
@@ -33,11 +33,9 @@ def main():
for name in [m for m in sys.modules if m == 'hermes_cli' or m.startswith('hermes_cli.')]:
del sys.modules[name]
from hermes_cli.update_stage import publish_stage
+ from tests.waiting import wait_until
publish_stage('Packaging the desktop app')
- hold = Path(os.environ['HANDOFF_HOLD'])
- deadline = time.monotonic() + 60
- while not hold.exists() and time.monotonic() < deadline:
- time.sleep(0.05)
+ wait_until(Path(os.environ['HANDOFF_HOLD']).exists, timeout=60, what='the test to release the update')
return 0
if __name__ == '__main__':
sys.exit(main())
@@ -59,11 +57,10 @@ def test_handoff_shows_the_stage_the_update_publishes(tmp_path: Path) -> None:
"HANDOFF_HOLD": str(hold), "HANDOFF_REPO": str(ROOT)},
)
try:
- deadline = time.monotonic() + 90
- while "stage: Packaging the desktop app" not in _log(home):
- assert time.monotonic() < deadline and script.poll() is None, (
- "the hand-off never relayed the update's own stage:\n" + _log(home)[-3000:])
- time.sleep(0.2)
+ wait_until(lambda: "stage: Packaging the desktop app" in _log(home) or script.poll() is not None,
+ timeout=90, what="the hand-off to relay the update's stage")
+ assert "stage: Packaging the desktop app" in _log(home), (
+ "the hand-off never relayed the update's own stage:\n" + _log(home)[-3000:])
finally:
hold.write_text("", encoding="utf-8")
try: