Skip to content

fix(updater): resume background checks after a local build session ends - #11223

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/local-build-check-restores-release-source
Jul 28, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/local-build-check-restores-release-source

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

The bug

A local-build check (macOS only: Option+click Check for Updates, pick a valid latest-mac.yml) sets activeUpdateSource = 'local' and pins the updater to a local feed server with allowDowngrade = true.

restoreReleaseUpdateSource() runs on only four paths — local selection error, a manual menu check, update-not-available, and the updater error handler. The update-available success path has no restore. Combined with the unconditional early return added at the top of runBackgroundUpdateCheck:

if (activeUpdateSource === 'local' || localBuildSelectionInProgress) { return }

...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 lastUpdateCheckAt froze.

Severity bounds

Two mitigations, stated so reviewers can judge scope:

  • A manual menu check fully recovers. checkForUpdatesFromMenu restores unconditionally; its guard only blocks during checking/downloading, not available.
  • Relaunching resets it. The state is process-lifetime only.
  • The trigger is macOS-only and requires the deliberate Option+click local-build flow.

The fix, and why not the obvious version

Not restoring when update-available fires. The local flow is still live at that moment — the pending download needs activeLocalBuildFeed and allowDowngrade. 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: error and not-available already restore, quitAndInstall exits 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; dismissUpdate persisted dismissedUpdateVersion and 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() calls sendStatus({ state: 'downloading' }) synchronously, before it calls into electron-updater — so by the time any download is under way the status is no longer available and the hook is inert. It is gated the same way against downloaded, where Squirrel.Mac may still be staging. The gate lives in main, so it holds regardless of what the renderer does: UpdateCard in fact routes downloading/downloaded/error to collapse, not dismiss, and a dismiss during a nudge-driven download still lands harmlessly.

After restoring, main sends idle. Without that, the stale available status would still satisfy downloadUpdate()'s canStart check 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:200

I did not change it. That if (!isLocalBuildCheck()) correctly skips recordCompletedUpdateCheck() 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 in runBackgroundUpdateCheck, not to this line, and it is fixed there.

Tests

Fail-first, verified red on origin/main (70c81c4) with only the test file applied:

Test Result on main
keeps the automatic check chain alive across a local build session RED — expected "vi.fn()" to be called with [ 'updater:status', {state:'not-available'} ] / Number of calls: 0
restores release checks when an offered local build is dismissed RED
keeps the local feed in force when a dismiss lands during a local build download RED
leaves a dismissed release update on the release source RED

The 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, allowDowngrade and disableDifferentialDownload must all still be in force; and a normal release-channel dismissal must leave the offer untouched.

Note on assertion style: the chain test asserts through its own webContents.send mock rather than the shared autoUpdaterMock.checkForUpdates counter. The shared counter made it pass in a full-file run while failing in isolation — sibling tests' real timers call into the shared mock. A status only reaches this window when this module instance owns the check attempt, so the send-based assertion cannot be faked by another test. Verified red in isolation and in the full file, green in both after the fix.

No existing updater test was weakened.

Verification

  • vitest src/main/updater.test.ts — 89 passed
  • All other updater + local-build suites — 12 files, 96 passed
  • UpdateCard.test.ts + UpdateCard.error-card.test.tsx — 46 passed
  • pnpm typecheck (after clearing tsbuildinfo) — clean
  • pnpm lint — clean, including max-lines ratchet
  • pnpm check:code-quality:changed — 0 new findings across 9 files

Cross-platform: the trigger is macOS-gated (checkForLocalBuildFromMenu rejects other platforms), but nothing added here is platform-conditional — the dismiss hook and timer re-arm behave identically on Windows and Linux, where activeUpdateSource is always 'release' and the hook is a no-op.

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.
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2fdaf481-6c50-4a5b-948e-69df3c7e0aa1

📥 Commits

Reviewing files that changed from the base of the PR and between 2b88931 and 2871b78.

📒 Files selected for processing (9)
  • src/main/updater.test.ts
  • src/main/updater.ts
  • src/main/window/attach-main-window-services.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/UpdateCard.error-card.test.tsx
  • src/renderer/src/components/UpdateCard.test.ts
  • src/renderer/src/store/slices/ui.ts
  • src/renderer/src/web/web-preload-api.ts

📝 Walkthrough

Walkthrough

The updater now re-schedules automatic checks when background checks are deferred. A new dismissAvailableUpdate operation clears offered local-update state and restores the release source when applicable. The operation is exposed through main-process IPC, typed preload APIs, the renderer store, and the web fallback. Tests cover deferred checks, local update dismissal during offer and download states, release dismissal behavior, and updated updater API mocks.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is thorough but doesn't follow the required template sections or headings. Reformat it to include Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes, and fill in the missing details.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: background update checks resume after a local build session ends.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown

Greptile Summary

This 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.

  • runBackgroundUpdateCheck now returns a boolean (true = launched, false = deferred/skipped), and the scheduleAutomaticUpdateCheck timeout re-arms with the full 24 h interval whenever the check is deferred, preventing a single deferral from permanently ending the scheduling chain.
  • A new dismissAvailableUpdate IPC action (main → preload → renderer) is wired into the dismissUpdate store action; on the main side it clears the local-build context and restores the release feed, guarded so it is a no-op for release-channel dismissals and for any state where a local download is still in progress.

Confidence Score: 4/5

Safe 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.

Important Files Changed

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
Loading

Comments Outside Diff (1)

  1. src/renderer/src/components/UpdateCard.test.ts, line 135-163 (link)

    P2 dismissAvailableUpdate call not asserted in renderer tests

    The existing dismissUpdate describe blocks verify dismissedUpdateVersion, window.api.ui.set, and dismissNudge, but none of them assert that window.api.updater.dismissAvailableUpdate is called. The end-to-end restore behaviour is well covered in updater.test.ts, but a call-site assertion here would guard against the renderer accidentally dropping the call in a future refactor of dismissUpdate.

    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

@brennanb2025
brennanb2025 merged commit 5753cf6 into main Jul 28, 2026
29 of 30 checks passed
zpyoung pushed a commit to zpyoung/orca that referenced this pull request Jul 29, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant