Skip to content

fix(crash-reporting): a fatal OOM crashes with a report instead of livelocking; name the worker and payload behind it - #43327

Merged
brennanb2025 merged 19 commits into
mainfrom
brennanb2025/worker-oom-crash
Nov 17, 2026
Merged

brennanb2025 merged 19 commits into
mainfrom
brennanb2025/worker-oom-crash

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Two failures on team machines today, both out-of-memory in Orca's main process:

  • Crash: Orca quit with a background worker running out of memory. That worker (the profile-state writer, by spawn order) held only ~60 MB. In Electron 43 the main thread and every worker share one ~3.25 GB V8 heap region, measured: with main holding 2.5 GB, a worker dies at 752 MB of its own heap and Node aborts the whole app. So the worker that dies is often a bystander, and nothing recorded which isolate filled the memory.
  • Hang at ~95% CPU, never recovering: the main thread ran out of memory while receiving a worker message. Chromium's out-of-memory path executes a trap instruction (brk #0, confirmed by disassembly) to crash with a report. proper-lockfile loads signal-exit, which adds JS listeners for SIGTRAP and SIGABRT. Those listeners make libuv's C handler catch the trap and return, so the trap re-fires forever. The listener itself can never run, because the thread never returns to the event loop.

Tracked in #42783 (the tab flood that put these profiles at ~10k tabs).

User-facing change

  • A fatal out-of-memory now crashes and writes a crash report instead of freezing Orca at full CPU until force-quit.
  • The next out-of-memory failure names its cause in diagnostics:
    • worker threads are named, so crash reports and samples show orca-journal-sql-reader instead of WorkerThread;
    • a breadcrumb names the isolates holding the memory and what each worker last sent.

How

  • fatal-signal-listener-guard.ts, installed first in Electron main, in orcad and in the backend utility process:

    • drops existing JS listeners on fault signals (SIGTRAP, SIGABRT, SIGIOT, SIGSYS, SIGILL, SIGBUS, SIGFPE, SIGSEGV);
    • refuses new ones synchronously (on, addListener, once, prependListener, prependOnceListener), so libuv never installs a handler for them;
    • leaves SIGINT, SIGTERM and SIGHUP listeners alone, so proper-lockfile's cleanup on normal exits still works.
  • Worker names: spawnWorkerThread now requires a role name (worker-thread-roles.ts), which Node uses as the thread name.

  • worker-send-ledger.ts:

    • a fixed shared-memory ledger (48 slots × 184 bytes) passed to workers through setEnvironmentData;
    • each worker entry calls installWorkerSendLedger(role), which records each post's kind, item count, approximate bytes, depth and the worker's heap before posting;
    • a full ledger stops recording;
    • the parent frees a slot when its worker exits, even if an owner stripped every listener (threadId === -1 sweep).
  • worker-message-shape.ts describes a payload within one budget (2,048 nodes, 16k keys and elements) and visits each object once. It reads own data properties only, never getters, so huge, wide, deep or cyclic payloads cost a bounded amount and the message itself is unchanged.

  • Large-send log: a send at or above 16 MB, 50k items or depth 100 is appended to logs/worker-large-sends.ndjson before posting, so the line survives the receiver aborting. A truncated walk needs only 4 MB or 10k items. The log is written only with local-file diagnostics consent, as one rotated file of at most 256 KB, by the worker-only worker-large-send-log.ts.

  • worker-thread-diagnostics.ts (main only):

    • samples committed heap for main and every worker every 60 s, or every 10 s once the total passes 1 GB;
    • each worker heap read times out after 2 s, and samples never overlap;
    • writes orca-isolate-heap (main committed heap split into old and large-object space, plus the total) and orca-worker-0..3 crash-report annotations each sample, so a crash that kills every isolate still says which one held the memory;
    • adds a worker_heap_pressure breadcrumb above 1.5 GB, at most every 10 min;
    • adds a worker_thread_failed breadcrumb on any worker error event, such as ERR_WORKER_OUT_OF_MEMORY.
  • Journal SQL reader reply limit (journal-sql-reader-reply-limit.ts):

    • What it does: a reply the bounded walk finds large is measured with v8.serialize; above 64 MB the reader sends a failed reply for that request instead of posting it to main.
    • Why 64 MB: decoding costs main 1.0–1.9× the serialized bytes, measured on journal rows (ASCII and two-byte), 400k small rows and chat records (decode-ratio.txt below). So one reply stays under ~120 MB of main heap, about 4% of the ~3.25 GB heap main shares with every worker. The reply that killed a team machine was a decoded whole-chat read: 647 MB of JSON, ~931 MB retained by main.
    • Exception: the record set (database/records) is never refused. It loads the chat store, so refusing it would leave every chat unopenable. It grows only with chat count, ~25 MB at 18k chats. Paging it is a follow-up.
    • Visits page by bytes: items-by-kind (the catch-up visit) was 256 rows with no byte budget, so 256 tool calls with 300 KiB outputs (~78 MB) would be refused. Its pages now end at 8 MiB of JSON (journal-items-by-kind-page.ts), reading rows lazily so rows past the budget are never loaded. A lone larger row still goes alone, and the visit keeps following nextOrdinal.
    • One stored item always goes: a point reply carrying a single stored item (item, item-detail, saved-content, submission-body, or an item list of at most one) is never refused. No page can split it, and main held it when it was written. Every other reply stays limited, including nested aggregates.
    • Cost: small replies are walked only. A page the walk cuts short is also serialized once on the reader worker (~0.3 ms for a full history page), never on main.
  • Hang watchdog: stores the four most recent worker sends with each heartbeat stall, so a main thread stuck receiving a message names its sender.

