Skip to content

feat(crash-reports): add byte attribution to renderer memory highwater breadcrumbs - #12198

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/investigate-slack-crash-report
Aug 3, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/investigate-slack-crash-report

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Renderer OOM crash reports currently name store slices by entry count only, which cannot attribute value-weight growth: crash 97b9e86d (1.4.164, renderer OOM at the 4.2GB heap limit) leaked ~700MB in a window where its largest slice grew by 4 entries, leaving the report unable to say what filled the heap.

renderer_memory_highwater breadcrumbs now carry byte attribution:

  • storeKB.* — sampled, extrapolated per-slice KB estimates for the top 16 store slices, plus storeKB.__totalKB so a report can exonerate the whole store at a glance. storeKB.__budgetHitSlices marks truncated estimates so a saturated scan cannot create false negative evidence. Live measurement on a 200-worktree session found a 1.3GB heap but only ~15MB of store state, redirecting investigation to non-store retainers.
  • terminals.managers / terminals.estPanes / terminals.estBufferKB — bounded live pane-manager sampling with extrapolated pane and xterm scrollback estimates. Mounted panes are the dominant highwater cost the store census cannot see (eviction-exempt panes stay mounted indefinitely; observed 32→51 managers over 2h in the field session that motivated this).

The estimator is built for its call site (≥60% heap pressure): no Object.keys on large collections, no stringify, a 4096-node budget per slice, at most 4096 root-record entries plus 1024 entries reserved for sampled-value descent, cycle guard, depth cap, and per-slice containment. Terminal profiling samples at most 64 managers and materializes at most 256 pane wrappers. Live-injected into a production renderer it censused the full store in 7.9ms; Electron QA on final HEAD measured five full profile collections at 0.6–5.4ms.

Screenshots

No visual product change. Electron QA evidence with one-pane and split-pane screenshots.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test — 43,540 passed; 23 failures in 9 files (src/main/ipc/pty.test.ts, relay/daemon PTY suites, check-root-directory-entries) are pre-existing on the base commit: verified by re-running the same files at parent 040734b18e in the same environment with identical failures. No failing file overlaps this diff.
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

14 estimator tests cover ranking, extrapolation, Map/Set/typed-array weighting, cycles, bounded nesting and flat-record scans, reserved fat-value descent, budget-hit signaling, raw-byte total accuracy, throwing-getter containment, and the top-limit/total contract. Three pane-census tests cover buffer estimation, contributor registration, and deterministic 64-manager/256-pane sampling limits. The extrapolation test was sabotage-verified: reintroducing the window-saturation bug it guards fails the suite.

AI Review Report

Reviewed for allocation behavior at near-OOM, extrapolation correctness, total accuracy, contributor budgets, breadcrumb growth, and HMR registration. A same-model review fixed two P2 issues: plain-object counting could scan an unbounded leaking record, and terminal profiling could materialize every retained pane precisely when that population was the suspected leak. A refreshed review also caught per-slice KB rounding that omitted sub-KB slices from __totalKB; totals now sum raw bytes and round once. All three fixes have deterministic regression tests, truncated store estimates emit __budgetHitSlices, and pane counts are explicitly estimated. The same reviewer iterated on final HEAD until returning clean.

Contributor-registry maximum is 41/64 keys: 20 store counts, up to 18 storeKB counts (16 slices, total, budget-hit marker), and three terminal counts. Payload values remain numeric and bounded. Same-name registration still overwrites safely during dev HMR.

Cross-platform: explicitly checked for macOS, Linux, and Windows concerns — this change is renderer-only pure TypeScript with no file paths, keyboard shortcuts, shell invocation, labels, or Electron platform-specific APIs; the only platform-adjacent surface is performance/heap reporting, which was already in place and is unchanged.

Security Audit

No new input handling, command execution, path handling, auth, secrets, or dependency surface. No IPC changes — the census rides the existing crash-breadcrumb recorder channel. Output contains only numbers keyed by code-level identifiers (store slice names, managers/estPanes/estBufferKB); no user data, file contents, or terminal contents are read into the payload — the estimator reads string lengths, never string values. Traversal of state is defensive: per-slice try/catch contains throwing getters/proxies, and the registry's existing contributor try/catch contains anything else.

