Skip to content

fix(desktop): a cancelled update download closes its transfer and a retry starts fresh - #292

Merged
jayleaton merged 7 commits into
mainfrom
fix/update-download-cancel
Nov 20, 2026
Merged

jayleaton merged 7 commits into
mainfrom
fix/update-download-cancel

Conversation

@jayleaton

@jayleaton jayleaton commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Randy's round-2 review of #287 (#287) found two problems with how a stalled update gets cancelled. #287 had already merged, so the fixes land here.

  1. Cancelling an update download did not actually stop it. In the installed electron-updater 6.8.9, cancelling a differential download left downloadPromise reserved, so Retry joined the cancelled download. Cancelling a full download rejected the promise but left the HTTP request open.
  2. The provider refresh deadline only freed the spinner. The 60 s Promise.race returned, but the refresh RPC kept running, so a repeat check could overlap it.

Randy's review of this PR found two more:

  1. A cancel between differential ranges left a continuation running. electron-updater pauses for a second after every 100th range. A cancel during that pause rejected the download, but the scheduled continuation still ran, copied the next block and opened range 101 next to the retry.
  2. An update check that joined a running refresh still spun past its deadline. refreshProviders is single-flight, so the scheduler hands a second caller the running promise and never applies that caller's abort signal. A check that joined a stalled refresh started elsewhere waited on it forever, and nothing ended the shared RPC.

Randy's second review found three more:

  1. The 60 s cut-off applied to every provider refresh. A manual model refresh waits on Antigravity model discovery, which has its own 90 s budget on the server, so the client stopped a 75 s refresh at 60 s.
  2. One caller's abort cancelled the shared refresh. If Check for Updates started the refresh and a manual refresh joined it, the update check's deadline stopped the RPC for both.
  3. runAtomCommand always passed a third argument. The provider snapshot and VCS revalidation suites assert the two-argument call, so CI Test failed.

Root cause in electron-updater

  • Full download: HttpExecutor.doDownload in builder-util-runtime 9.7.0 receives onCancel from download/downloadToBuffer but never calls it. On cancel, createPromise rejects while the request keeps going. Nothing ends the file stream either, because pipe() never ends its destination when the response is aborted.
  • Differential download: DifferentialDownloader creates its range requests through httpExecutor.createRequest and never passes them the token. The single-range path, the multi-range path and readRemoteBytes all do this. A stalled range request ignores the cancel, so doDownloadUpdate stays pending and AppUpdater.downloadPromise stays set. downloadUpdate then returns that same promise to the next caller.
  • The single-range path chains each range and copy step through callbacks, and every 100th range schedules the next one with a bare setTimeout. Nothing checks the token before a step resumes, so a continuation scheduled before the cancel runs after it.
  • Even after both are fixed, Effect.tryPromise returns as soon as it is interrupted. electron-updater clears downloadPromise only after it finishes its async temp-file cleanup, so a Retry that came straight away still joined the old download.

Fix

  • New patches/builder-util-runtime@9.7.0.patch, registered and pinned in pnpm-workspace.yaml: doDownload aborts its request on cancel, and an aborted response destroys the file stream.
  • patches/electron-updater@6.8.9.patch gains a change to DifferentialDownloader. It tracks its open requests, and on cancel it aborts them and rejects through cancellationToken.createPromise. multipleRangeDownloader creates its requests the same way. A cancel also clears the pending pause after the 100th range. Every range or copy step checks the token before it resumes, in both the single-range and multiple-range paths.
  • ElectronUpdater.downloadUpdate cancels on interrupt and then waits for electron-updater's download promise to settle. raceFirst in DesktopUpdates waits for the losing fiber, so the stall error and its Retry show only after electron-updater has released the download. The 5-minute backstop is unchanged. It still resets on every download-progress event, and it can now actually stop the transfer.
  • Atom commands take an optional { signal }. It flows through runAtomCommand, createRuntimeCommand and useAtomCommand on web and mobile, and aborting it interrupts the command's effect, which interrupts the RPC. The shared update check (client-runtime/updateCheck.ts, used on web and mobile) gives each request an abort deadline in place of the Promise.race. A request that hits the deadline is still reported as "No answer after 60 seconds."
  • The atom command scheduler takes each caller's signal. A caller's signal ends only its own wait. A single-flight run gets its own AbortController, counts the callers waiting on it, and is cancelled only when the last one leaves. A caller with no signal never leaves, so a manual refresh keeps a shared run alive after the update check that started it gives up. The 60 s deadline belongs to the update check alone, and manual refreshes keep the server's provider budgets. The round-2 timeout option on runtime commands is gone.
  • runAtomCommand calls command.run(registry, input) when there is no signal, and passes { signal } only when one is given.

