Repository navigation
fix(main): stop unhandled rejections from silently killing the app during startup restore - #9970
Conversation
… app (#9441) Main had no unhandledRejection handler — Node's default killed the process with a clean exit code and no macOS crash report, which is exactly the silent startup-restore exit in #9441. Rejections now record a durable crash breadcrumb (flushed to the trace sink) and the app stays alive; uncaught exceptions still terminate but record the same breadcrumb first so field exits stop being undiagnosable.
|
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⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded bounded, failure-safe diagnostics for fatal main-process errors, durable crash breadcrumb recording, and console logging. Added uncaught-exception and unhandled-rejection guards, wired unhandled-rejection logging into startup, removed the previous guard implementation from 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a99608f3-dbcd-445b-9a2c-9dd32c8d4995
📒 Files selected for processing (5)
src/main/index.tssrc/main/startup/configure-process-pipe-error-guard.test.tssrc/main/startup/configure-process.tssrc/main/startup/main-process-error-guards.test.tssrc/main/startup/main-process-error-guards.ts
💤 Files with no reviewable changes (2)
- src/main/startup/configure-process-pipe-error-guard.test.ts
- src/main/startup/configure-process.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/index.ts
… main One broken resource can reject hundreds of concurrent restore chains, and each durable record does a synchronous trace flush. Cap records at 20 per 60s window and carry the suppressed count into the next recorded event.
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: 0096186b-6845-4a62-bc4f-c46557106918
📒 Files selected for processing (2)
src/main/startup/main-process-error-guards.test.tssrc/main/startup/main-process-error-guards.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/startup/main-process-error-guards.test.ts
A rejection storm that exhausted the 60s record window would suppress the one main_uncaught_exception record taken right before the re-throw kills the process, recreating the undiagnosable death from issue #9441. Scope the fixed window to main_unhandled_rejection only; the uncaught path records at most once per install (handler removes itself, EPIPE/EIO never record), so it cannot storm.
…ring startup restore (stablyai#9970) * fix(main): log unhandled rejections durably and stop them killing the app (stablyai#9441) Main had no unhandledRejection handler — Node's default killed the process with a clean exit code and no macOS crash report, which is exactly the silent startup-restore exit in stablyai#9441. Rejections now record a durable crash breadcrumb (flushed to the trace sink) and the app stays alive; uncaught exceptions still terminate but record the same breadcrumb first so field exits stop being undiagnosable. * fix(main): harden process error guard diagnostics * fix(main): cap fatal-error records to stop a rejection storm stalling main One broken resource can reject hundreds of concurrent restore chains, and each durable record does a synchronous trace flush. Cap records at 20 per 60s window and carry the suppressed count into the next recorded event. * fix(main): never rate-limit the fatal uncaught-exception breadcrumb A rejection storm that exhausted the 60s record window would suppress the one main_uncaught_exception record taken right before the re-throw kills the process, recreating the undiagnosable death from issue stablyai#9441. Scope the fixed window to main_unhandled_rejection only; the uncaught path records at most once per install (handler removes itself, EPIPE/EIO never record), so it cannot storm. * fix(main): reset fatal-error window on backward clock jumps
Fixes #9441
The silent-exit mechanism
The main process had no
unhandledRejectionhandler, and the onlyuncaughtExceptionguard re-throws everything except EPIPE/EIO. Node's default response to an unhandled rejection terminates the process with a clean exit code — no macOS crash report, and stderr is invisible for Finder launches. During a large-profile startup restore (326 worktrees / 58 terminal histories in the report), main runs hundreds of concurrent async chains; a single failure in any of them exited the app exactly as described in #9441: runtime reaches ready, CPU spikes during restore, process vanishes ~15s in with nothing in the logs.The fix
unhandledRejection: record a durable crash breadcrumb (flushed synchronously to the trace sink) and keep the app alive — one failed background task should never take down the whole desktop app.uncaughtException: unchanged die-on-error semantics, but the error is now durably recorded before the re-throw, so any future field exit names its cause inlogs/main.trace.ndjsoninstead of being undiagnosable.Companion to #9446, which removes the startup-restore load that made these failures likely (full worktree scan deferred off the critical path).
Validation
ORCA_STARTUP_DIAGNOSTICS=1): startup unchanged (~1.5s hydration), zero guard breadcrumbs on a healthy boot.