orca icon indicating copy to clipboard operation
orca copied to clipboard

Improve renderer crash recovery

Open brennanb2025 opened this issue 5 months ago • 5 comments

Summary

This PR reduces several renderer crash classes seen in recent crash triage:

  • Prevents recovered/partial worktree metadata from crashing sidebar rendering when displayName or branch is missing, blank, or whitespace-only.
  • Strengthens lazy chunk recovery: retry, then one guarded renderer reload, then one guarded app restart only after a post-reload chunk-like failure.
  • Restores legacy dynamic-import failure coverage for ChunkLoadError names and Chromium failed to load module script errors so the new classifier does not narrow recovery.
  • Adds critical renderer heap-pressure recovery before likely hard process loss.
  • Explains guarded reload/restart recovery with a one-shot localized toast using calmer recovered/restored workspace copy so users are not left with a mysterious app refresh.

Why this should reduce future crashes

The design targets repeatable failure classes rather than only one report. The sidebar crash came from trusting persisted/recovered metadata as fully shaped UI strings. The lazy-boundary crashes are consistent with stale, corrupt, truncated, or failed dynamic chunks, where React.lazy caches the rejection and a local retry cannot recover. The heap reports included sustained V8 heap saturation before renderer death; this PR turns that state into one controlled renderer reload with diagnostics.

The recovery paths are intentionally loop-safe: renderer reloads are session-guarded, app restart is version-guarded, restart eligibility requires proof that a renderer reload already completed, and storage/version failures fail closed to the existing error boundary. That means the app should recover from known future instances of the same failure shapes without converting them into restart storms.

The new toast is not a separate recovery mechanism; it is the user-facing explanation for the guarded recovery that already happened. Recovery markers are written immediately before the controlled reload/restart, are consumed once after boot, expire after a short TTL, and prefer the newest marker so an old durable restart marker cannot mislabel a later refresh.

Design And Review Outcome

The design review tightened several safety requirements that are implemented here:

  • App restart can only follow a positively observed prior renderer reload, not unreadable storage or a same-renderer reload request.
  • Missing app version fails closed for restart eligibility.
  • Durable restart guard is only written after restart is accepted.
  • Lazy recovery breadcrumbs are sanitized and do not include raw import URLs, query strings, local paths, or error text.
  • Startup heap sampling can count as the first critical heap-pressure sample.
  • Recovery notifications must be best-effort, consume-once, localized, and unable to block crash recovery.

Completeness, performance, and code-review passes checked whether the branch should reduce future crash volume rather than only mask one report. Reviews found and drove fixes for storage-write failure loops, localStorage restart guard failures, concurrent restart coalescing, legacy card title gaps, syntax/fetch classification boundaries, the same-renderer reload race, stale durable recovery markers, untranslated recovery strings, and the i18n startup race before showing the one-shot toast. A later external review caught that the extracted classifier had dropped two known dynamic-import signatures from origin/main; this PR restores both with tests.

Implementation Notes

  • lazy-with-retry now records classified breadcrumbs, prefers the preload reload bridge, coalesces concurrent app restarts, and uses a renderer boot token to distinguish “reload requested” from “this renderer has already reloaded and failed again.”
  • lazy-chunk-error-classification keeps chunk-like error detection focused and sanitized without putting extra parsing work on the successful import path, including ChunkLoadError names and failed to load module script messages.
  • crash-diagnostics reuses the existing minute memory sampler and adds constant-time critical heap detection with a session guard.
  • Worktree card title display now normalizes partial recovered metadata and falls back to linked work or branch identity instead of throwing or rendering blank rows.
  • renderer-recovery-notification stores short-lived, versioned recovery markers in session/local storage and treats notification state as best-effort so it never blocks the actual recovery path.
  • App consumes the marker after persisted settings and i18n language are ready, then shows an 8-second info toast with recovered/restored workspace copy and “you can keep working” reassurance.

Performance

The hot path remains unchanged for successful lazy imports. New lazy recovery work only runs after failed dynamic imports. Memory-pressure logic piggybacks on the existing renderer memory interval and does bounded arithmetic plus guarded storage only when samples are critical. Recovery toasts add one mount-time/settings-ready marker check and storage cleanup after boot. No new polling, subprocess churn, store subscriptions, or long-lived buffers were added.