Notes

  • Estimates are heuristic (sampled, first-window biased, shared references counted once per slice); only relative ranking between slices is meaningful. A __budgetHitSlices value means the aggregate is a bounded partial estimate and must not be used to exonerate the store.
  • Byte constants are rough V8 costs; changing them shifts absolute values but tests pin ranking, extrapolation, and budget behavior, so tuning is safe.
  • Follow-up (separate PRs): bound the eviction-exempt mounted-pane accumulation this census now measures, and fix three main-process exception bugs found during the same investigation (recurring SyntaxError in runWaitBlockedCheck, unhandled rejections in onPtyData pane-key handling, __orcaTerminalFreezeReport RPC failure).

…r breadcrumbs

Entry counts stay flat when a slice grows by value weight (97b9e86d leaked
~700MB while its biggest slice grew by 4 entries), so highwater breadcrumbs
now carry sampled per-slice KB estimates for the store plus a live pane
census (managers, panes, estimated scrollback KB) — the dominant heap cost
the store census cannot see.
@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Added a bounded estimator for renderer state collection sizes, including arrays, maps, sets, typed arrays, objects, cycles, and error cases. Registered the estimator as the storeKB memory-profile contributor. Added terminal pane profiling that counts live managers and panes and estimates active buffer memory. Added tests for both profiling contributors and estimator behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the primary change: adding byte attribution to renderer memory highwater breadcrumbs.
Description check ✅ Passed The description includes all required sections, testing results, review coverage, security audit, platform checks, and follow-up notes.
✨ Finishing Touches 💡 1
📝 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 Plus

Run ID: f693354b-3d77-4199-8f01-23dd864132f1

📥 Commits

Reviewing files that changed from the base of the PR and between 5887b36 and d1a906c.

📒 Files selected for processing (5)
  • src/renderer/src/lib/pane-manager/pane-manager-registry.test.ts
  • src/renderer/src/lib/pane-manager/pane-manager-registry.ts
  • src/renderer/src/lib/state-collection-byte-estimate.test.ts
  • src/renderer/src/lib/state-collection-byte-estimate.ts
  • src/renderer/src/store/index.ts

@greptile-apps

greptile-apps Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR adds byte-weight attribution to renderer_memory_highwater breadcrumbs to address a class of OOM crash reports (exemplified by 97b9e86d) where entry counts stayed flat while heap size ballooned — making store slice counts useless for triage. Two new data streams are added: a sampled/extrapolated per-slice KB census (storeKB.*) and a bounded pane-manager terminal census (terminals.*).

  • state-collection-byte-estimate.ts — a new bounded estimator that traverses each top-level store slice with per-slice node and entry budgets (4096 nodes, 4096 + 1024 entries), samples values at stride intervals, extrapolates, and emits __budgetHitSlices whenever truncation occurs so saturated totals cannot falsely exonerate the store.
  • pane-manager-registry.ts — a new getLivePaneMemoryProfileCounts that samples at most 64 managers and 256 pane wrappers, uses getPaneCount() for exact totals on unsampled managers, and extrapolates buffer KB from the sampled panes.
  • pane-manager.ts — getPanes() gains an optional limit parameter to enforce the 256-pane materialization cap without allocating a full array.

Confidence Score: 5/5

Safe to merge. All new code is renderer-only diagnostic logic that runs on the existing crash-breadcrumb path and outputs only bounded numeric counts; no IPC, auth, or data-exposure surface is touched.

