Repository navigation
fix(renderer): raise renderer V8 heap toward the 4GB pointer-compression cage - #7531
Conversation
…ion cage
Renderer OOM ('renderer crashed'/'oom', exit 5 / 0xE0000008 / SIGTRAP) is the
dominant crash in the crash channel: the renderer JS heap reaches Chromium's
default V8 old-space ceiling (~RAM/4) and V8 aborts. Two adversarial leak hunts
(13 agents across every renderer subsystem) found no unbounded GB-scale leak, so
this is a capacity ceiling, not a leak.
Chromium sizes the renderer heap at ~RAM/4, leaving 8-15GB machines well under
V8's ~4GB pointer-compression cage (an 8GB machine caps near 2.2GB). Reclaim that
unused headroom via --max-old-space-size in a focused startup module, gated on
physical RAM (>=8GB, ~40% of RAM, floor 3072MB, capped at the real 4096MB cage).
16GB+ machines are already at the cage so this is a no-op for them; low-RAM
machines keep the default to avoid trading a clean OOM for OS memory-pressure
kills.
Overridable with ORCA_RENDERER_HEAP_MB (number to force, default/off/0 to opt
out). Verified on Electron 42.3.3: the main-process js-flags switch propagates to
the renderer V8 and is honored up to the 4096MB cage (5000/12288 -> 4096).
Co-authored-by: Orca <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis change adds a renderer heap headroom module that computes an optional V8 heap ceiling from total system memory and Changes
Sequence Diagram(s)sequenceDiagram
participant MainIndex
participant renderer_heap_headroom
participant app_commandLine
MainIndex->>renderer_heap_headroom: enableRendererHeapHeadroom()
renderer_heap_headroom->>renderer_heap_headroom: computeRendererHeapCeilingMb(totalMemoryBytes, envOverride)
renderer_heap_headroom->>app_commandLine: appendSwitch("js-flags", "--max-old-space-size=<ceiling>")
Related Issues: None found in the provided context. Related PRs: None found in the provided context. Suggested labels: electron, main-process, performance Suggested reviewers: None specified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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
🧹 Nitpick comments (1)
src/main/startup/renderer-heap-headroom.ts (1)
16-20: 🩺 Stability & Availability | 🔵 Trivial8 GiB gate depends on exact
os.totalmem()reporting.The RAM tier gate assumes
totalmem()reports at least8 * 1024^3bytes for machines marketed as "8 GB." In practice, some hardware/OS combinations report slightly less than the nominal capacity (shared/reserved memory), which could exclude borderline 8 GB machines from the intended headroom increase. Worth confirming against real 8 GB hardware readings as part of the crash-triage validation, since the PR's stated target is 8–15 GB machines.Also applies to: 54-74
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: ce93b8f7-f1fa-4d0a-9b71-b2946bf3d4d6
📒 Files selected for processing (3)
src/main/index.tssrc/main/startup/renderer-heap-headroom.test.tssrc/main/startup/renderer-heap-headroom.ts
- parseRendererHeapOverrideMb: a fractional override in (0,1) floored to 0 and emitted an invalid --max-old-space-size=0; treat floored-to-0 as an opt-out. - Lower the RAM gate from 8 to 7.5 GiB: os.totalmem() on Linux reports MemTotal (excludes kernel/firmware-reserved RAM), so a real 8 GB box reports ~7.7 GiB and was wrongly excluded from the headroom — the exact crashing population. 7.5 still cleanly excludes 6 GB machines (report ~5.7 GiB). Co-authored-by: Orca <[email protected]>
|
Addressed both CodeRabbit comments in 23e73b1:
|
74 commits from main, including the STA-1278 ai-vault transcript perf work, terminal flicker fix (#7540), renderer V8 heap raise (#7531), scrollbar position preservation (#7472), and the per-delivery debug-snapshot allocation removal (#7541). Conflict resolutions (our structure, main's semantics): - agent-detection: kept the split-module barrel; grafted main's Gemini/Pi title-detection refinements (path-fragment false positives, legacy Pi synthetic titles) into agent-title-core, dropped the superseded PI_IDLE_PREFIX. - orca-runtime wait-blocked detection: kept the throttled scheduleWaitBlockedCheck (branch §1 optimization) and ported it to main's new cached TerminalTailWaitState API; main's per-chunk cached scan stays on the leaf mismatch path where it auto-merged. pty.tailWaitState is deliberately never populated on this branch (throttle owns the pty record), so the leaf mirror copy invalidates rather than shares — the fromTail exactness contract is never violated by stale state. - recordPtyRendererDeliveryPressure: took main's allocation-free peak update (#7541) and derived per-pty in-flight from this branch's cumulative sent/acked accounting instead of the removed rendererInFlightCharsByPty map. - rpc/methods/terminal detach: kept both sides — our flushAllAckPendingOutput and main's exitWaiterAbort release. - pty-connection: kept our single-policy handleCommandFinished (invariant) alongside main's new sampleVisiblePaneForegroundAgent (bodies were byte-identical where they overlapped). - e2e pressure scenarios: kept the Phase-4 hidden-gate contract assertions and the extracted pressure-script module; adopted main's MAX_WORST_KEY_LATENCY_UNDER_LOAD_MS budget. Also documents the renderer-pull delivery watchdog in the branch guide. Gates: typecheck clean; ipc/daemon/terminal-pane/pane-manager suites 4256 passed; both fuzz suites pass. Co-authored-by: Orca <[email protected]>
…ion cage (stablyai#7531) * fix(renderer): raise renderer V8 heap toward the 4GB pointer-compression cage Renderer OOM ('renderer crashed'/'oom', exit 5 / 0xE0000008 / SIGTRAP) is the dominant crash in the crash channel: the renderer JS heap reaches Chromium's default V8 old-space ceiling (~RAM/4) and V8 aborts. Two adversarial leak hunts (13 agents across every renderer subsystem) found no unbounded GB-scale leak, so this is a capacity ceiling, not a leak. Chromium sizes the renderer heap at ~RAM/4, leaving 8-15GB machines well under V8's ~4GB pointer-compression cage (an 8GB machine caps near 2.2GB). Reclaim that unused headroom via --max-old-space-size in a focused startup module, gated on physical RAM (>=8GB, ~40% of RAM, floor 3072MB, capped at the real 4096MB cage). 16GB+ machines are already at the cage so this is a no-op for them; low-RAM machines keep the default to avoid trading a clean OOM for OS memory-pressure kills. Overridable with ORCA_RENDERER_HEAP_MB (number to force, default/off/0 to opt out). Verified on Electron 42.3.3: the main-process js-flags switch propagates to the renderer V8 and is honored up to the 4096MB cage (5000/12288 -> 4096). Co-authored-by: Orca <[email protected]> * fix(renderer): address CodeRabbit — floor-to-0 override + Linux 8GB gate - parseRendererHeapOverrideMb: a fractional override in (0,1) floored to 0 and emitted an invalid --max-old-space-size=0; treat floored-to-0 as an opt-out. - Lower the RAM gate from 8 to 7.5 GiB: os.totalmem() on Linux reports MemTotal (excludes kernel/firmware-reserved RAM), so a real 8 GB box reports ~7.7 GiB and was wrongly excluded from the headroom — the exact crashing population. 7.5 still cleanly excludes 6 GB machines (report ~5.7 GiB). Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
Description
usedHeapMB == totalHeapMB == heapLimitMBin the reports (heap pegged at the ceiling for minutes).5, Windows-536870904=0xE0000008(Chromium's Windows OOM code), Linux133= 128+5 SIGTRAP (V8FatalProcessOutOfMemory).It is not a leak. Two adversarial leak-hunts (13 expert agents across every renderer subsystem — terminal buffers/scrollback, PTY streams, agent-state stores, source-control diff/status, PR/checks caches, runtime RPC, diagnostics, sidebar, DOM/listener leaks, React DOM growth, IPC subscriptions, undisposed xterm instances, orchestration logs) found zero unbounded GB-scale accumulators — everything is already capped (
withBoundedCacheEntry,hostedReviewCache→500,AGENT_STATE_HISTORY_MAX, scrollback 5k/50k, hidden-output chunks, 256 KB automation output, …). The renderer is simply hitting a capacity ceiling.Root cause of the ceiling: Chromium sizes the renderer's V8 old-space heap at ~
RAM/4, and Orca never raises it (nojs-flags/--max-old-space-sizeanywhere in the codebase). So an 8 GB machine caps the renderer near ~2.2 GB — far below V8's ~4 GB pointer-compression cage — and heavy multi-agent sessions crash early.The fix (
src/main/startup/renderer-heap-headroom.ts, wired into early startup inindex.ts) reclaims that unused headroom via--max-old-space-size, gated on physical RAM:≥ 8 GBmachines getclamp(⌊0.4 × RAM_GiB⌋ GB, 3072, 4096)MB;< 8 GBmachines keep the default. Overridable withORCA_RENDERER_HEAP_MB(a number to force,default/off/0to opt out).CLEAR UNDENIABLE fix evidence
Measured on Electron 42.3.3 — the exact version every crashing user runs — with a minimal harness reading the renderer's real
v8.getHeapStatistics().heap_size_limit(theperformance.memoryvalue in the crash reports is quantized and does not reflect the real limit).1. The main-process
js-flagsswitch really reaches the renderer V8:app.commandLine.appendSwitch('js-flags', …)typeof globalThis.gcin the rendererundefined--expose-gcfunction2.
--max-old-space-sizeis honored by the renderer, capped at the ~4 GB pointer-compression cage:heap_size_limit(MB)So on an 8 GB machine (Chromium default ≈ 2.2 GB, confirmed by the
heapLimitMB: 2222reports) the fix lifts the renderer to ~3.2 GB — a ~40 % / ~1 GB larger ceiling before OOM.3. Unit tests (
renderer-heap-headroom.test.ts, 11 cases, all green) pin the RAM tiers, the 4096 cap, the env override/opt-out, the≥8 GBgate, the "never stack a second--max-old-space-size" guard, and the switch string. Typecheck + lint clean.A full triage of all 48 crashes (reproductions, exit-code decode, per-report heap analysis, both leak-hunt results) was produced during this investigation. It is intentionally not committed — it contains raw crash artifacts and reporter handles — and can be shared on request.
ELI5
Think of the renderer as a backpack. Chromium hands out backpack sizes based on how much RAM you have — and on smaller laptops it hands out a small backpack (~2 GB) even though the zipper could hold ~4 GB. When you run several agents for hours, the backpack fills up and rips (crash). This change asks for the biggest backpack the zipper allows (up to 4 GB) on machines that have the RAM to spare, so it fills up much less often. We can't make it bigger than ~4 GB — that's a hard limit of how the renderer packs its memory — so we grab all the room that's being left on the table.
Trade-offs / honest limitations
< 8 GBmachines are deliberately left on the default so we don't push a memory-constrained box into swap / an OS-level kill.js-flagsalso raises the main/utility V8 ceiling, but those processes stay small in practice; it does not force them to use more.Not fixed here (documented in the triage report, not app bugs)
killed(exit 9 / platform code) reports are OS memory-pressure kills of Electron's GPU/Network helpers while the renderer heap is tiny (18–61 MB) — Orca never SIGKILLs those helpers.react-error-boundary(useTabBarQuickCommands is not defined) is a contributor's dev-mode HMR artifact (orca_channel: dev,localhost:5173; the symbol doesn't exist in mainline).windows-crashes-07-05-2026/(with an index) to be exercised on a real Windows machine.