Validation

  • [x] pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/error-boundaries/RecoverableRenderErrorBoundary.lazy-chunk.test.tsx src/renderer/src/components/sidebar/WorktreeCard.compact-hover.test.tsx src/renderer/src/components/sidebar/worktree-card-title-display.test.ts src/renderer/src/lib/renderer-recovery-notification.test.ts src/renderer/src/lib/lazy-with-retry.test.ts src/renderer/src/lib/crash-diagnostics.test.ts - 6 files, 82 tests
  • [x] pnpm run typecheck
  • [x] pnpm run lint
  • [x] git diff --check
  • [x] VITE_EXPOSE_STORE=true npx electron-vite build --mode e2e
  • [x] SKIP_BUILD=1 npx playwright test tests/e2e/renderer-recovery-toast.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1 - validates no toast on normal boot, consume-once memory reload toast, restart-over-reload marker precedence, marker cleanup, and persisted Spanish UI language toast copy
  • [x] Electron launched from this branch/worktree; identity verified as brennanb2025/crash-triage rooted at /Users/thebr/orca/workspaces/orca/sprat.
  • [x] Demo target only: /Users/thebr/orca/workspaces/demo-project/Coral in a temporary app profile.
  • [x] UI validation: persisted whitespace displayName: " "; sidebar rendered fallback title Branch brennanb2025/Coral.
  • [x] Renderer console/app logs inspected; no relevant errors found.
  • [x] Cleanup complete: Electron stopped, debug ports closed, temporary profile/config removed.

Screenshot evidence captured locally: .playwright-cli/worktree-title-fallback-2026-06-24.png.

Crash-recovery manual gap: I did not manually corrupt lazy chunks or force heap-pressure reloads in Electron because those are destructive non-interactive recovery paths. Unit and e2e tests cover guarded reload/restart, sanitized breadcrumbs, restart coalescing, fail-closed storage behavior, same-renderer reload races, stale marker TTL/precedence, one-shot recovery toasts, persisted-language toast localization, critical heap-pressure reload guards, ChunkLoadError name classification, and Chromium module-script load failures.

Review Evidence

  • Design review completed with safety requirements incorporated.
  • Completeness verification passed after fixes.
  • Performance audit passed after concurrent restart coalescing was added; the later toast patch was also reviewed for boot/render/storage overhead.
  • Multiple independent code-review rounds were run. The latest rounds found stale marker precedence, locale catalog, and i18n startup timing issues; all were fixed and the final reviewers returned clean.
  • Merge-confidence validation returned land after focused tests, static checks, and Electron validation.
  • CodeRabbit's actionable classifier-comment item is already addressed by rationale comments around syntax, fetch, and name-fallback heuristics; a fresh incremental review was requested after the final copy-only commit.

Post-PR Stabilization

Automated stabilization is complete after commit 345e440c8: GitHub verify passed and the PR merge state is clean. The remaining docstring-coverage and description-template warnings are non-blocking bot warnings, not PR check failures.

Assumptions And Residual Risk

  • Some Windows killed or GPU/native process-loss reports may remain outside these renderer JS recovery paths.
  • Heap-pressure reload is intentionally blunt and may interrupt active UI work, but only after two critical samples near the V8 heap limit.
  • The recovery toast explains a guarded refresh/restart after it happens; it does not make the app refresh more often.
  • The app-generation/coherency problem behind stale chunks deserves a deeper updater lifecycle follow-up; this PR adds guarded recovery at the failure point.

Made with Orca

brennanb2025 avatar Jun 24 '26 19:06 brennanb2025

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
📝 Walkthrough

Walkthrough

The PR updates WorktreeCard title handling to normalize stored display names and recover linked review titles. It adds renderer crash diagnostics for sustained heap pressure with guarded reloads, expands lazy retry recovery to record structured breadcrumbs, reload the renderer, and restart the app under guarded conditions, and adds renderer recovery notification storage plus localized toast display. The related tests add coverage for title fallback cases, heap-pressure recovery behavior, notification display, and reload/restart guard handling.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is detailed, but it misses required template sections for Screenshots, AI Review Report, Security Audit, and Notes. Add the missing template sections, include screenshots or state no visual change, and summarize review/security findings with explicit macOS/Linux/Windows compatibility coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title succinctly matches the main change: broader renderer crash recovery.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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[bot] avatar Jun 24 '26 19:06 coderabbitai[bot]

@coderabbitai review

brennanb2025 avatar Jun 24 '26 20:06 brennanb2025

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Jun 24 '26 20:06 coderabbitai[bot]

@coderabbitai review

brennanb2025 avatar Jun 24 '26 23:06 brennanb2025

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Jun 24 '26 23:06 coderabbitai[bot]