Repository navigation
fix(desktop): a quit can no longer hang on a fatal main-process error - #10396
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
[Medium impact] The changes affect desktop shutdown and window cleanup. The remaining macOS window race and the shared-helper requirement should be addressed before merging. FindingsSummaryThe PR changes fatal-error recovery during quit and removes visibility listeners from closed windows.
Reviews (3) · Last reviewed commit: "fix(desktop): only a committed quit skip..." · Reviewed by Greptile |
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
| win.once('closed', () => { | ||
| for (const event of VISIBILITY_EVENTS) win.removeAllListeners(event) | ||
| }) |
There was a problem hiding this comment.
Late window events still throw
detachVisibilityListenersOnClose leaves Electron's listener active until closed. The PR description reports that some late show events arrive after destruction but before closed. In that order, visibilityChanged still calls isVisible() on a destroyed window and raises a fatal error during quit.
Guard the listener with isDestroyed() before it runs, and cover that event order in the test.
| async function settlePrompt() { | ||
| for (let turn = 0; turn < 5; turn++) await Promise.resolve() | ||
| } |
There was a problem hiding this comment.
Shared test helper is duplicated
settlePrompt() redefines the existing flushMicrotasks() helper. The testing guide requires using shared helpers instead of redefining them. Replace this function with flushMicrotasks(5) from @sim/testing/helpers/async, adding the workspace dependency if needed.
This repository requirement must be satisfied before merging.
Context Used: CLAUDE.md (source)
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!
Summary
Two bugs, surfaced by the desktop E2E harness's bounded quit ("Electron did not quit within 15s") on
terminal-cancel.spec.ts, whose stall diagnostics showed amain_uncaught_exception, a failed load of the bundled dialog page, and the main thread parked in-[NSAlert runModal].1. A fatal error during a quit hung the app forever. The fatal handler opened the "Sim encountered a problem" prompt even during shutdown. The bundled dialog page cannot load then (
ERR_FAILEDonsim-shell://pages/dialog.html), so it fell back to a parentlessdialog.showMessageBox, which on macOS is a synchronous app-modalNSAlertthat nothing answers.will-quit) now records the event and exits without prompting.before-quit) while the prompt is open answers it as Quit through the prompt'ssignal. Abefore-quitthat another listener cancels (account teardown guard) leaves later failures their Restart prompt.2. The exception itself. A CI experiment (draft #10394) that traced the error and window events over ~1,400 launches found it:
TypeError: Object has been destroyed at BrowserWindow.visibilityChanged. When the app quits just as its first window appears, macOS delivers the window'sshow(an occlusion change) after the window has closed and been destroyed; Electron's own per-windowvisibilityChangedlistener then callsisVisible()on the dead window. Every hit followedbefore-quit→will-quit→quit, with theshowarriving after the window was destroyed. The fix wraps Electron's visibility listener (show,hide,minimize,maximize,restore) on every BrowserWindow, frombrowser-window-created(emitted right after Electron subscribes it), so it is skipped once the window is destroyed. A first version that only dropped the listeners onclosedcut the rate from 7/960 to 2/960: some lateshows arrive after the window is destroyed but before itsclosedruns.Type of Change
Testing
observability.test.ts: a failure afterwill-quitexits without prompting; a failure after a cancelledbefore-quitstill prompts; a quit request while the prompt is open answers it as Quit. Each fails with its guard reverted.window.test.ts: on an Electron-wired window, visibility is still tracked while it lives, and ashowdelivered after it is destroyed no longer throws (fails with theisDestroyedguard reverted).type-check, biome.showstill threw in 2/480 then 7/960 relaunch-and-quit loops, and every quit completed. With the close-time listener removal: 2/960. The rerun with the destroyed-window guard is in that PR.Checklist
🤖 Generated with Claude Code