Skip to content

The agent that grows with you

refactor(desktop-update): keep only the reachable 124-after-completion remap

teknium191e8f7595d26
diff --git a/scripts/desktop-update/posix.sh b/scripts/desktop-update/posix.sh
index 6804be6c311..b1c86d26ed7 100755
--- a/scripts/desktop-update/posix.sh
+++ b/scripts/desktop-update/posix.sh
@@ -848,20 +848,6 @@ OUT="$("${UPDATE_INVOKE[@]}" update --yes $GATEWAY_FLAG $KEEP_STASH "${TARGET_AR
printf '%s\n' "$OUT" >> "$LOG" 2>/dev/null
log "hermes update exit code: $CODE"
-# A completed update killed by the idle watchdog is terminal (#96205): exit
-# 124 with "✓ Update complete!" already printed means the install state is
-# done and only the silent post-update finalization overran the ceiling.
-# Re-running the update would re-apply the whole install (the retry storm
-# that parks the updater UI for 70+ minutes), and failing would relaunch the
-# old build. Surface success instead. Deliberately NARROW: a plain exit 1
-# after the marker is the stale-gateway verdict (hermes_cli/update_receipt.py
-# prints "✗ Update not complete" after the completion banner and must
-# supersede it), so only the timeout sentinel is remapped.
-if [ "$CODE" -eq 124 ] && printf '%s' "$OUT" | grep -q "Update complete!"; then
- log "update completed before the watchdog killed the finalizing step (exit $CODE); treating as success, not retrying (#96205)"
- CODE=0
-fi
-
if [ "$LEGACY_INSTALL" -eq 1 ] && [ "$CODE" -ne 0 ] && [ "$CODE" -ne 2 ]; then
# Retry once: update-boundary class (fresh code on disk, stale in memory).
# Exit 2 ("close all Hermes windows") is not retryable.
diff --git a/scripts/desktop-update/windows.ps1 b/scripts/desktop-update/windows.ps1
index 82114e1d6c6..771a3b4038d 100644
--- a/scripts/desktop-update/windows.ps1
+++ b/scripts/desktop-update/windows.ps1
@@ -54,7 +54,6 @@ param(
[switch]$SelfTestUi,
[switch]$SelfTestPipeDrain,
[switch]$SelfTestMarker,
- [switch]$SelfTestRetryState,
[switch]$SelfTestWorkingDirectory
)
@@ -63,7 +62,7 @@ if ($PSBoundParameters.ContainsKey("Branch") -and $PSBoundParameters.ContainsKey
}
$targetArgs = if ($Channel) { @("--channel", $Channel.ToLowerInvariant()) } else { @("--branch", $Branch) }
-if (-not $SelfTestUi -and -not $SelfTestPipeDrain -and -not $SelfTestRetryState -and -not $InstallRoot) {
+if (-not $SelfTestUi -and -not $SelfTestPipeDrain -and -not $InstallRoot) {
# Mandatory in spirit; relaxed in the signature only so the self-test
# switches can drive the UI / the pipe drain without a checkout.
throw "-InstallRoot is required"
@@ -1250,36 +1249,18 @@ function Invoke-HermesStep([string]$Exe, [string[]]$HermesArgs, [string]$Tag) {
return @{ Code = $code; Output = $all; TreeQuiesced = (-not $stalled -or $proc.HasExited); StartedAfterJobAssignment = $true }
}
-# ── Update retry state machine (#96205) ────────────────────────────────────
-# `hermes update` can COMPLETE (its output shows "✓ Update complete!") and
-# still be killed with the timeout sentinel 124: the post-update finalization
-# (gateway-restart hand-off) can stay alive and silent past the idle ceiling,
-# so Invoke-HermesStep terminates the tree and reports 124. The old gates
-# retried on any non-zero, non-2 exit, re-running a completed update from
-# scratch -- the #96205 retry storm that parked the Desktop updater popup
-# for 70+ minutes.
-#
-# The rule is deliberately NARROW: only exit 124 + the completion marker is
-# terminal. A plain exit 1 after the marker is the stale-gateway verdict
-# (hermes_cli/update_receipt.py prints "✗ Update not complete" AFTER the
-# completion banner and must supersede it), so it keeps propagating as a
-# failure. Exit 2 ("close all Hermes windows") is fail-closed, not retryable.
-function Get-HermesUpdateRetryState([int]$Code, [string]$Output) {
- if ($Code -eq 0) { return 'success' }
- if ($Code -eq 124 -and $Output -match 'Update complete!') { return 'completed' }
- if ($Code -eq 2) { return 'fail-closed' }
- return 'retryable'
-}
-
-# Apply the terminal-state rule to a finished update step: a completed update
-# that the idle watchdog killed is surfaced as success (Code = 0, output
-# preserved so the truthful-completion check below still sees a
-# "Desktop build failed" warning if one was printed), letting the hand-off
-# verify and relaunch the NEW build instead of re-running the update.
+# `hermes update` can COMPLETE (its output carries "✓ Update complete!") and
+# still be killed with the idle-watchdog sentinel 124: the post-update phase
+# (gateway restart hand-off) stayed alive and silent past the ceiling, so
+# Invoke-HermesStep terminated the tree (#96205). The install is done; failing
+# would keep the old Desktop and a legacy install would re-run the whole update.
+# Surface success so the hand-off verifies, restores the gateways and relaunches.
+# Only 124 is remapped, and never after "✗ Update not complete": that verdict
+# (hermes_cli/update_receipt.py) is printed after the banner and supersedes it.
function Resolve-HermesUpdateOutcome($StepResult) {
- if ((Get-HermesUpdateRetryState -Code $StepResult.Code -Output $StepResult.Output) -eq 'completed') {
- Write-HandoffLog "update completed but the finalizing step was killed by the idle watchdog (exit $($StepResult.Code)); treating as success, not retrying (#96205)"
- return @{ Code = 0; Output = $StepResult.Output; TreeQuiesced = $StepResult.TreeQuiesced; StartedAfterJobAssignment = $StepResult.StartedAfterJobAssignment }
+ if ($StepResult.Code -eq 124 -and $StepResult.Output -match 'Update complete!' -and $StepResult.Output -notmatch 'Update not complete') {
+ Write-HandoffLog "update completed before the idle watchdog killed its finalizing step (exit 124); treating it as success, not retrying (#96205)"
+ $StepResult.Code = 0
}
return $StepResult
}
@@ -1539,56 +1520,6 @@ exit 3
exit 0
}
-# -SelfTestRetryState: prove the retry state machine never re-runs a ------
-# completed update (#96205). Fixture states drive Get-HermesUpdateRetryState,
-# then Resolve-HermesUpdateOutcome is checked against the exact #96205 shape
-# (update completes, prints the marker, is then killed with the timeout
-# sentinel 124): it must surface as exit 0. The stale-gateway verdict shape
-# (exit 1 after the marker) must NOT be flattened into success. Exits before
-# any marker/desktop machinery, same as the other self-test arms.
-if ($SelfTestRetryState) {
- New-Item -ItemType Directory -Path $LogDir -Force -ErrorAction SilentlyContinue | Out-Null
- $problems = @()
- $fixtures = @(
- @{ Name = 'clean success'; Code = 0; Output = 'Update complete! (v0.20.5)'; Expected = 'success' }
- @{ Name = 'fail-closed exit 2'; Code = 2; Output = 'close all Hermes windows'; Expected = 'fail-closed' }
- @{ Name = 'completed then timeout'; Code = 124; Output = 'Update complete! (v0.20.5) [main @ 2903a3fd]'; Expected = 'completed' }
- @{ Name = 'timeout mid-update'; Code = 124; Output = 'Cloning into C:\hermes...'; Expected = 'retryable' }
- @{ Name = 'ordinary failure'; Code = 1; Output = 'Traceback (most recent call last)'; Expected = 'retryable' }
- @{ Name = 'stale-gateway verdict'; Code = 1; Output = 'Update complete! then gateways still stale'; Expected = 'retryable' }
- @{ Name = 'empty output timeout'; Code = 124; Output = ''; Expected = 'retryable' }
- )
- foreach ($f in $fixtures) {
- $actual = Get-HermesUpdateRetryState -Code $f.Code -Output $f.Output
- if ($actual -ne $f.Expected) { $problems += "$($f.Name): state '$actual', expected '$($f.Expected)'" }
- }
-
- # The #96205 shape: completed then watchdog-killed (124) -> success.
- $res = Resolve-HermesUpdateOutcome @{ Code = 124; Output = 'Update complete! (v0.20.5) [main @ 2903a3fd]'; TreeQuiesced = $true; StartedAfterJobAssignment = $true }
- if ($res.Code -ne 0) { $problems += "completed-after-timeout surfaced as exit $($res.Code), expected 0" }
- if ($res.Output -notmatch 'Update complete!') { $problems += "completed-after-timeout lost the step output" }
- if (-not $res.TreeQuiesced) { $problems += "completed-after-timeout lost TreeQuiesced" }
-
- # A genuine mid-update timeout keeps its non-zero exit (retryable/failure).
- $res2 = Resolve-HermesUpdateOutcome @{ Code = 124; Output = 'Cloning into...'; TreeQuiesced = $true; StartedAfterJobAssignment = $true }
- if ($res2.Code -ne 124) { $problems += "mid-update timeout surfaced as exit $($res2.Code), expected 124" }
-
- # The stale-gateway verdict (exit 1 after the marker) must stay a failure.
- $res3 = Resolve-HermesUpdateOutcome @{ Code = 1; Output = 'Update complete! then gateways still stale'; TreeQuiesced = $true; StartedAfterJobAssignment = $true }
- if ($res3.Code -ne 1) { $problems += "stale-gateway verdict flattened to exit $($res3.Code), expected 1" }
-
- # Fail-closed exit 2 is not remapped either.
- $res4 = Resolve-HermesUpdateOutcome @{ Code = 2; Output = 'close all Hermes windows'; TreeQuiesced = $true; StartedAfterJobAssignment = $true }
- if ($res4.Code -ne 2) { $problems += "fail-closed exit 2 remapped to exit $($res4.Code), expected 2" }
-
- if ($problems.Count -gt 0) {
- Write-Host "RETRY-STATE SELF-TEST: FAIL -- $($problems -join '; ')"
- exit 1
- }
- Write-Host "RETRY-STATE SELF-TEST: PASS"
- exit 0
-}
-
$savedConsoleInputMode = if ($script:ConsoleInput) { [HermesHandoff.ConsoleInput]::DisableQuickEdit() } else { $null }
try {
New-Item -ItemType Directory -Path $LogDir -Force -ErrorAction SilentlyContinue | Out-Null
@@ -1723,9 +1654,6 @@ try {
Publish-UiProgress "Updating code and dependencies"
$res = Invoke-HermesStep $pythonExe $updateArgs "update"
Write-HandoffLog "hermes update exit code: $($res.Code)"
- # A completed update is terminal even when the idle watchdog kills the
- # finalizing step with 124 (#96205): never re-run, surface success so the
- # hand-off verifies and relaunches the new build.
$res = Resolve-HermesUpdateOutcome $res
# Retry only the identified pre-PM update-boundary transition. Current
diff --git a/tests/scripts/desktop_update/test_desktop_update_windows_python_handoff.py b/tests/scripts/desktop_update/test_desktop_update_windows_python_handoff.py
index 1367e881228..da25f416138 100644
--- a/tests/scripts/desktop_update/test_desktop_update_windows_python_handoff.py
+++ b/tests/scripts/desktop_update/test_desktop_update_windows_python_handoff.py
@@ -24,6 +24,11 @@ def main():
print('Desktop build failed') # no warning-driven second build on PM
if sys.argv[1:] == ['gateway', 'start', '--all']:
return int(os.environ.get('GATEWAY_EXIT', '0'))
+ if os.environ.get('HANDOFF_HANG'):
+ # Print, then park silently: the shape the hand-off's idle watchdog kills.
+ sys.stdout.reconfigure(encoding='utf-8') # as the real CLI does
+ print(os.environ['HANDOFF_HANG'].replace('|', '\\n'), flush=True)
+ import time; time.sleep(300)
return int(os.environ['HANDOFF_EXIT'])
if __name__ == '__main__':
sys.exit(main())
@@ -66,6 +71,37 @@ def test_pm_handoff_reports_update_and_gateway_results(
assert not (home / '.hermes-update-in-progress').exists()
[email protected](('output', 'code'), [
+ ('✓ Update complete! (v1.0.0)', 0),
+ ('✓ Update complete! (v1.0.0)|✗ Update not complete: 1 gateway(s) still running the old code', 124),
+ ('Cloning into the checkout...', 124),
+])
+def test_update_killed_by_idle_watchdog_after_completing_is_a_success(
+ tmp_path: Path, output: str, code: int,
+) -> None:
+ """#96205: a finished update parked silently in its restart phase is still finished."""
+ install = tmp_path / 'checkout'
+ publish_fixture_launcher(install, CLI)
+ (install / 'hermes_cli/desktop_update_verify.py').write_text('pass\n')
+ home = tmp_path / 'profile'; home.mkdir()
+ calls = tmp_path / 'calls.jsonl'
+ result = subprocess.run(
+ ['powershell', '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File',
+ str(ROOT / 'scripts/desktop-update/windows.ps1'), '-InstallRoot', str(install), '-NoUi'],
+ cwd=tmp_path, env={**os.environ, 'HERMES_HOME': str(home),
+ 'HERMES_RUNTIME_DIR': str(tmp_path / 'empty-store'),
+ 'HANDOFF_CALLS': str(calls), 'HANDOFF_EXIT': '0', 'HANDOFF_HANG': output,
+ 'HERMES_UPDATE_STEP_IDLE_SECONDS': '3', 'PYTHONIOENCODING': 'utf-8'},
+ capture_output=True, text=True, timeout=180,
+ )
+ assert result.returncode == code, result.stdout + result.stderr
+ argv = [json.loads(line)['argv'][:2] for line in calls.read_text().splitlines()]
+ assert argv == ([['update', '--yes'], ['gateway', 'start']] if code == 0 else [['update', '--yes']])
+ receipt = json.loads((home / '.hermes-update-result.json').read_text(encoding='utf-8-sig'))
+ assert receipt['ok'] == (code == 0)
+
+
@pytest.mark.platforms('windows')
def test_earlier_pm_userbin_launcher_is_identity_checked(tmp_path: Path) -> None:
home = tmp_path / 'profile'
diff --git a/tests/scripts/desktop_update/test_desktop_update_windows_retry_state.py b/tests/scripts/desktop_update/test_desktop_update_windows_retry_state.py
deleted file mode 100644
index cc9cca454a3..00000000000
--- a/tests/scripts/desktop_update/test_desktop_update_windows_retry_state.py
+++ /dev/null
@@ -1,105 +0,0 @@
-"""Regression: a completed update must never be re-run by the timeout retry.
-
-#96205: on native Windows, ``hermes update`` runs to completion (its output
-shows "✓ Update complete!") but the step process does not exit cleanly -- the
-post-update finalization (gateway-restart hand-off) stays alive and silent
-until the idle watchdog in ``Invoke-HermesStep`` terminates the tree with
-the timeout sentinel 124. The retry gates re-ran the update on any non-zero,
-non-2 exit code, so the completed update was re-applied from scratch and the
-Desktop updater popup hung for 70+ minutes. The sibling fix on the bootstrap
-installer (``apps/bootstrap-installer/src-tauri/src/update.rs``) excludes
-exit 124 from its own auto-retry, so both retry layers agree.
-
-The fix is the retry state machine in ``scripts/desktop-update/windows.ps1``
-(``Get-HermesUpdateRetryState`` + ``Resolve-HermesUpdateOutcome``): exit 124
-with the completion marker is a terminal state, surfaced as success so the
-hand-off verifies and relaunches the NEW build. The rule is deliberately
-narrow -- a plain exit 1 after the marker is the stale-gateway verdict
-(``hermes_cli/update_receipt.py`` prints "✗ Update not complete" after the
-completion banner and must supersede it), and exit 2 is fail-closed.
-
-The executable proof is the ``-SelfTestRetryState`` arm of ``windows.ps1``
-(``platforms("windows")`` below): fixture states drive the state machine and
-``Resolve-HermesUpdateOutcome`` directly, including the exact #96205 shape
-(completed then watchdog-killed), the stale-gateway verdict that must NOT be
-flattened into success, and the mid-update timeout that keeps its non-zero
-exit. ``scripts/desktop-update/posix.sh`` carries the same terminal-state gate
-for the sibling POSIX hand-off.
-"""
-
-from __future__ import annotations
-
-import os
-import subprocess
-from pathlib import Path
-
-import pytest
-
-
-REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent
-WINDOWS_PS1 = REPO_ROOT / "scripts" / "desktop-update" / "windows.ps1"
-
-
-def test_completed_update_surfaces_as_success_after_watchdog_kill(
- tmp_path: Path,
-) -> None:
- """Execute the real retry state machine against fixture step results.
-
- ``-SelfTestRetryState`` drives ``Get-HermesUpdateRetryState`` with fixture
- ``(code, output)`` pairs and ``Resolve-HermesUpdateOutcome`` with the
- shapes that matter:
-
- * *completed then timeout* -- exit 124 after "✓ Update complete!" was
- printed. Must surface as exit 0 with the step output preserved, so the
- hand-off relaunches the new build instead of re-running the update.
- * *stale-gateway verdict* -- exit 1 after the marker. Must keep its
- non-zero exit: the fleet restart phase lands exit codes after the
- completion banner on purpose.
- * *mid-update timeout* -- exit 124 without the marker. Must keep its
- non-zero exit so the ordinary retry/failure paths decide.
- * *fail-closed* -- exit 2 ("close all Hermes windows"). Not remapped.
- """
- system_root = Path(os.environ.get("SystemRoot", r"C:\Windows"))
- powershell = (
- system_root / "System32" / "WindowsPowerShell" / "v1.0" / "powershell.exe"
- )
- if not powershell.is_file():
- pytest.skip(f"Windows PowerShell not found at {powershell}")
-
- env = {
- **os.environ,
- # The arm writes its hand-off log under TEMP; point that at tmp_path
- # so the test leaves nothing behind.
- "TEMP": str(tmp_path),
- "TMP": str(tmp_path),
- }
-
- result = subprocess.run(
- [
- str(powershell),
- "-NoProfile",
- "-ExecutionPolicy",
- "Bypass",
- "-File",
- str(WINDOWS_PS1),
- "-SelfTestRetryState",
- ],
- capture_output=True,
- text=True,
- timeout=120,
- env=env,
- cwd=str(REPO_ROOT),
- )
-
- (tmp_path / "retry-state.stdout.log").write_text(result.stdout, encoding="utf-8")
- (tmp_path / "retry-state.stderr.log").write_text(result.stderr, encoding="utf-8")
- if "RETRY-STATE SELF-TEST: PASS" not in result.stdout or result.returncode != 0:
- pytest.fail(
- "The update retry state machine regressed: a completed update can "
- "be re-run after a watchdog timeout (the #96205 retry storm that "
- "hangs the Desktop updater popup for 70+ minutes), or a state maps "
- "to the wrong outcome. Fixture diagnosis follows.\n"
- f"--- stdout ---\n{result.stdout}\n--- stderr ---\n{result.stderr}",
- pytrace=False,
- )