Skip to content

fix(updater): skip IPC when the main window is destroyed - #11567

Merged
nwparker merged 1 commit into
stablyai:mainfrom
innocarpe:fix/mac-updater-destroyed-webcontents
Oct 27, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
innocarpe:fix/mac-updater-destroyed-webcontents

Conversation

@innocarpe

@innocarpe innocarpe commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Before: UpdaterState.mainWindowRef is set in setupAutoUpdater and never cleared. Every updater IPC site did this.mainWindowRef?.webContents.send(...). On a destroyed BrowserWindow, Electron's webContents getter throws TypeError: Object has been destroyed, so the hourly background check produced a main_unhandled_rejection from sendStatus <- sendErrorStatus <- handleFailure <- sendCheckFailureStatus <- MacUpdater. On the install path the throw also skipped sendInstallFailureStatus and the lifecycle record.
  • After: a new UpdaterState.sendToMainWindow(channel, ...args) returns early when the ref is null, win.isDestroyed(), or win.webContents.isDestroyed() (the same guard Electron uses internally). All 6 direct sends now go through it:
    • updater:status x2 (updater-status.ts)
    • updater:clearDismissal (updater-nudge.ts)
    • updater:quitAndInstallAborted (updater-install-execution.ts x2, updater-mac-install-preflight.ts x2; reachable from remote/mobile quitAndInstall after the desktop window closed)
  • Tests: the shared updaterMainWindow test helper now models isDestroyed() on the window and webContents, and the updater suites use it instead of inline { webContents: { send } } as never mocks. Added a regression test in updater.check-failure.test.ts with a destroyed window whose webContents getter throws.

Why

Dropping IPC to a dead window is the correct behavior: every new window re-runs setupAutoUpdater and refreshes the ref, and the renderer pulls updater:getStatus on mount, so no status is lost. The nudge dismissal is persisted before its send. A try/catch around send was considered and rejected: isDestroyed() and send() 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 to origin/main and the new test kept, pnpm test src/main/updater.check-failure.test.ts fails with TypeError: Object has been destroyed at sendStatus 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/updater passed 414/414 across all 33 updater suites. After rebasing onto current main (no src/main/updater* changes upstream), local reruns only hit the known await import('./updater') warm-up hook timeout under heavy machine load (it also reproduces on main), with 0 assertion failures; CI is the final gate. oxlint and oxfmt --check are 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@greptile-apps

greptile-apps Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes an unhandled rejection that fires hourly on macOS when the auto-updater's async callback tries to IPC-send to a BrowserWindow whose WebContents has already been destroyed during renderer restart/teardown. A new sendToMainWindow helper gates every IPC send with isDestroyed() checks on both the window and its webContents, plus a try/catch for the residual TOCTOU window, replacing the two bare mainWindowRef?.webContents.send call sites.

  • sendToMainWindow helper (updater.ts): checks win.isDestroyed?.() before accessing webContents (avoiding the getter throw on a destroyed BrowserWindow), then checks wc.isDestroyed?.(), and wraps wc.send in a try/catch to handle the destroy-mid-send race.
  • Three new tests (updater.check-failure.test.ts): cover destroyed webContents (send not called), destroyed BrowserWindow with throwing getter (webContents never accessed), and live webContents (send still fires correctly).

Confidence Score: 5/5

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

Important Files Changed

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
Loading

Reviews (4): Last reviewed commit: "test(updater): assert destroyed window n..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0a6ac424-238d-4512-b5f0-b2b564d15289
📥 Commits

Reviewing files that changed from the base of the PR and between ca721cc0abb52ea0429a63a896751d59acd3b8a2 and 64b7e8f.

📒 Files selected for processing: 4
  • src/main/updater.check-failure.test.ts
  • src/main/updater/updater-nudge.ts
  • src/main/updater/updater-state.ts
  • src/main/updater/updater-status.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

