Skip to content

fix(main): stop unhandled rejections from silently killing the app during startup restore - #9970

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/fix-9441-unhandled-rejection-guard
Jul 24, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/fix-9441-unhandled-rejection-guard

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Fixes #9441

The silent-exit mechanism

The main process had no unhandledRejection handler, and the only uncaughtException guard 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 in logs/main.trace.ndjson instead 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

  • Unit tests: rejection listener records the breadcrumb and never throws; EPIPE/EIO stay silently swallowed; the recorder survives a failing breadcrumb sink.
  • Live boot (synthetic 40-repo / 360-worktree profile, ORCA_STARTUP_DIAGNOSTICS=1): startup unchanged (~1.5s hydration), zero guard breadcrumbs on a healthy boot.

… 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.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review 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: Pro Plus

Run ID: 8f7cedac-af15-469e-a13a-47475a58d2ff

📥 Commits

Reviewing files that changed from the base of the PR and between 5f79219 and 39e8d09.

📒 Files selected for processing (2)
  • src/main/startup/main-process-error-guards.test.ts
  • src/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.ts

📝 Walkthrough

Walkthrough

Added 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 configure-process.ts, and added tests covering diagnostics, truncation, hostile inputs, pipe errors, suppression, and asynchronous rethrows.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the bug, fix, and validation, but it misses most required template sections like Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. Add the missing template sections and complete the testing, review, security, and notes details required by the repository template.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: preventing unhandled rejections from silently killing the app during startup restore.
Linked Issues check ✅ Passed The changes address #9441 by adding durable unhandled-rejection logging and preserving existing fatal error handling while keeping the app alive during startup restore.
Out of Scope Changes check ✅ Passed The new error-guard refactor, breadcrumb durability, and test coverage all support the startup-restore crash fix and do not appear unrelated.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a99608f3-dbcd-445b-9a2c-9dd32c8d4995

📥 Commits

Reviewing files that changed from the base of the PR and between 7b87f3e and 2d7135e.

📒 Files selected for processing (5)
  • src/main/index.ts
  • src/main/startup/configure-process-pipe-error-guard.test.ts
  • src/main/startup/configure-process.ts
  • src/main/startup/main-process-error-guards.test.ts
  • src/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.

@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: 0096186b-6845-4a62-bc4f-c46557106918

📥 Commits

Reviewing files that changed from the base of the PR and between 2d7135e and 63c420a.

📒 Files selected for processing (2)
  • src/main/startup/main-process-error-guards.test.ts
  • src/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.
@brennanb2025
brennanb2025 merged commit 6eb70d8 into main Jul 24, 2026
3 of 4 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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
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]: macOS app exits during startup when restoring a persisted profile (v1.4.146)

1 participant