Tests
Each test fails without its fix and passes with it.

  • apps/desktop/src/electron/ElectronUpdater.test.ts, "ElectronUpdater stalled download". These tests use the real electron-updater singleton (Linux AppImageUpdater) and the real ElectronHttpExecutor download code over node:http. A local server serves the update.
    • Two tests stall the update bytes partway through, interrupt ElectronUpdater.downloadUpdate, check that the server sees the stalled connection close, then retry and check that the retry sends a new request.
      • Before the fix, full download: AssertionError: the cancelled request stayed open.
      • Before the fix, differential download: AssertionError: the cancelled request stayed open. With only the retry assertion: AssertionError: the retry joined the cancelled download.
      • With only the dependency patches, both cases fail: the retry joined the cancelled download. That is what the wait in ElectronUpdater.ts fixes.
    • "a differential download cancelled between ranges opens no further range" covers finding 3. The update has 101 changed blocks between copies, so electron-updater pauses after the 100th range. The test cancels after the client has read the 100th range, which puts the cancel inside the pause. Then it retries. The server stalls the retry's first range, so any later range request must come from the cancelled download. The test checks that the retry starts again from the first range, and that no other range is requested in the next 2 seconds.
      • Before the fix it failed 3 of 3 runs: AssertionError: the cancelled download opened another range, actual: { _tag: 'Some', value: 3216 }. 3216 is the offset of range 101.
      • After the fix the file passes 3 of 3 runs.
  • packages/client-runtime/src/updateCheck.test.ts
    • "interrupts a request that never answers and reports it". This replaces the round-1 hang test that fix(web): check for updates checks Ada and every provider on every surface #290 moved here. The refresh is a real createRuntimeCommand whose effect never finishes. The test checks for "No answer after 2 seconds." and waits until the effect is interrupted. Before the fix the reason matches, but the effect is never interrupted and the test times out. After the fix it passes.
    • "stops waiting on a refresh it joined at its own deadline" covers finding 4. A single-flight refresh that never finishes is started by a caller with no deadline, and an update check with a 2 s deadline joins it. At 2 s the check reports "No answer after 2 seconds." Before the round-2 fix: Error: Test timed out in 5000ms.
    • "leaves a refresh it started running for a manual refresh that joined it" covers finding 6. The update check starts a single-flight refresh, a manual refresh joins it, and the check's 2 s deadline fires. Then the refresh answers. The check reports "No answer after 2 seconds.", the manual refresh gets the providers, and the refresh effect was never interrupted.
      • Before the fix: AssertionError: expected { _tag: 'Failure', … } to match object { _tag: 'Success', … }, because the check's abort interrupted the shared run.
      • After the fix the file passes (5 tests).
  • packages/client-runtime/src/state/server.test.ts, "lets a manual provider refresh outlast a minute" covers finding 5. It runs the real refreshProviders command from createServerEnvironmentAtoms against an RPC that answers after 75 s, on fake timers.
    • Before the fix: the result was { _tag: "Failure" } with an Interrupt cause at 60 s.
    • After the fix it succeeds with the providers.
  • Finding 7 needed no new test. providerSkills.test.ts ("scans a missing snapshot once and skips a repeat inside the TTL") and vcsStatusRevalidation.test.ts ("refreshes once per connection, shared by every subscriber, and again on reconnect") failed on da20a06 with expected "vi.fn()" to be called with arguments: [ Anything, … ]. Both pass after the fix (30 tests).
  • These targeted suites pass: ElectronUpdater.test.ts (4), plus updateCheck.test.ts, server.test.ts, runtime.test.ts, providerSkills.test.ts and vcsStatusRevalidation.test.ts together (120).
  • vp run check:changed passes: format, lint, knip, typecheck of 41 packages, 5 test files, react compiler and unused patches.

