Repository navigation
feat(crash-reports): add byte attribution to renderer memory highwater breadcrumbs - #12198
Conversation
…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.
📝 WalkthroughWalkthroughAdded a bounded estimator for renderer state collection sizes, including arrays, maps, sets, typed arrays, objects, cycles, and error cases. Registered the estimator as the 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f693354b-3d77-4199-8f01-23dd864132f1
📒 Files selected for processing (5)
src/renderer/src/lib/pane-manager/pane-manager-registry.test.tssrc/renderer/src/lib/pane-manager/pane-manager-registry.tssrc/renderer/src/lib/state-collection-byte-estimate.test.tssrc/renderer/src/lib/state-collection-byte-estimate.tssrc/renderer/src/store/index.ts
Greptile SummaryThis PR adds byte-weight attribution to
Confidence Score: 5/5Safe 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.
|
| 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
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
src/renderer/src/lib/pane-manager/pane-manager-registry.test.tssrc/renderer/src/lib/pane-manager/pane-manager-registry.tssrc/renderer/src/lib/pane-manager/pane-manager.tssrc/renderer/src/lib/state-collection-byte-estimate.test.tssrc/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
Electron QA evidenceValidated the intended
Final HEAD — responsive terminalPane-sampling commit — responsive split panes |
…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


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_highwaterbreadcrumbs now carry byte attribution:storeKB.*— sampled, extrapolated per-slice KB estimates for the top 16 store slices, plusstoreKB.__totalKBso a report can exonerate the whole store at a glance.storeKB.__budgetHitSlicesmarks 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.keyson 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 lintpnpm typecheckpnpm 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 parent040734b18ein the same environment with identical failures. No failing file overlaps this diff.pnpm build14 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
storecounts, up to 18storeKBcounts (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
__budgetHitSlicesvalue means the aggregate is a bounded partial estimate and must not be used to exonerate the store.SyntaxErrorinrunWaitBlockedCheck, unhandled rejections inonPtyDatapane-key handling,__orcaTerminalFreezeReportRPC failure).