Skip to content

The agent that grows with you

fix(update): a Desktop build that never ran is named for the hand-off

Tekniumfdbd0dfff910
diff --git a/hermes_cli/update_completion.py b/hermes_cli/update_completion.py
index e64b8b6bd1c..135caec8827 100644
--- a/hermes_cli/update_completion.py
+++ b/hermes_cli/update_completion.py
@@ -198,6 +198,26 @@ def _publish_gateway_success(request: dict) -> None:
print(f" ⚠ Could not publish the gateway's update status: {exc}")
+#: The one whole line the Desktop hand-off scripts match (scripts/desktop-update/posix.sh and
+#: windows.ps1); ``source_build.build_update_products`` prints the same prefix when the build fails.
+DESKTOP_BUILD_OWED = "Desktop app build owed:"
+
+
+def _report_desktop_build_owed(request: dict, record: dict | None, reason: str) -> None:
+ """Name the owed Desktop build when this run never got the build to its own verdict (F6, review P4).
+
+ The builder prints the line only when the build itself fails; a run that never reached it
+ (dependencies owed, the tail refused by the lock, a completion process lost) would otherwise end
+ as a plain "Update complete." in the hand-off. A ``build`` stage on the run's record means the
+ build ran and printed this line itself when the Desktop app failed.
+ """
+ if not request.get("desktop"):
+ return
+ if any(isinstance(mark, dict) and mark.get("name") == "build" for mark in (record or {}).get("stages") or ()):
+ return
+ print(f" {DESKTOP_BUILD_OWED} {reason}", flush=True)
+
+
def _settle_after_commit(request: dict, result_path: Path, step: str, reason: str) -> int:
"""The tree already moved, so a failure here is owed work, never a failed update (C3, A6).
@@ -216,7 +236,9 @@ def _settle_after_commit(request: dict, result_path: Path, step: str, reason: st
receipt = _read_terminal_receipt(request) # a prepared child that finalized, then died
if receipt is None:
# A prepared child that died mid-tail persisted stages the parent's snapshot lacks.
- _resume_receipt(_running_record(request) or request["receipt"])
+ record = _running_record(request) or request["receipt"]
+ _report_desktop_build_owed(request, record, f"{step} did not finish")
+ _resume_receipt(record)
update_receipt.record_stage("deps" if step == "dependencies" else "build", "failed")
update_receipt.record_followup(step, reason, retry="dependencies not installed yet — the next launch retries"
if step == "dependencies" else "the next launch or `hermes update` retries it")
@@ -311,6 +333,8 @@ def _complete_selected(request: dict) -> bool:
followups=followups)
except (Exception, SystemExit) as exc: # health: allow BLE001 -- e.g. the shared update lock refused the tail
reason = str(exc) or type(exc).__name__
+ # The tail's steps catch their own failures, so a raise here means the build never ran.
+ _report_desktop_build_owed(request, None, "the source-update tail did not run")
record_followup("completion", reason)
followups.append(("completion", reason))
tail_owed = any(step in TAIL_FOLLOWUPS for step, _ in followups)
@@ -361,6 +385,15 @@ class _ForwardedOutput:
return getattr(self.stream, name)
+def _report_unbuilt_desktop(request: dict) -> None:
+ """The tail raised out of ``_complete_selected``: before the build stage, the build never ran."""
+ from hermes_cli import update_receipt
+
+ current = update_receipt._current.get()
+ if current is not None: # a finalized run got past the build (verification finalizes it)
+ _report_desktop_build_owed(request, current.data, "the source-update tail did not finish")
+
+
def _finish(request: dict, result_path: Path) -> int:
from hermes_cli import update_receipt
from pm.receipt import accept_worker_receipt
@@ -379,8 +412,10 @@ def _finish(request: dict, result_path: Path) -> int:
update_receipt.finalize_interrupted_update_receipt(reason, exit_code=code)
except SystemExit as exc:
if exc.code not in (0, None):
+ _report_unbuilt_desktop(request)
update_receipt.record_followup("completion", f"completion exited {exc.code}")
except BaseException as exc: # noqa: BLE001 — after the commit point nothing fails the update
+ _report_unbuilt_desktop(request)
update_receipt.record_followup("completion", f"{type(exc).__name__}: {exc}")
finally:
if code and request["gateway_mode"]:
diff --git a/tests/hermes_cli/test_update_completion_process.py b/tests/hermes_cli/test_update_completion_process.py
index 8f8ed40c176..2dc5d811e29 100644
--- a/tests/hermes_cli/test_update_completion_process.py
+++ b/tests/hermes_cli/test_update_completion_process.py
@@ -280,6 +280,37 @@ def test_missing_child_result_fails_boundary_receipt_and_releases_lock(transitio
lock.release()
[email protected]("never_built", ["dependencies", "refused", "died"])
[email protected]("desktop", [True, False])
+def test_desktop_build_that_never_ran_is_named_for_the_handoff(transition, capsys, never_built, desktop):
+ """Review P4 (F6): the hand-off scripts read ``Desktop app build owed:`` to tell the user the app is
+ stale. The builder prints it only when the build fails; a run whose build never ran (dependency
+ sync failed, the tail refused by the update lock, the prepared child died) must print it too."""
+ scripts = Path(update_completion.__file__).parents[1] / "scripts/desktop-update"
+ for script in ("posix.sh", "windows.ps1"): # the exact prefix the hand-off scripts match
+ assert "Desktop app build owed: " in (scripts / script).read_text(encoding="utf-8")
+ assert update_completion.DESKTOP_BUILD_OWED == "Desktop app build owed:"
+ root, git, old, new, request = transition
+ request["desktop"] = desktop
+ shutil.copy2(update_completion.__file__, root / "hermes_cli/update_completion.py")
+ if never_built == "dependencies":
+ (root / "pm/__init__.py").write_text("def sync_venv(**kw): raise RuntimeError('dependency refused')\n")
+ elif never_built == "refused":
+ (root / "hermes_cli/source_completion.py").write_text(
+ "def complete_source_checkout(*args, **kwargs):\n"
+ " raise RuntimeError('an update is still running (pid 1); wait for it to exit')\n")
+ else:
+ (root / "hermes_cli/source_completion.py").write_text(
+ "import os, signal\n"
+ "def complete_source_checkout(*args, **kwargs): os.kill(os.getpid(), signal.SIGKILL)\n")
+ result = update_completion.run_completion(request)
+ out = capsys.readouterr().out
+ assert result["exit_code"] == 0, out
+ owed = [line.strip() for line in out.splitlines() if line.strip().startswith("Desktop app build owed: ")]
+ assert len(owed) == (1 if desktop else 0), out
+
+
def test_unwritable_gateway_status_never_fails_a_settled_commit(tmp_path, monkeypatch):
"""Review P1: the bootstrap's gateway status write is best effort, like
``_write_gateway_update_exit_code``; the committed run still answers its result with exit 0."""