Repository navigation
fix(updater): skip IPC when the main window is destroyed - #11567
Conversation
Greptile SummaryThis PR fixes an unhandled rejection that fires hourly on macOS when the auto-updater's async callback tries to IPC-send to a
Confidence Score: 5/5Safe to merge — the change is a narrow defensive wrapper around two existing IPC call sites, with no logic changes to the update flow itself. The fix is minimal and well-scoped: it adds a guard function that only early-returns when the window is already gone, so live windows are completely unaffected. The TOCTOU race between isDestroyed() and wc.send() is correctly handled by the try/catch. Three targeted tests verify the destroyed-window, destroyed-BrowserWindow-getter, and live-window paths. No other call sites were missed — a grep confirms no remaining bare mainWindowRef?.webContents.send calls in the file. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/main/updater.ts | Adds sendToMainWindow helper that guards IPC sends with isDestroyed() checks and a try/catch; replaces two direct mainWindowRef?.webContents.send call sites. |
| src/main/updater.check-failure.test.ts | Adds three new test cases: destroyed webContents skips send, destroyed BrowserWindow (getter throws) skips send, and live webContents still sends as expected. |
Sequence Diagram
sequenceDiagram
participant MU as MacUpdater (hourly)
participant UA as updater.ts
participant STW as sendToMainWindow()
participant BW as BrowserWindow
participant WC as WebContents
participant R as Renderer
MU->>UA: error-update / check-failure callback
UA->>UA: sendStatus() / checkForUpdateNudge()
UA->>STW: sendToMainWindow(channel, payload)
STW->>BW: win.isDestroyed?.()
alt Window destroyed
BW-->>STW: true
STW-->>UA: return (no send)
else Window alive
BW-->>STW: false
STW->>WC: wc.isDestroyed?.()
alt WebContents destroyed
WC-->>STW: true
STW-->>UA: return (no send)
else WebContents alive
WC-->>STW: false
STW->>WC: wc.send(channel, payload)
note over STW,WC: try/catch handles destroy-mid-send race
WC->>R: IPC message delivered
end
end
Reviews (4): Last reviewed commit: "test(updater): assert destroyed window n..." | Re-trigger Greptile
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. ℹ️ Recent review info
Walkthrough
Priority: Severity of issue fixed: Low Merge Risk:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/updater.check-failure.test.ts (1)
387-417: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winExercise the send-time teardown race.
sendMockthrows, butisDestroyed()returnstrue, sosend()is never reached and the helper’scatchbranch at Line 171 remains untested. Add a case whereisDestroyed()is false butsend()throws, while retaining this test for the early-return path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e6c3f03f-57af-4a42-b6d7-0777902b28b8
📥 Commits
Reviewing files that changed from the base of the PR and between ab665a3 and a1df3bc0e81b451e23340199ca40e404e79ee6e9.
📒 Files selected for processing (2)
src/main/updater.check-failure.test.tssrc/main/updater.ts
|
July 31 recovery review completed at cb2f884e9e399af4a55477f1532b20bc57ff63c9. The added commit is load-bearing: Electron throws from a destroyed BrowserWindow webContents getter before the original guard, so the fix now checks BrowserWindow.isDestroyed() first and adds a getter-throw regression test. Gates are clean: two independent code reviews; focused 12/12 and broader 254/254 updater tests; merge-tree 205/205 updater tests; regular and type-aware oxlint; node/web TypeScript; diff check; and a CLEAN performance/lifecycle audit. Retained live Electron evidence at this exact candidate shows the destroyed-window check no longer throws and the live-window path still delivers; the branch merges cleanly with current main fcb23e1 (tree c22e660dc6). No merge, approval, workflow approval, close, auto-merge, or check bypass was performed; CI on this new head remains authoritative. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a13d9a43-ee63-4328-9c17-4a1ddb52a4eb
📥 Commits
Reviewing files that changed from the base of the PR and between a1df3bc0e81b451e23340199ca40e404e79ee6e9 and cb2f884e9e399af4a55477f1532b20bc57ff63c9.
📒 Files selected for processing (2)
src/main/updater.check-failure.test.tssrc/main/updater.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/updater.ts
03aae03 to
ca721cc
Compare
ca721cc to
64b7e8f
Compare
64b7e8f to
295c4f8
Compare
The updater kept a reference to the main BrowserWindow after it closed, and every status/nudge/install-abort send read `webContents` on it. Electron throws "Object has been destroyed" from that getter, so the hourly background check produced main-process unhandled rejections from the MacUpdater failure path. Route all updater IPC through UpdaterState.sendToMainWindow, which drops the send when the window or its webContents is destroyed. The renderer re-pulls status via updater:getStatus on mount, so nothing is lost. Updater test window mocks now come from the shared updaterMainWindow helper. Fixes stablyai#11544 Co-authored-by: Brennan Benson <[email protected]> Co-authored-by: Neil <[email protected]>
295c4f8 to
a25d116
Compare
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
ELI5
Orca's updater sends little status messages ("checking for updates", "update failed", ...) to the app window. If that window had already been closed (macOS keeps Orca running with no window), sending a message to it crashed with "Object has been destroyed" in the background, once an hour. Now the updater checks the window is still alive before sending. If it is gone, the message is skipped; a reopened window asks for the latest status anyway.
What Changed
UpdaterState.mainWindowRefis set insetupAutoUpdaterand never cleared. Every updater IPC site didthis.mainWindowRef?.webContents.send(...). On a destroyedBrowserWindow, Electron'swebContentsgetter throwsTypeError: Object has been destroyed, so the hourly background check produced amain_unhandled_rejectionfromsendStatus <- sendErrorStatus <- handleFailure <- sendCheckFailureStatus <- MacUpdater. On the install path the throw also skippedsendInstallFailureStatusand the lifecycle record.UpdaterState.sendToMainWindow(channel, ...args)returns early when the ref is null,win.isDestroyed(), orwin.webContents.isDestroyed()(the same guard Electron uses internally). All 6 direct sends now go through it:updater:statusx2 (updater-status.ts)updater:clearDismissal(updater-nudge.ts)updater:quitAndInstallAborted(updater-install-execution.tsx2,updater-mac-install-preflight.tsx2; reachable from remote/mobilequitAndInstallafter the desktop window closed)updaterMainWindowtest helper now modelsisDestroyed()on the window and webContents, and the updater suites use it instead of inline{ webContents: { send } } as nevermocks. Added a regression test inupdater.check-failure.test.tswith a destroyed window whosewebContentsgetter throws.Why
Dropping IPC to a dead window is the correct behavior: every new window re-runs
setupAutoUpdaterand refreshes the ref, and the renderer pullsupdater:getStatuson mount, so no status is lost. The nudge dismissal is persisted before its send. A try/catch aroundsendwas considered and rejected:isDestroyed()andsend()run in the same synchronous main-process tick, so there is no race to catch, and a catch would hide real errors such as structured-clone failures. No IPC contract change, so mixed client/server versions are unaffected.Linked Issue
Fixes #11544
Visual Proof
N/A - main-process IPC behavior only; nothing on screen changes. The fix removes a background unhandled rejection after the window is closed.
Testing
Reproduced red on main: with
src/main/updater/reverted toorigin/mainand the new test kept,pnpm test src/main/updater.check-failure.test.tsfails withTypeError: Object has been destroyedatsendStatus src/main/updater/updater-status.ts:176, matching the stack in [Bug]: MacUpdater fires IPC to destroyed WebContents on update-check failure — TypeError: Object has been destroyed (hourly) #11544.Scratch probes (not committed) also covered a live window with destroyed webContents, and a window destroyed between a background error and a later menu check; both fail on main and pass here.
Green on branch (pre-rebase):
pnpm test src/main/updaterpassed 414/414 across all 33 updater suites. After rebasing onto currentmain(nosrc/main/updater*changes upstream), local reruns only hit the knownawait import('./updater')warm-up hook timeout under heavy machine load (it also reproduces onmain), with 0 assertion failures; CI is the final gate.oxlintandoxfmt --checkare clean on all 21 touched files.Platform: macOS (unit tests). The guard is platform-neutral; it applies equally on Linux/Windows and is independent of folder vs. git workspaces.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Original fix by @innocarpe in #11567, with follow-ups by maintainers (guarding the window itself, routing all updater sends through the helper, and consolidating test window mocks).
Agent skill upstream boundary
Notes
Security, cross-platform, remote SSH, mobile, backwards compatibility and performance considered: no IPC contract change, no platform-specific code, no new work on the hot path.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)