Merged with main (c3bee4a): main's command scheduler already counts the waiters on a shared run, so the client-runtime part uses it, and the per-caller deadline and joined-refresh tests pass against it unchanged. Upstream's resumable full download (pingdotgg#38038) stopped handing doDownload an onCancel, so a cancelled full download left its request open again; "a cancelled full download closes its request and a retry downloads again" failed on the merged tree. The electron-updater patch now passes onCancel so a cancel aborts the request, and both that test and upstream's ElectronHttpExecutor tests pass.

CI flake fixed (packages/mcp-gateway): after the merge, "moves a running stdio session to the next owner" failed three runs in a row with connect ECONNRESET or read ECONNRESET. It had also failed on main at ff92ac7 and f7ad11b. A stopping owner can accept the launcher's reconnect and then reset it while it releases the port, and the launcher only treated ECONNREFUSED as transient, so it exited. connectMcpSession now maps ECONNRESET during the handshake to GatewayRetiringError, so the launcher retries and starts or joins the next owner. The new test "joins the next owner when a stopping owner resets the connection" uses a listener that resets the first connection. Before the fix it failed with connect ECONNRESET; after it, all 19 tests in sharedGateway.test.ts pass.

🤖 Generated with Claude Code

jayleaton and others added 2 commits November 19, 2026 12:41
…etry starts fresh

electron-updater 6.8.9 never handed its cancellation token to the requests doing the work.
builder-util-runtime's doDownload ignored the onCancel it was given, so a cancelled full download
rejected but kept its request and file open. DifferentialDownloader made its range requests with
no token at all, so a cancelled differential download stayed pending and kept downloadPromise
reserved, and Retry rejoined it. Both are patched to abort their requests on cancel, and the
desktop waits for electron-updater to release the download before the cancel completes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t it gave up on

The 60-second Promise.race freed the check but left the refresh RPC running, so a repeat check
could overlap it. Atom commands now take an abort signal that interrupts their effect, and the
update check aborts each request at its deadline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L labels Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: c3bee4a · PR result: 196c8be · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@jayleaton

Copy link
Copy Markdown
Owner Author

Randy reviewed head c6e8930. What's verified:

  • The Linux full and differential stall-and-retry tests pass.
  • Frozen install and the unused-patch check pass.
  • The lockfile keeps builder-util-runtime 9.7.0 for every consumer, and both electron-builder and electron-updater load the patched runtime.

Two blockers:

  1. Blocking: patches/electron-updater@6.8.9.patch:31. Cancelling between differential ranges can leave a continuation running. A cancel during the pause after range 100 rejected the promise, but the scheduled continuation still opened range 101. Fix: cancel pending continuations and check the token before each range or copy step resumes. Add a regression test that cancels between requests.
  2. Blocking: packages/client-runtime/src/state/runtime.ts:235. The 60 s deadline can leave the update check spinning when it joins a provider refresh that's already running under the same key. The scheduler returns the existing promise before it applies the second caller's signal. Fix: give the shared refresh a bounded RPC lifetime, and make each caller's wait abortable. Test an update check that joins a stalled refresh started elsewhere.

jayleaton and others added 2 commits November 19, 2026 18:15
…no further range

Cancelling during electron-updater's one-second pause after every 100th range rejected the
download, but the scheduled continuation still ran and opened the next range, racing the retry.
The patched DifferentialDownloader now clears that pending pause on cancel, and every range or
copy step checks the cancellation token before it resumes, in both the single and multiple range
paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fresh stops at its deadline

A single-flight command hands a joining caller the running promise, so the caller's abort signal
never reached it and the update check kept spinning past its 60-second deadline. Each caller's
wait now ends when its own signal aborts, and the shared refresh-providers run is interrupted
after 60 seconds, so the request itself ends even when no caller can cancel it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jayleaton

Copy link
Copy Markdown
Owner Author

Randy reviewed head da20a06 (round 2). Changes needed.

Both round-one regressions are fixed. The old updater opened range 101 after a cancel in 3 of 3 runs, and the old joined update check missed its deadline. Targeted tests passed (92/92), and so did vp run check:changed.

Blocking:

  1. packages/client-runtime/src/state/server.ts:1718: the 60 s cut-off applies to every refresh. A manual model refresh can rightly take longer than 60 s, because the RPC waits for Antigravity model discovery, which has its own 90 s budget (AntigravityDriver.ts:500-525). A fake-clock reproduction showed the client stopping a 75 s refresh at 60 s. Set the update-check deadline per caller, and let manual refreshes use the server's provider-specific budgets.
  2. packages/client-runtime/src/state/runtime.ts:490: one caller's abort cancels the shared refresh. Suppose Check for Updates starts the refresh and a manual caller joins it. If the first caller then aborts, the RPC stops for both callers (reproduced with one shared execution). Fix:
    • Give the shared run its own cancellation signal.
    • Detach each caller when it aborts.
    • Cancel the RPC only when the last waiter leaves.
  3. packages/client-runtime/src/state/runtime.ts:373: runAtomCommand passes {} as a third argument even when there is no signal. The provider snapshot and VCS revalidation suites fail on this head and pass on the base, which is why the CI Test job and the aggregate Check fail. Keep the two-argument call when no signal is given.

jayleaton and others added 3 commits November 20, 2026 00:20
…at started it

The 60 s deadline now belongs to the update check alone. Manual refreshes
keep the server's own provider budgets, so a 75 s Antigravity model
discovery is no longer cut off.

A single-flight run gets its own AbortController. Each caller's signal only
ends that caller's wait, and the run is cancelled once the last waiter
leaves. runAtomCommand keeps the two-argument call when there is no signal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main's command scheduler already counts the waiters on a shared run, so this
branch takes it and adapts updateCheck to its API. Upstream's resumable full
download (pingdotgg#38038) stopped handing doDownload an onCancel, which left a
cancelled request open again; the electron-updater patch now gives it one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er resets its connection

A stopping owner can accept the launcher's reconnect and then reset it while
it releases the port. Only ECONNREFUSED was transient, so the launcher exited
with ECONNRESET instead of moving the session; this made the owner-handover
test fail on CI. Treat a reset during the handshake like a retiring owner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jayleaton
jayleaton merged commit 48a0854 into main Nov 20, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant