Skip to content

fix(desktop): guard destroyed recovery windows#37406

Merged
Hona merged 1 commit into
anomalyco:devfrom
Hona:desktop-recovery-export
Jul 17, 2026
Merged

fix(desktop): guard destroyed recovery windows#37406
Hona merged 1 commit into
anomalyco:devfrom
Hona:desktop-recovery-export

Conversation

@Hona

@Hona Hona commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

  • make renderer recovery diagnostics tolerate destroyed BrowserWindow and WebContents instances
  • allow load-failure and renderer-gone handlers to reach the existing recovery dialog and Export Logs action
  • harden app-level and unresponsive sampler URL logging against the same lifecycle race

Related to #33106, #32923, and #35501.

Testing

  • bun test src/main (47 passed)
  • bun typecheck
  • bun run build
  • pre-push bun turbo typecheck (30 packages)

Test decision

No regression test is included because reproducing this requires Electron's native app.exit and responsive event ordering; structural fakes would not exercise the failing lifecycle race.

Copilot AI review requested due to automatic review settings July 17, 2026 00:57
@Hona
Hona requested a review from Brendonovich as a code owner July 17, 2026 00:57

Copilot AI 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.

Pull request overview

This PR hardens the Desktop main-process recovery/diagnostics logging against Electron lifecycle races where a BrowserWindow/WebContents is already destroyed when event handlers fire, preventing uncaught TypeError: Object has been destroyed crashes and allowing recovery dialogs/export-logs flows to proceed.

Changes:

  • Introduces safeWindowURL / safeWebContentsURL helpers that tolerate destroyed instances and exceptions when reading URLs.
  • Switches window recovery and unresponsive sampling logs to use the safe URL helpers.
  • Hardens app-level render-process-gone logging similarly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/desktop/src/main/windows.ts Uses safeWindowURL(win) in recovery/unresponsive/responsive/load-failure diagnostics to avoid destroyed-object URL access.
packages/desktop/src/main/window-state.ts Adds safe URL access helpers that guard isDestroyed() and catch Electron “destroyed” exceptions.
packages/desktop/src/main/unresponsive.ts Uses safeWindowURL(win) in the unresponsive sampler output to avoid lifecycle-race crashes while logging.
packages/desktop/src/main/index.ts Uses safeWebContentsURL(webContents) in app-level render-process-gone logging to avoid destroyed WebContents URL access.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Hona
Hona merged commit 4436678 into anomalyco:dev Jul 17, 2026
10 checks passed
avion23 pushed a commit to avion23/opencode that referenced this pull request Jul 17, 2026
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.

2 participants