Skip to content

fix(renderer): raise renderer V8 heap toward the 4GB pointer-compression cage - #7531

Merged
nwparker merged 2 commits into
mainfrom
nwparker/fix-renderer-heap-headroom
Jul 6, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/fix-renderer-heap-headroom

Conversation

@nwparker

@nwparker nwparker commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • usedHeapMB == totalHeapMB == heapLimitMB in the reports (heap pegged at the ceiling for minutes).
  • Exit codes decode to OOM on every platform: macOS 5, Windows -536870904 = 0xE0000008 (Chromium's Windows OOM code), Linux 133 = 128+5 SIGTRAP (V8 FatalProcessOutOfMemory).
  • The heap climbs ~30–45 MB/min while agents are active and never reclaims. Not git (0.1–0.4 exec/s), not browser webviews (usually 0).

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 (no js-flags / --max-old-space-size anywhere 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 in index.ts) reclaims that unused headroom via --max-old-space-size, gated on physical RAM: ≥ 8 GB machines get clamp(⌊0.4 × RAM_GiB⌋ GB, 3072, 4096) MB; < 8 GB machines keep the default. Overridable with ORCA_RENDERER_HEAP_MB (a number to force, default/off/0 to 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 (the performance.memory value in the crash reports is quantized and does not reflect the real limit).

1. The main-process js-flags switch really reaches the renderer V8:

app.commandLine.appendSwitch('js-flags', …) typeof globalThis.gc in the renderer
(nothing) undefined
--expose-gc function

2. --max-old-space-size is honored by the renderer, capped at the ~4 GB pointer-compression cage:

requested (MB) renderer real heap_size_limit (MB)
default (this 128 GB box) 4096
512 608
2048 2144
3072 (fix value, 8–11 GB machines) 3168
4096 (fix value, ≥12 GB machines) 4096
5000 4096 (capped by the cage)
12288 4096 (capped by the cage)

So on an 8 GB machine (Chromium default ≈ 2.2 GB, confirmed by the heapLimitMB: 2222 reports) 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 GB gate, 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

  • Bounded by the 4 GB pointer-compression cage — this is a mitigation, not a cure. The renderer physically cannot exceed ~4 GB. Users whose working set genuinely needs > 4 GB (very heavy sessions) can still OOM. The only remedy for them is reducing the renderer working set (lower default scrollback / evict scrollback for terminals in non-visible worktrees / virtualize the largest lists) — flagged as follow-ups, not in this PR.
  • No benefit for 16 GB+ machines whose Chromium default is already ≈ 4 GB (the cage): the fix is a harmless no-op there. It provably helps the 8–15 GB machines whose default sits below the cage.
  • More RAM used before a crash, on 8–15 GB machines. A heavy renderer can now grow to ~3–4 GB instead of crashing at ~2.2 GB. This only bites under load the user was already crashing under. < 8 GB machines are deliberately left on the default so we don't push a memory-constrained box into swap / an OS-level kill.
  • No change for light users. V8 only grows to the ceiling under real pressure, so setting a higher max doesn't pre-allocate anything.
  • Process-wide flag. js-flags also 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)

  • 2 macOS/Linux 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.
  • 1 macOS 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).
  • 16 Windows reports were gathered verbatim into windows-crashes-07-05-2026/ (with an index) to be exercised on a real Windows machine.

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

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1aeb308d-d902-4bae-b81c-e78a7bec84b7

📥 Commits

Reviewing files that changed from the base of the PR and between ef0cad9 and 23e73b1.

📒 Files selected for processing (2)
  • src/main/startup/renderer-heap-headroom.test.ts
  • src/main/startup/renderer-heap-headroom.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/startup/renderer-heap-headroom.ts
  • src/main/startup/renderer-heap-headroom.test.ts

📝 Walkthrough

Walkthrough

This change adds a renderer heap headroom module that computes an optional V8 heap ceiling from total system memory and ORCA_RENDERER_HEAP_MB, applies it through Electron app.commandLine js-flags, and skips changes when a ceiling is not computed or an explicit --max-old-space-size already exists. The main process now calls this initializer during early startup before GPU fallback and headless display setup. New tests cover ceiling calculation, override parsing, and command-line flag merging behavior.

Changes

Area Description
Startup logic New renderer heap headroom initialization and js-flags update path
Main entrypoint Imports and invokes the new initializer during early startup
Tests New unit coverage for ceiling computation and flag behavior

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>")
Loading

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is informative but does not follow the required template and omits Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. Rewrite it using the repository template and add each required section, including screenshots status, testing checklist, AI review, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: raising the renderer V8 heap ceiling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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

🧹 Nitpick comments (1)
src/main/startup/renderer-heap-headroom.ts (1)

16-20: 🩺 Stability & Availability | 🔵 Trivial

8 GiB gate depends on exact os.totalmem() reporting.

The RAM tier gate assumes totalmem() reports at least 8 * 1024^3 bytes 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

📥 Commits

Reviewing files that changed from the base of the PR and between 88640ef and ef0cad9.

📒 Files selected for processing (3)
  • src/main/index.ts
  • src/main/startup/renderer-heap-headroom.test.ts
  • src/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]>
@nwparker

nwparker commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Addressed both CodeRabbit comments in 23e73b1:

  1. Fractional override → --max-old-space-size=0 (major): floored-to-0 overrides now opt out instead of emitting an invalid ceiling. Regression test added.
  2. 8 GiB gate vs os.totalmem() (nitpick — actually valuable): lowered the gate from 8 → 7.5 GiB. os.totalmem() on Linux reports MemTotal, which excludes kernel/firmware-reserved RAM, so a real 8 GB box reports ~7.7 GiB and was being wrongly excluded — that's exactly the crashing population (the Linux OOM report sat at the 2222 MB = ~8 GB-machine limit). 7.5 still cleanly excludes 6 GB machines (~5.7 GiB). Test added for the 7.5–7.7 GiB band.

@nwparker
nwparker merged commit b41cab1 into main Jul 6, 2026
1 check passed
Jinwoo-H added a commit that referenced this pull request Jul 6, 2026
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]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
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