Not in this PR

  • Full containment: no resourceLimits setting can promise that one worker never aborts the app. With a 256 MB cap, a worker's large JSON.parse still aborted the whole process. That needs the heavy workers (chat SQL, usage scan, search) moved into utility processes, a design decision listed for follow-up.
  • Reconcile and tab-flood work stays with its own lane.

Verification

  • Tests:
    • fatal-signal-listener-guard.test.ts: fault-signal listeners added through any API are dropped and SIGTERM and SIGINT are kept. A real child process that loads the shipped proper-lockfile has no SIGTRAP listener in either load order and keeps its SIGTERM cleanup.
    • worker-send-ledger.test.ts: a real worker's post names its role, kind and item count, and the slot is freed on exit.
    • journal-sql-reader-reply-limit.test.ts: a 20k-row decoded read becomes a failed reply for its id, a 512-row page passes, rows past the bounded walk are still measured, a lone 9 MB item passes an 8 MB limit, and the record set is never refused.
    • journal-items-by-kind-page.test.ts: a visit page ends before the row that would pass the JSON budget, resumes after the last kept row, and still sends a lone oversized row.
    • worker-message-shape.test.ts: counts are right, getters are never read, and the walk stays bounded on wide self-referential, 100k-deep and 5M-item payloads.
  • Decode cost per serialized MB (plain Node, so pointers are uncompressed and these are upper bounds): 60k rows of 1 KB ASCII or two-byte text 1.16×; 400k 100-byte rows 1.81×; 4k 16 KB tool-call rows 1.01×; 18k chat records 1.92×.

QA

QA on the M4Air with dev builds of OLD (merge-base 33b133601ba) and NEW (7e5beb758c6), side by side. Each used a throwaway HOME seeded like the reporters' profiles: 18k records and 10.9k tabs, and 9.5k records and 1.8k tabs. Real config hashes were unchanged after the run.

