Repository navigation
fix(updater): resume background checks after a local build session ends - #11223
Conversation
A local-build check (Option+click "Check for Updates" on macOS) pins activeUpdateSource to 'local' for the rest of the process. The 'update-available' success path never restores it, and runBackgroundUpdateCheck early-returns on it, so every wake-from-sleep check, window-focus daily check and nudge poll became a no-op once a local build reached 'available'. The one-shot automatic timer fired into that early return and nothing re-armed it, so the scheduling chain died too and lastUpdateCheckAt froze. Restoring the source when 'update-available' fires would break the flow the user just started — the pending download still needs the local feed and allowDowngrade. Instead the release source is restored when the user closes the offered card, which main previously never learned about, and only while status is exactly 'available': downloadUpdate() flips status to 'downloading' synchronously before it calls into electron-updater, so this cannot fire once a download is under way. The automatic timer now re-arms when a check is deferred rather than launched, so a deferral can no longer end automatic checks for the process lifetime.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
📝 WalkthroughWalkthroughThe updater now re-schedules automatic checks when background checks are deferred. A new 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR fixes two related bugs in the Electron auto-updater: the automatic background-check timer chain dying after a deferred check during a local-build session, and the lack of a "session ended" signal when a user dismisses the offered local build without installing it.
Confidence Score: 4/5Safe to merge. The two changed behaviours (timer re-arm on deferral, dismiss signal from renderer) are well-isolated, gated by existing state flags, and each covered by a dedicated fail-first test. All four new tests were verified red on main and green after the fix, including the timing-sensitive chain test which uses a send-based assertion specifically to avoid cross-test timer leakage. The dismiss guard (state === 'available' && source === 'local') is tight: a download already in progress keeps the local feed alive, and a release-channel dismissal is a no-op on the main side. The only gap is that the renderer-level dismissUpdate tests don't assert that dismissAvailableUpdate is called, leaving that call-site unguarded against future refactors of the renderer action. Files Needing Attention: src/renderer/src/components/UpdateCard.test.ts — the dismissUpdate describe blocks should gain an assertion that window.api.updater.dismissAvailableUpdate is called.
|
| Filename | Overview |
|---|---|
| src/main/updater.ts | Core fix: runBackgroundUpdateCheck returns boolean so deferred checks can re-arm the timer; new dismissAvailableUpdate export with correct 'available' + 'local' guards to end abandoned local sessions. |
| src/main/updater.test.ts | Four new tests covering the chain-alive scenario, dismiss-restores-release-source, mid-download dismiss no-op, and release-channel dismiss no-op; each was verified red on main. |
| src/main/window/attach-main-window-services.ts | Registers the new updater:dismissAvailableUpdate IPC handler with correct removeHandler guard before handle, matching the existing pattern for all other updater channels. |
| src/renderer/src/store/slices/ui.ts | dismissUpdate now calls window.api.updater.dismissAvailableUpdate() unconditionally (fire-and-forget); main's guard makes it a no-op for non-local and non-available states. |
| src/renderer/src/components/UpdateCard.test.ts | Adds dismissAvailableUpdate mock to prevent test failures; existing dismissUpdate describe blocks do not add assertions that the new IPC call is made, leaving that path untested at the renderer level. |
| src/preload/index.ts | Adds dismissAvailableUpdate IPC bridge, matching the pattern of dismissNudge. |
| src/preload/api-types.ts | Adds dismissAvailableUpdate: () => Promise to the PreloadApi updater type. |
| src/renderer/src/web/web-preload-api.ts | Adds no-op dismissAvailableUpdate stub for the web (non-Electron) environment, consistent with all other updater stubs here. |
| src/renderer/src/components/UpdateCard.error-card.test.tsx | Adds dismissAvailableUpdate mock for completeness; no behavioral regression. |
Sequence Diagram
sequenceDiagram
participant Timer as Auto-check Timer
participant Main as updater.ts (main)
participant IPC as IPC Bridge
participant Renderer as UpdateCard / ui.ts
Note over Timer,Main: Local build session starts
Renderer->>IPC: "checkForUpdatesFromMenu({localBuild:true})"
IPC->>Main: checkForLocalBuildFromMenu()
Main->>Main: "activeUpdateSource = 'local', allowDowngrade = true"
Main->>Renderer: "updater:status {state:'available', source:'local'}"
Note over Timer,Main: Timer fires during local session (OLD: chain dies here)
Timer->>Main: runBackgroundUpdateCheck()
Main-->>Timer: false (deferred — local source active)
Main->>Timer: scheduleAutomaticUpdateCheck(24h) NEW re-arm
Note over Renderer: User closes the update card without installing
Renderer->>IPC: dismissAvailableUpdate() NEW IPC call
IPC->>Main: dismissAvailableUpdate()
Main->>Main: "guard: state==='available' and source==='local'"
Main->>Main: clearAvailableUpdateContext()
Main->>Main: "restoreReleaseUpdateSource() — allowDowngrade=false"
Main->>Renderer: "updater:status {state:'idle'}"
Note over Timer,Main: Re-armed timer fires — session is over
Timer->>Main: runBackgroundUpdateCheck()
Main-->>Timer: true (launched)
Main->>Renderer: "updater:status {state:'not-available' or 'available'}"
Main->>Timer: scheduleAutomaticUpdateCheck(24h) via outcome handler
Comments Outside Diff (1)
-
src/renderer/src/components/UpdateCard.test.ts, line 135-163 (link)dismissAvailableUpdatecall not asserted in renderer testsThe existing
dismissUpdatedescribe blocks verifydismissedUpdateVersion,window.api.ui.set, anddismissNudge, but none of them assert thatwindow.api.updater.dismissAvailableUpdateis called. The end-to-end restore behaviour is well covered inupdater.test.ts, but a call-site assertion here would guard against the renderer accidentally dropping the call in a future refactor ofdismissUpdate.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Reviews (1): Last reviewed commit: "fix(updater): resume background checks a..." | Re-trigger Greptile
…ds (stablyai#11223) A local-build check (Option+click "Check for Updates" on macOS) pins activeUpdateSource to 'local' for the rest of the process. The 'update-available' success path never restores it, and runBackgroundUpdateCheck early-returns on it, so every wake-from-sleep check, window-focus daily check and nudge poll became a no-op once a local build reached 'available'. The one-shot automatic timer fired into that early return and nothing re-armed it, so the scheduling chain died too and lastUpdateCheckAt froze. Restoring the source when 'update-available' fires would break the flow the user just started — the pending download still needs the local feed and allowDowngrade. Instead the release source is restored when the user closes the offered card, which main previously never learned about, and only while status is exactly 'available': downloadUpdate() flips status to 'downloading' synchronously before it calls into electron-updater, so this cannot fire once a download is under way. The automatic timer now re-arms when a check is deferred rather than launched, so a deferral can no longer end automatic checks for the process lifetime.
…ds (stablyai#11223) A local-build check (Option+click "Check for Updates" on macOS) pins activeUpdateSource to 'local' for the rest of the process. The 'update-available' success path never restores it, and runBackgroundUpdateCheck early-returns on it, so every wake-from-sleep check, window-focus daily check and nudge poll became a no-op once a local build reached 'available'. The one-shot automatic timer fired into that early return and nothing re-armed it, so the scheduling chain died too and lastUpdateCheckAt froze. Restoring the source when 'update-available' fires would break the flow the user just started — the pending download still needs the local feed and allowDowngrade. Instead the release source is restored when the user closes the offered card, which main previously never learned about, and only while status is exactly 'available': downloadUpdate() flips status to 'downloading' synchronously before it calls into electron-updater, so this cannot fire once a download is under way. The automatic timer now re-arms when a check is deferred rather than launched, so a deferral can no longer end automatic checks for the process lifetime.
The bug
A local-build check (macOS only: Option+click Check for Updates, pick a valid
latest-mac.yml) setsactiveUpdateSource = 'local'and pins the updater to a local feed server withallowDowngrade = true.restoreReleaseUpdateSource()runs on only four paths — local selection error, a manual menu check,update-not-available, and the updatererrorhandler. Theupdate-availablesuccess path has no restore. Combined with the unconditional early return added at the top ofrunBackgroundUpdateCheck:...once a local build check reaches
available, every wake-from-sleep check, window-focus daily check and 30-minute nudge poll returns at that guard for the rest of the process. Dismissing the card is not required to get into this state. A user in this state never learns about a release, including a security release.There is a second, compounding effect. The automatic check timer is one-shot; the chain is re-armed by each check's outcome handler. A deferred check reaches no outcome handler, so the timer that fired during the local session was the last one — the scheduling chain died and
lastUpdateCheckAtfroze.Severity bounds
Two mitigations, stated so reviewers can judge scope:
checkForUpdatesFromMenurestores unconditionally; its guard only blocks duringchecking/downloading, notavailable.The fix, and why not the obvious version
Not restoring when
update-availablefires. The local flow is still live at that moment — the pending download needsactiveLocalBuildFeedandallowDowngrade. Restoring there closes the feed server and would break the very flow the user just started, trading a background-check freeze for a broken local install.Tracing the lifecycle, the local session has no terminal event on the success path:
errorandnot-availablealready restore,quitAndInstallexits the process, and everything else leaves the session pinned indefinitely. The one real abandonment point — the user closing the offered card — was renderer-only state;dismissUpdatepersisteddismissedUpdateVersionand main never learned about it.So this adds that missing signal (
updater:dismissAvailableUpdate) and restores there.Why it cannot fire mid-download: the restore is gated on
currentStatus.state === 'available'.downloadUpdate()callssendStatus({ state: 'downloading' })synchronously, before it calls into electron-updater — so by the time any download is under way the status is no longeravailableand the hook is inert. It is gated the same way againstdownloaded, where Squirrel.Mac may still be staging. The gate lives in main, so it holds regardless of what the renderer does:UpdateCardin fact routesdownloading/downloaded/errorto collapse, not dismiss, and a dismiss during a nudge-driven download still lands harmlessly.After restoring, main sends
idle. Without that, the staleavailablestatus would still satisfydownloadUpdate()'scanStartcheck and let a retry try to pull the local version off the now-restored release feed.Separately, the automatic timer now re-arms when a check is deferred rather than launched, so a single deferral can no longer end automatic checks for the process lifetime.
On
updater-events.ts:200I did not change it. That
if (!isLocalBuildCheck())correctly skipsrecordCompletedUpdateCheck()for a local check — a local build check is not evidence the release channel was checked, and recording it would suppress the next release check for 24h. The severed chain traces to the early return inrunBackgroundUpdateCheck, not to this line, and it is fixed there.Tests
Fail-first, verified red on
origin/main(70c81c4) with only the test file applied:keeps the automatic check chain alive across a local build sessionexpected "vi.fn()" to be called with [ 'updater:status', {state:'not-available'} ] / Number of calls: 0restores release checks when an offered local build is dismissedkeeps the local feed in force when a dismiss lands during a local build downloadleaves a dismissed release update on the release sourceThe first is the behavioral proof: a local build reaches
available, the scheduled release check fires and defers, the local download then fails (an existing restore path — no new API involved), and the next automatic tick must actually run a release check. On main it never does, because the chain died at the deferral.The two regression guards cover the trap: while a local download is genuinely pending, the local feed URL,
allowDowngradeanddisableDifferentialDownloadmust all still be in force; and a normal release-channel dismissal must leave the offer untouched.No existing updater test was weakened.
Verification
vitest src/main/updater.test.ts— 89 passedUpdateCard.test.ts+UpdateCard.error-card.test.tsx— 46 passedpnpm typecheck(after clearingtsbuildinfo) — cleanpnpm lint— clean, including max-lines ratchetpnpm check:code-quality:changed— 0 new findings across 9 filesCross-platform: the trigger is macOS-gated (
checkForLocalBuildFromMenurejects other platforms), but nothing added here is platform-conditional — the dismiss hook and timer re-arm behave identically on Windows and Linux, whereactiveUpdateSourceis always'release'and the hook is a no-op.