The estimator and pane census are both tightly bounded: per-slice node/entry budgets cap worst-case work, cycle detection prevents infinite recursion, and budget-hit sentinels prevent a saturated scan from silently producing a misleading result. All edge cases are handled with explicit fallbacks and covered by tests. No correctness issues were found on the changed paths.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/lib/state-collection-byte-estimate.ts New sampled byte estimator with per-slice node/entry budgets, cycle detection, depth cap, and budget-hit sentinel. Entry scanning, array/Map/Set sampling, and plain-object key traversal are all individually bounded. Logic is sound and matches the test expectations.
src/renderer/src/lib/pane-manager/pane-manager-registry.ts Adds getLivePaneMemoryProfileCounts with 64-manager / 256-pane sampling caps. The double-extrapolation (managerScale for pane counts, paneScale for buffer bytes) is mathematically consistent and verified by the test suite.
src/renderer/src/lib/pane-manager/pane-manager.ts Minimal change: getPanes gains an optional limit parameter with Number.POSITIVE_INFINITY default, preserving all existing call sites while enabling bounded sampling from the registry.
src/renderer/src/lib/state-collection-byte-estimate.test.ts 13 tests covering ranking, extrapolation, Map/Set/typed-array handling, cycle safety, depth bounding, fat-value descent with saturated scan, budget-hit signaling, throwing-getter containment, and the total/top-limit contract.
src/renderer/src/lib/pane-manager/pane-manager-registry.test.ts Three new pane census tests verify buffer estimation math, sampling bound enforcement (64 managers / 256 panes), and contribution to the memory profile.
src/renderer/src/store/index.ts Registers a second contributor ('storeKB') backed by the new estimator alongside the existing count-based 'store' contributor. Minimal change with clear rationale.

Reviews (3): Last reviewed commit: "fix(crash-reports): total raw store esti..." | Re-trigger Greptile

@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: 15825bb0-64fc-4325-90e5-896ae545edf9

📥 Commits

Reviewing files that changed from the base of the PR and between d1a906c and f0e518c.

📒 Files selected for processing (5)
  • src/renderer/src/lib/pane-manager/pane-manager-registry.test.ts
  • src/renderer/src/lib/pane-manager/pane-manager-registry.ts
  • src/renderer/src/lib/pane-manager/pane-manager.ts
  • src/renderer/src/lib/state-collection-byte-estimate.test.ts
  • src/renderer/src/lib/state-collection-byte-estimate.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/lib/pane-manager/pane-manager-registry.test.ts
  • src/renderer/src/lib/pane-manager/pane-manager-registry.ts

@brennanb2025

brennanb2025 commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Electron QA evidence

Validated the intended sandlance @ brennanb2025/investigate-slack-crash-report dev instance with an isolated profile and separate renderer/CDP ports.

  • Final HEAD 0afc053f52: a real terminal accepted input and stayed responsive. Five full profile collections took 0.6–5.4 ms, used 40/64 keys, reported terminals.managers=1, terminals.estPanes=1, terminals.estBufferKB=122, storeKB.__totalKB=1590, and no budget saturation.
  • Final raw-total behavior was exercised in the live renderer: three individually sub-KB slices returned { __totalKB: 1 }.
  • Pane-sampling commit f0e518c785 (direct ancestor of final HEAD): Split Terminal Right created two responsive panes and the live profile changed from estPanes=1 to estPanes=2.
  • A repeat split on final HEAD was attempted, but the host-wide PTY pool was exhausted; Orca correctly showed “cannot allocate any more pty devices.” I did not terminate unrelated sessions. The pane code is unchanged between f0e518c785 and final HEAD.
  • Renderer console: 0 errors. Mobile QA is not applicable because this PR changes desktop renderer diagnostics only.

Final HEAD — responsive terminal

Final HEAD with one responsive terminal pane

Pane-sampling commit — responsive split panes

Two responsive split terminal panes

@brennanb2025
brennanb2025 merged commit 153acf3 into main Aug 3, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…r breadcrumbs (stablyai#12198)

* feat(crash-reports): add byte attribution to renderer memory highwater breadcrumbs

Entry counts stay flat when a slice grows by value weight (97b9e86d leaked
~700MB while its biggest slice grew by 4 entries), so highwater breadcrumbs
now carry sampled per-slice KB estimates for the store plus a live pane
census (managers, panes, estimated scrollback KB) — the dominant heap cost
the store census cannot see.

* fix(crash-reports): bound renderer OOM profiling

* fix(crash-reports): total raw store estimate bytes
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