Flow OLD NEW
Fatal OOM on main while it deserializes a worker message (main filled to 2.26 GB, then a worker posts a large two-byte string) Livelock: main at ~200% CPU for 11 min after the OOM, no dump, no report Crash in ~2 s: SIGTRAP, Crashpad dump plus macOS report. The main-thread stack is the reporter's exact path: worker message deserialize → V8 OOM → brk at the same offsets
process.listeners at startup (proper-lockfile loaded on both) SIGTRAP 1, SIGABRT 1, SIGTERM 2 SIGTRAP 0, SIGABRT 0, SIGTERM 2
Thread names (proc_pidinfo) 11 × WorkerThread 0 × WorkerThread. Present: orca-journal-sql-reader ×4, -writer, -checkpoint, orca-profile-state-writer, orca-environment-store, …
Seeded launch (10.9k tabs), 3 min main CPU mean 34.6%; 150 MB after forced GC main CPU mean 20.1%; 153 MB after forced GC
1.6 GB hold n/a worker_heap_pressure breadcrumb, totalHeapMB 1896
60 s main-thread block n/a main_thread_hang_detected on relaunch carries workerSend0..3_*
Crash annotations in the NEW dump n/a orca-isolate-heap and orca-worker-0..3 present
25 min live chat on the 1.8k-tab copy n/a main heapUsed 118–171 MB with no upward trend, so no snapshot diff was needed

Notes:

  • Annotation lag: orca-isolate-heap is the last sample, so it can lag a sudden fill by up to 60 s; it showed 162 MB 14 s before the synthetic crash. The sender is named by the ledger and the large-send log, which are written before the post.
  • Renderer crash loop (OLD and NEW alike): on the 10.9k-tab copy the renderer reaches its own ~4 GB heap limit and crashes about every 70 s. That is not touched here and belongs to the tab-flood work.
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​276 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​273
Prod 58 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1079 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1049

…ker behind it

A JS listener on SIGTRAP/SIGABRT (signal-exit, loaded by proper-lockfile) made
Chromium's fatal-OOM trap re-fire forever at full CPU instead of crashing.
Every worker thread now carries a role name, records what it posts to its parent
in a fixed shared-memory ledger, and main reports heap pressure across isolates,
so the next out-of-memory failure names the worker that caused it.
…vive crashes with sender evidence

Review fixes: the guard refuses SIGTRAP/SIGABRT listeners before libuv installs a handler and also
runs in orcad and the backend process; large sends are logged to disk before posting and the last
heap sample per isolate goes into crash annotations; slot release no longer races a new claim,
a full ledger evicts its stalest slot, and the payload walk never invokes accessors.
…unt as rows, worker-only large-send log

Second review pass: refuse/forward listeners through Reflect instead of casts; drop slot eviction
(a full ledger stops recording instead of racing a release); count big keyed objects toward the
large-send threshold; scale bytes when the walk is cut short; move the large-send append into a
worker-only module with an explicit sync-fs baseline line.
…udget; no byte extrapolation

Third review pass: a wide self-referential object re-enumerated its keys per visit; the walk
now uses a seen-set and a global key/element budget. Bytes stay a lower bound, and a truncated
walk counts as large from 4 MB or 10k items instead of an extrapolated estimate.
…f posting it to main

A decoded whole-chat read (647 MB of JSON, ~931 MB retained) posted from the journal SQL reader
exhausted the V8 heap main shares with every worker. Replies the bounded walk finds large are
measured and refused with a failure the caller already handles; paged reads never pay for it.
…st; never refuse the record set

Decoding costs main 1.0-1.9x the serialized bytes, so 256 MB could still cost ~490 MB of the
shared heap. 64 MB keeps one reply under ~120 MB. The record set loads the chat store and grows
only with chat count, so it is exempt rather than refused.
…IGTRAP listener in either load order and keeps SIGTERM cleanup
…; test the reply boundary

Review: rows past the 2,048-node walk could hide a 456 MB reply. A truncated walk now always
measures the serialized size (on the reader thread, never main). The reader posts every reply
through limitJournalReaderReply, which the test exercises directly.
…e of large tool outputs stays under the reader reply limit
@brennanb2025
brennanb2025 marked this pull request as ready for review November 17, 2026 00:43
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds named worker roles, shared send tracking, bounded message inspection, and worker heap diagnostics. Hang-watchdog observations can include recent worker-send details. Journal item pages and worker replies gain size limits. Startup paths install a fatal-signal listener guard. Tests cover the new message, ledger, guard, and journal behaviors.

Merge Risk: Low · up to 3ae06

