The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop-update): completed update killed with exit 124 is terminal, never re-run (#96205)
Brooklyn Nicholson1b0d8aa3d503
diff --git a/scripts/desktop-update/posix.sh b/scripts/desktop-update/posix.shindex b1c86d26ed7..6804be6c311 100755--- a/scripts/desktop-update/posix.sh+++ b/scripts/desktop-update/posix.sh@@ -848,6 +848,20 @@ OUT="$("${UPDATE_INVOKE[@]}" update --yes $GATEWAY_FLAG $KEEP_STASH "${TARGET_ARprintf '%s\n' "$OUT" >> "$LOG" 2>/dev/nulllog "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.ps1index bb1f0a93a2a..82114e1d6c6 100644--- a/scripts/desktop-update/windows.ps1+++ b/scripts/desktop-update/windows.ps1@@ -54,6 +54,7 @@ param([switch]$SelfTestUi,[switch]$SelfTestPipeDrain,[switch]$SelfTestMarker,+ [switch]$SelfTestRetryState,[switch]$SelfTestWorkingDirectory)@@ -62,7 +63,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 $InstallRoot) {+if (-not $SelfTestUi -and -not $SelfTestPipeDrain -and -not $SelfTestRetryState -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"@@ -1249,6 +1250,40 @@ 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.+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 }+ }+ return $StepResult+}+function Set-InstallRootCurrentDirectory([string]$Root) {$resolved = [System.IO.Path]::GetFullPath($Root)[Environment]::CurrentDirectory = $resolved@@ -1504,6 +1539,56 @@ exit 3exit 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@@ -1638,6 +1723,10 @@ 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# update/build failures propagate and must not trigger another owner.@@ -1651,6 +1740,7 @@ try {# legacy one being converted until this run succeeds.$updateArgs = $runtimeArgs + @('update', '--yes') + $gatewayArg + $forceArg + $targetArgs$res = Invoke-HermesStep $pythonExe $updateArgs 'update'+ $res = Resolve-HermesUpdateOutcome $res}# Pre-PM updates reported a successful exit with a failed build warning.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.pynew file mode 100644index 00000000000..cc9cca454a3--- /dev/null+++ b/tests/scripts/desktop_update/test_desktop_update_windows_retry_state.py@@ -0,0 +1,105 @@+"""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"++[email protected]("windows")+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,+ )