UpdaterState adds sendToMainWindow to check window and webContents availability, avoid sending to destroyed contents, and catch send errors. Updater status and dismissal-clear notifications now use this helper. New check-failure tests cover destroyed contents, a destroyed window whose webContents getter throws, and status delivery when the contents remain live.

Priority: Low

Severity of issue fixed: Low

Merge Risk: Minimal · previous review 64b7e

No actionable issue remains in the supplied review; the updater change is ready for normal merge checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed The changes implement issue #11544. sendToMainWindow checks BrowserWindow.isDestroyed() before accessing webContents, checks webContents.isDestroyed() before sending, and catches send failures…
Out of Scope Changes check Passed The changes remain within the stated scope for issue #11544. They add a shared safe IPC helper, route the affected updater sends through it, and add focused regression tests. No window lifecycle refac…
Title check Passed The title clearly and concisely describes the main change: preventing IPC sends when the main window is destroyed.
Description check Passed The description is complete and aligned with the repository template. It explains the problem, implementation, rationale, linked issue, testing, visual proof, platform considerations, and checklist st…
Full details: Linked Issues check

Explanation

The changes implement issue #11544. sendToMainWindow checks BrowserWindow.isDestroyed() before accessing webContents, checks webContents.isDestroyed() before sending, and catches send failures. updater:status and updater:clearDismissal use this helper. The added tests cover destroyed targets and live-window status delivery.

Full details: Out of Scope Changes check

Explanation

The changes remain within the stated scope for issue #11544. They add a shared safe IPC helper, route the affected updater sends through it, and add focused regression tests. No window lifecycle refactor or update policy change is shown.

Full details: Description check

Explanation

The description is complete and aligned with the repository template. It explains the problem, implementation, rationale, linked issue, testing, visual proof, platform considerations, and checklist status.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/updater.check-failure.test.ts (1)

387-417: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Exercise the send-time teardown race.

sendMock throws, but isDestroyed() returns true, so send() is never reached and the helper’s catch branch at Line 171 remains untested. Add a case where isDestroyed() is false but send() 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.ts
  • src/main/updater.ts

@brennanb2025

Copy link
Copy Markdown
Contributor

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts
  • src/main/updater.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/updater.ts

Comment thread src/main/updater.check-failure.test.ts Resolved
@innocarpe
innocarpe force-pushed the fix/mac-updater-destroyed-webcontents branch from 03aae03 to ca721cc Compare August 1, 2026 09:03
@nwparker nwparker removed the P1 label Aug 19, 2026
@innocarpe
innocarpe force-pushed the fix/mac-updater-destroyed-webcontents branch from ca721cc to 64b7e8f Compare October 22, 2026 02:02
@nwparker
nwparker force-pushed the fix/mac-updater-destroyed-webcontents branch from 64b7e8f to 295c4f8 Compare October 26, 2026 11:15
@nwparker nwparker changed the title fix(updater): skip IPC when main WebContents is destroyed fix(updater): skip IPC when the main window is destroyed Oct 26, 2026
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]>
@nwparker
nwparker force-pushed the fix/mac-updater-destroyed-webcontents branch from 295c4f8 to a25d116 Compare October 27, 2026 06:29
@nwparker
nwparker merged commit 217f935 into stablyai:main Oct 27, 2026
57 of 59 checks passed
audichuang added a commit to audichuang/orca that referenced this pull request Oct 28, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Oct 29, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Oct 30, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 2, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 3, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 4, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 5, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 5, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 6, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 7, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 8, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 8, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 10, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 10, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 12, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 13, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 14, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 16, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 18, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 18, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 19, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 20, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 20, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 20, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
audichuang added a commit to audichuang/orca that referenced this pull request Nov 21, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Upstream stablyai#11567 checks win.isDestroyed() and webContents.isDestroyed() before sending IPC.
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.

[Bug]: MacUpdater fires IPC to destroyed WebContents on update-check failure — TypeError: Object has been destroyed (hourly)

4 participants