This change makes fatal out-of-memory failures crash with a report instead of hanging, and it adds worker diagnostics and size limits on journal replies. The remaining risk is minor: sending a message with a very wide object can allocate a full key array during inspection. Other previously raised concerns are addressed.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Description check Inconclusive The description follows the template closely. It has Problem, User-facing change, How, Not in this PR, Verification, and QA sections, and it explains the mechanism and the risk-relevant boundaries. It… Add an ELI5 section in plain language. Link an actual issue with 'Fixes #NNN' or explain why none exists. Add before/after media for the behavior change, or write N/A with a reason. Set the Risk Level (Low, Medium, or High) and state how to…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: a fatal out-of-memory now produces a crash report instead of livelocking. It also names the second goal, naming the worker and payload behind the failure. It is long (…
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.
Full details: Title check

Explanation

The title names the main change: a fatal out-of-memory now produces a crash report instead of livelocking. It also names the second goal, naming the worker and payload behind the failure. It is long (117 characters) and uses a conventional commit prefix, but it matches the changeset and does not mislead.

Full details: Description check

Explanation

The description follows the template closely. It has Problem, User-facing change, How, Not in this PR, Verification, and QA sections, and it explains the mechanism and the risk-relevant boundaries. It is missing or incomplete in several template areas. The ELI5 section is absent. The Linked Issue section has no issue number; it cites #42783 as tracking only and leaves 'Fixes #' blank. Visual Proof has no before/after media, though the QA table partly covers behavior. The Testing checklist boxes are unticked. The Risk section has no Level value and no explicit revert instructions. The AI Disclosure and Agent skill upstream boundary sections are unfilled.

Resolution

Add an ELI5 section in plain language. Link an actual issue with 'Fixes #NNN' or explain why none exists. Add before/after media for the behavior change, or write N/A with a reason. Set the Risk Level (Low, Medium, or High) and state how to back out the change. Tick the testing checklist items that apply. Complete or mark the AI Disclosure and upstream-boundary sections.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 96b043bb-7e56-4722-b20a-db0ac5ef0a7a
Commits

Reviewing files that changed from the base of the PR and between 4b83fd3 and 3ae06af.

Files selected for processing: 6

  • src/main/crash-reporting/fatal-signal-listener-guard.test.ts
  • src/main/native-chat/agent-session-journal/journal-items-by-kind-page.ts
  • src/main/native-chat/agent-session-journal/journal-sql-item-reads.ts
  • src/main/worker-threads/worker-message-shape.test.ts
  • src/main/worker-threads/worker-message-shape.ts
  • src/main/worker-threads/worker-send-ledger.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@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: 10

Additional comments: 1

src/main/native-chat/agent-session-journal/journal-items-by-kind-page.ts-21-21: 1

21-21: Minor · Functional Correctness · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Count UTF-8 bytes for the JSON budget.

Two rows with two million CJK characters each pass this check, although their combined UTF-8 JSON exceeds 12 MB. Neither row needs the oversized-single-row exception.

Use Buffer.byteLength(json, 'utf8') for both the comparison and used. Node documents that byte length differs from string length. Add a multi-byte boundary test. (nodejs.org)

Based on learnings, str.length counts UTF-16 code units, not UTF-8 bytes.

Also applies to: 24-24

Source: Learnings

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d70554ca-0883-424a-af38-d6cb92496350
Commits

Reviewing files that changed from the base of the PR and between 4bb4a98 and 99efae1.

Files selected for processing: 65

  • config/main-sync-fs-baseline.txt
  • src/main/agent-hooks/identity/agent-identity-worker-client.ts
  • src/main/agent-hooks/identity/agent-identity-worker-entry.ts
  • src/main/agent-hooks/identity/pane-agent-identities.test.ts
  • src/main/ai-vault-search/worker/session-search-worker-client.ts
  • src/main/ai-vault-search/worker/session-search-worker-entry.ts
  • src/main/ai-vault-search/worker/session-search-worker.test-fixture.ts
  • src/main/ai-vault/scanners/opencode/reader-transport/session-scanner-opencode-sqlite-process-entry.ts
  • src/main/ai-vault/scanners/opencode/reader-transport/session-scanner-opencode-sqlite-worker-spawn.ts
  • src/main/backend/backend-entry.ts
  • src/main/claude-accounts/profiles/setup/claude-profile-setup-worker-entry.ts
  • src/main/claude-accounts/profiles/setup/claude-profile-setup-worker.ts
  • src/main/claude/transcripts/claude-conversation-fork-worker-entry.ts
  • src/main/claude/transcripts/claude-rewind-transcript.ts
  • src/main/crash-reporting/fatal-signal-listener-guard.test.ts
  • src/main/crash-reporting/fatal-signal-listener-guard.ts
  • src/main/foreign-sqlite-readers/foreign-sqlite-reader-entry.ts
  • src/main/foreign-sqlite-readers/foreign-sqlite-reader-spawn.ts
  • src/main/hang-watchdog/hang-observation-schema.ts
  • src/main/hang-watchdog/hang-observations.ts
  • src/main/hang-watchdog/hang-worker-sends.ts
  • src/main/hang-watchdog/main-thread-hang-capture.test.ts
  • src/main/hang-watchdog/main-thread-hang-import-failure.test.ts
  • src/main/hang-watchdog/main-thread-hang-watchdog-entry.ts
  • src/main/hang-watchdog/previous-hang-detection.ts
  • src/main/index.ts
  • src/main/ipc/command-path/command-path-directory-worker-client.ts
  • src/main/ipc/command-path/command-path-directory-worker-entry.ts
  • src/main/native-chat/agent-session-journal/database/journal-checkpoint-owner.ts
  • src/main/native-chat/agent-session-journal/journal-items-by-kind-page.test.ts
  • src/main/native-chat/agent-session-journal/journal-items-by-kind-page.ts
  • src/main/native-chat/agent-session-journal/journal-sql-item-reads.ts
  • src/main/native-chat/agent-session-journal/journal-sql-owner.ts
  • src/main/native-chat/agent-session-journal/journal-sql-reader-entry.ts
  • src/main/native-chat/agent-session-journal/journal-sql-reader-reply-limit.test.ts
  • src/main/native-chat/agent-session-journal/journal-sql-reader-reply-limit.ts
  • src/main/native-chat/agent-session-journal/journal-sql-reader-slot.ts
  • src/main/native-chat/agent-session-journal/journal-sql-worker-entry.ts
  • src/main/orcad/main.ts
  • src/main/persistence/profile-state/backup/profile-state-backup-worker-entry.ts
  • src/main/persistence/profile-state/backup/profile-state-backup-worker.ts
  • src/main/persistence/profile-state/writer/profile-state-writer-thread.ts
  • src/main/persistence/profile-state/writer/profile-state-writer-worker-entry.ts
  • src/main/plugins/panels/plugin-source-transpile-client.ts
  • src/main/plugins/panels/plugin-source-transpile-worker-entry.ts
  • src/main/ports/port-scan-command-client.ts
  • src/main/ports/port-scan-command-worker-entry.ts
  • src/main/usage/scan-worker/usage-scan-worker-entry.ts
  • src/main/usage/scan-worker/usage-scan-worker-spawn.ts
  • src/main/warp-themes/parser-runner.ts
  • src/main/warp-themes/warp-theme-parser-worker.ts
  • src/main/worker-thread-child-process/worker-thread-child-process-entry.ts
  • src/main/worker-thread-child-process/worker-thread-child-process.ts
  • src/main/worker-threads/worker-large-send-log.ts
  • src/main/worker-threads/worker-message-shape.test.ts
  • src/main/worker-threads/worker-message-shape.ts
  • src/main/worker-threads/worker-send-ledger.test.ts
  • src/main/worker-threads/worker-send-ledger.ts
  • src/main/worker-threads/worker-thread-diagnostics.ts
  • src/main/worker-threads/worker-thread-roles.ts
  • src/main/worker-threads/worker-thread-spawn.ts
  • src/main/workspaces/space-analysis/workspace-space-scan-worker-client.ts
  • src/main/workspaces/space-analysis/workspace-space-scan-worker-entry.ts
  • src/shared/remote-runtime/host-store/runtime-environment-store-worker-client.ts
  • src/shared/remote-runtime/host-store/runtime-environment-store-worker-entry.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status

Problem. Two team machines failed today, both because Orca's process ran out of memory.

  • The crash: a worker thread aborted because the ~3.25 GB V8 heap region that main and every worker share was full. The worker itself held ~60 MB; it was a bystander.
  • The hang: main itself ran out of memory while decoding a worker's message. Chromium's OOM trap then re-fired forever, because signal-exit (loaded through proper-lockfile) had JS listeners on SIGTRAP and SIGABRT. The result was ~95% CPU and no crash report.

User-facing change.

  • A fatal out-of-memory now crashes with a crash report instead of freezing Orca until force-quit.
  • Worker threads are named by role.
  • The next out-of-memory failure names the isolate holding the memory and what each worker last sent.
  • One journal reader reply can no longer exhaust main's heap: replies over 64 MB fail their request, and catch-up visits page by bytes.

Fixed during review (7 passes; each finding has a reproducer in the pass notes):

  • the ledger release race and slot leaks;
  • getters being invoked by the payload walk;
  • a re-walk of wide cyclic objects;
  • casts flagged by lint;
  • Reflect calls flagged by lint;
  • a reply-limit bypass via a truncated walk;
  • refusal of the record set;
  • refusal of 256-row visits with large tool output (now paged by bytes and read lazily);
  • refusal of a single stored item over the limit.

After the last review pass, the only changes are one merge with main and a config fix: the new worker-threads files are listed in tsconfig.tc.web.json, which CI's web typecheck needs.

Deferred, not blocking:

  • Paging the record set: exempt for now, ~25 MB at 18k chats.
  • Paging the continuation context.
  • A lone oversized history group, which is still limited.
  • The second shape walk per history page (~95 µs, on the reader worker).
  • The heap annotation can lag a sudden fill by up to 60 s.
  • Full containment: moving heavy workers into utility processes.
  • A pre-OOM capture.
  • The reconcile receipt's device-number comparison.

Verified:

  • Checks: remote check:changed passed all 37 checks on 4b83fd34e5 (after one merge with main), plus tc:web, and the named tests passed, including a subprocess test with the shipped proper-lockfile in both load orders.
  • QA on the M4Air, OLD (merge-base) against NEW, with test copies seeded like the reporters' profiles:
    • Forced main OOM while deserializing a worker message: OLD livelocked at ~200% CPU for 11 min with no report. NEW crashed in ~2 s with SIGTRAP and wrote a Crashpad dump plus a macOS report, and its stack is the reporter's exact path.
    • Startup listeners: SIGTRAP and SIGABRT go from 1 to 0; SIGTERM stays at 2.
    • Thread names: 0 threads are still named WorkerThread (OLD had 11).
    • Breadcrumbs: the 1.6 GB pressure breadcrumb fired, and the 60 s hang record names the worker senders.
    • 25 min live chat: main heap stayed between 118 and 171 MB with no growth.
  • Perf scan: about 1.5 µs fixed per worker post, on worker threads; the main sampler costs under 1 ms per minute. Nothing scales with chats or tabs on a repeated trigger.

Relaunch after a forced 60 s main-thread block, 10.9k-tab copy (NEW):
relaunch after hang

End of the 25 min live chat on the 1.8k-tab copy (NEW), still streaming:
25 min chat

Inherited and not touched here: on the 10.9k-tab copy the renderer reaches its own ~4 GB heap and crashes about every 70 s, on OLD and NEW alike. That belongs to the tab-flood work.

Tracked in #42783.

…the logged kind, page items-by-kind by key lookups, record the spawned thread name, skip SIGTRAP subprocess tests on Windows
@brennanb2025

brennanb2025 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Review status

Problem. Two team machines failed today, both because Orca's process ran out of memory.

  • The crash: a worker thread aborted because the ~3.25 GB V8 heap region that main and every worker share was full. The worker itself held ~60 MB; it was a bystander.
  • The hang: main itself ran out of memory while decoding a worker's message. Chromium's OOM trap then re-fired forever, because signal-exit (loaded through proper-lockfile) had JS listeners on SIGTRAP and SIGABRT. The result was ~95% CPU and no crash report.

User-facing change.

  • A fatal out-of-memory now crashes with a crash report instead of freezing Orca until force-quit.
  • Worker threads are named by role.
  • The next out-of-memory failure names the isolate holding the memory and what each worker last sent.
  • One journal reader reply can no longer exhaust main's heap: replies over 64 MB fail their request, and catch-up visits page by bytes.

Fixed during review (9 passes, each finding with a reproducer, plus 10 automated review threads, all answered and resolved):

  • the ledger release race and slot leaks;
  • getters being invoked by the payload walk;
  • a re-walk of wide cyclic objects;
  • casts flagged by lint;
  • Reflect calls flagged by lint;
  • a reply-limit bypass via a truncated walk;
  • refusal of the record set;
  • refusal of 256-row visits with large tool output (now paged by bytes and read lazily);
  • refusal of a single stored item over the limit;
  • from the automated threads:
    • Map/Set sizes and buffer lengths now read through built-in accessors, and Map keys are counted;
    • the logged message kind is capped;
    • catch-up pages are read by primary key, so the budget stops reads;
    • the spawned thread name is recorded;
    • the SIGTRAP subprocess tests are skipped on Windows.

Beyond review fixes, the branch has one merge with main and a config fix: the new worker-threads files are listed in tsconfig.tc.web.json, which CI's web typecheck needs.

Deferred, not blocking:

  • Paging the record set: exempt for now, ~25 MB at 18k chats.
  • Paging the continuation context.
  • A lone oversized history group, which is still limited.
  • The second shape walk per history page (~95 µs, on the reader worker).
  • The heap annotation can lag a sudden fill by up to 60 s.
  • Full containment: moving heavy workers into utility processes.
  • A pre-OOM capture.
  • The reconcile receipt's device-number comparison.

Verified:

  • Checks: remote check:changed passed all 37 checks on 3ae06af53b (after one merge with main), plus tc:web, and the named tests passed, including a subprocess test with the shipped proper-lockfile in both load orders.
  • QA on the M4Air, OLD (merge-base) against NEW, with test copies seeded like the reporters' profiles:
    • Forced main OOM while deserializing a worker message: OLD livelocked at ~200% CPU for 11 min with no report. NEW crashed in ~2 s with SIGTRAP and wrote a Crashpad dump plus a macOS report, and its stack is the reporter's exact path.
    • Startup listeners: SIGTRAP and SIGABRT go from 1 to 0; SIGTERM stays at 2.
    • Thread names: 0 threads are still named WorkerThread (OLD had 11).
    • Breadcrumbs: the 1.6 GB pressure breadcrumb fired, and the 60 s hang record names the worker senders.
    • 25 min live chat: main heap stayed between 118 and 171 MB with no growth.
  • QA on the final code (M4Air, 431c668; the head after it only moves two SQLite calls between files, reviewed as behavior-identical), with real native Claude (Sonnet 5.5) and Codex (GPT-6.1-Sol) chats:
    • each ran three tool calls, then went through a graceful relaunch;
    • both came back with identical items, order and tool outputs (5→5 and 8→8);
    • both answered a follow-up that needed earlier context ("2000"), and the turn completed;
    • there was no exceeds refusal, no worker_thread_failed, and no thread named WorkerThread.
  • Perf scan: about 1.5 µs fixed per worker post, on worker threads; the main sampler costs under 1 ms per minute. Nothing scales with chats or tabs on a repeated trigger.

Relaunch after a forced 60 s main-thread block, 10.9k-tab copy (NEW):
relaunch after hang

End of the 25 min live chat on the 1.8k-tab copy (NEW), still streaming:
25 min chat

Native Codex chat after relaunch, history intact (final code):
codex after relaunch

Native Claude chat after relaunch, history intact (final code):
claude after relaunch

Inherited and not touched here: on the 10.9k-tab copy the renderer reaches its own ~4 GB heap and crashes about every 70 s, on OLD and NEW alike. That belongs to the tab-flood work.

Tracked in #42783.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan (fresh reviewer, full perf-scan, head 3ae06af53b)

Verdict: clean. Nothing the PR adds grows with chats, tabs, rows or records on a repeated trigger, and no per-post work lands on Electron main. Timings come from microbenchmarks on Node 26.5 that ran the PR's real walker on synthetic shapes.

Work Trigger / thread Bound Price
Reader reply limit (publish, journal-sql-reader-entry.ts:35) each reader reply / reader worker walk 2048 nodes; serialize only when the walk is cut short or past 16 MB; one-item replies and the record set skipped 512-item history page +0.5 ms (vs 0.9 ms clone); 256-item visit page +0.3 ms; point read +1 µs; main unchanged
Per-post ledger walk every worker postMessage / sending worker 2048 nodes, 16k entries, fixed 48×184 B shared memory spawner stdout chunk +0.5–1.6 µs (about 3 ms/s at 3k chunks/s, 0 on main); worst walk ≤18% of the clone
Large-send append sends ≥16 MB (or cut short at 4 MB / 10k items) / worker only 256 KB plus one rotated file one stat plus one append
Heap sampler 60 s timer (10 s above 1 GB), unref'd / main about 20 live workers, 2 s timeout tens of µs per sample, under 1 ms/min
subscribe: worker error listener once per worker failure one per worker, released on exit one breadcrumb
worker: spawn wrapper each spawn sweep of about 20 entries constant
items-by-kind pages each catch-up page / reader worker 8 MiB per page, lookups stop at the budget +45–125 µs per 256-row page
Hang watchdog / listener guard stall only / each process.on 48 slots / one Set.has negligible

Deferred note: a page the walk cuts short is serialized once to measure it and again by postMessage. That costs about 0.2–0.7 ms per page on the reader worker and nothing on main. Posting the measured buffer as a transfer would remove it, which is a follow-up.

brennanb2025 added a commit that referenced this pull request Nov 17, 2026
…thread never stalls (#43550)

The hourly pass from #43322 deleted each settled Run, every message included,
in one synchronous step. On a real 1.7 GB orchestration.db that blocked the
main thread for up to 1.3 s per large Run (98 one-second windows over 100 ms
in the first pass).

Each Run is now retired in bounded steps, each its own transaction, with the
pass's rest between them: its coordinator panes are read 256 messages at a
time, then its rows are deleted one table page at a time (128 rows; 64
messages; 8 saved output copies; removed-work records too), and the Run row
goes last. The full settled check runs once first and again before the Run
row; each page checks only pane liveness (an in-memory lookup) and whether the
Run was touched (a newer updated_at or newer row, or reopened work: a pending
Task, Dispatch, gate or question, all indexed probes), so a reattached
coordinator, a new write or a gate opened mid-way stops the deletes before a
page removes the work the final check would have kept the Run for. A pass stopped by a quit or
crash leaves the Run with fewer settled rows for the next pass to finish.
Candidate pages now read only Run-level columns (the full check for 8 large
Runs took up to 197 ms cold), and the orphaned-output-copy sweep deletes at
most 8 per step.

The settled-Run check's moved-terminal clause used NOT IN over the Run's
Dispatches, which SQLite rebuilt per row: 133 ms per check for a Run with 675
Dispatches, 8.3 s to classify all 1,226 Runs. It is now NOT EXISTS on the
Dispatch id: 11 ms and 0.45 s, selecting the same Runs.

While a pass prunes, WAL checkpoints run on a worker thread's own connection
(PASSIVE, every 250 ms) and main's auto-checkpoint is off: a commit that
crossed the 1000-page threshold checkpointed and fsynced the 1.7 GB file on
main, which a CPU profile of the pass showed as every remaining stall (up to
934 ms on a busy disk). The worker failing or exiting hands checkpoints back
to main at once, and the pass restores the previous threshold when it ends.

(cherry picked from commit c5ea444)
Conflict: src/main/worker-threads/worker-thread-roles.ts (added by #43327, not on this branch) removed; this branch has no worker role list.

Also rewords the page-size doc comment in settled-run-retirement.ts.
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.

1 participant