fix(desktop): carry a renderer heap-growth trajectory on the Sentry scope
Problem
Two renderer OOM aborts on 1.20.2, one event each. Both are native minidumps with
no first-party JavaScript frames — the process dies inside the allocator, so every
frame is Electron, Chromium or V8. They are undiagnosable as they stand: the report
shows a full heap, never what filled it or how fast.
User-visible harm: the renderer is killed outright. The window disappears
mid-session and every unsaved renderer-side state goes with it — twice in the
1.20.2 population so far, after 75h (macOS) and 5h (WSL2) of uptime.
Will this reach the reported failure? The crash kills the renderer from inside
the allocator, so nothing can be transmitted at crash time — it has to be
attached beforehand. Traced through @sentry/electron 7.16.0:
scopeToMainIntegration(renderer) pushes the merged scope to main on every
scope change.handleScope(main,main/ipc.js) applies onlyuser,tags,extra,
attachmentsandbreadcrumbsfrom that message.contextsis dropped, so
Sentry.setContextin the renderer would be worthless here — this uses
setExtraandsetTag.sentryMinidumpIntegrationfiles the minidump from the main process via
core.captureEvent, which applies main's current scope. On the other path
(minidump found at next startup) it applies the persistedscope_v3store via
applyScopeDataToEvent, which also carries tags and extra. Both paths keep it.
DESKTOP-Y3 came through the live render-process-gone path (it has
electron.crashed_url and details); DESKTOP-Y8 came through the startup path
(it has neither). The enrichment survives both.
Why now, rather than archiving or waiting: these are the first two events of a
family that only appears after long uptime, so waiting means waiting days per data
point and still getting a bare minidump each time. Archiving discards a crash that
kills the window. The enrichment costs nothing per event and makes the next
occurrence — whenever it lands — carry its own history.
Root cause
Not addressed here, and deliberately not guessed at: the renderer heap grows
without bound during long sessions until V8 aborts. Both issues stay open as
trackers.
What the current reports already contain, and therefore what this must not
duplicate:
- DESKTOP-Y3 ships Chromium's full
v8-oom-*crash-key set — old-space
3761/3930 MB, allocator 4036/4096 MB, the trailing GC log. Point-in-time heap
statistics are already there, more precisely than any JS-side reading. - DESKTOP-Y8 ships none of them: those keys are written by V8's
FatalProcessOutOfMemorypath, and that abort came from PartitionAlloc failing
to commit insideJSON.stringify. It has no JS heap figures at all. - Uptime is derivable on both from
app.app_start_timeversus the event time.
So the gap is not the sizes and not the uptime. It is that no crash report can
contain history. A steady leak and a session that sat flat for three days then
ran away produce the same endpoint and the same average rate, and they point at
completely different code.
Fix
apps/desktop/src/renderer/lib/heap-trajectory.ts — a pure, bounded series:
recordHeapSample folds a reading in, keeping the latest value and the peak on
every tick and at most 24 history points. When the history fills it halves its
resolution and doubles its interval, so the retained points stay evenly spread
over the whole session instead of collapsing onto the last hour.
apps/desktop/src/renderer/lib/sentry.ts — reads performance.memory every 5
minutes after Sentry.init and writes renderer_heap (extra) and
renderer.heap_used (tag). No captureException, no beforeSend filter, no
behaviour or message changes.
Sampling interval is 5 minutes because Chromium refreshes performance.memory at
most every 20 minutes and rounds it into buckets unless the app runs with
--enable-precise-memory-info — which is deliberately not set, as it hands
precise heap readings to any web content the app renders (webviewTag is on).
Bucketed 20-minute values resolve a multi-day, multi-GB climb fine.
What it must not report: nothing, ever, as an event. There is no threshold and
no sampler that transmits. It only mutates scope state that rides along on reports
that were going to be filed anyway, so no input can turn it into quota. Its only
runtime cost is one local IPC scope message per 5 minutes, in an app that already
emits one per breadcrumb.
Verification
bunx biome check on both changed files, from the repo root:
Checked 2 files in 37ms. No fixes applied.
cd apps/desktop && bun run typecheck:
$ bun run generate:icons && bun run generate:routes
$ bun run scripts/generate-file-icons.ts
Generated file icons: 1067 SVGs copied, 2046 file names, 1152 extensions, 4528 folder names
$ tsr generate
$ tsc --noEmit
bun test src/renderer/lib (from apps/desktop):
508 pass
0 fail
2455 expect() calls
Ran 508 tests across 38 files. [658.00ms]
apps/desktop/src/no-main-process-blocking.test.ts is not applicable — no git
client code is touched.
Replaying two synthetic 75-hour sessions through the series, both ending at the
cap that DESKTOP-Y3 actually hit, both with the same ~46 MB/h average — the shape
separates them, which is the entire point:
steady leak:
used_mb 3765 limit_mb 3930 peak_mb 3765 uptime_minutes 4500 growth_mb_per_hour 46
history "300@0 546@320 793@640 1039@960 1286@1280 1532@1600 1778@1920 2025@2240
2271@2560 2518@2880 2764@3200 3010@3520 3257@3840 3503@4160 3750@4480"
late runaway:
used_mb 3810 limit_mb 3930 peak_mb 3810 uptime_minutes 4500 growth_mb_per_hour 47
history "300@0 300@320 300@640 300@960 300@1280 300@1600 300@1920 300@2240
300@2560 300@2880 300@3200 300@3520 300@3840 1600@4160 3680@4480"
first sample: used_mb 180 peak_mb 180 uptime_minutes 0 growth_mb_per_hour 0 history "180@0"
tag buckets: 90-100% for both; "unknown" when jsHeapSizeLimit is 0
An earlier revision decimated the array without widening the sampling stride,
which decayed old points exponentially and left the first 71 hours as a single
sample. That is what the replay above was written to catch, and the committed
version is the corrected one.
Not verified end-to-end against a live crash: reproducing it means exhausting a
4 GB heap in a packaged production build. The transmission path is established by
reading the SDK source, cited above, rather than by observation.
Refs DESKTOP-Y3
Refs DESKTOP-Y8
https://claude.ai/code/session_f97cca1f-a6b1-47bf-b456-22bba1e67a4b
Summary by cubic
Attach a renderer heap-growth trajectory to the Sentry scope so OOM renderer crashes carry history. Previously minidumps had no heap history; now each report includes a bounded series and a decile tag without sending new events.
- New
heap-trajectory.tskeeps a 24-point bounded series, doubles stride when full, and summarizes used_mb, limit_mb, peak_mb, growth rate, and history. sentry.tssamplesperformance.memoryevery 5 minutes afterSentry.init, setsrenderer_heap(extra) andrenderer.heap_used(tag), and no-ops if memory is unavailable.- Uses tags/extras because
@sentry/electronforwards them from renderer to main and the minidump path applies them; avoids contexts. - No config or user-visible behavior changes. No event volume increase. Minimal overhead (one scope update per 5 minutes). Addresses DESKTOP-Y3 and DESKTOP-Y8.
Summary by CodeRabbit
- New Features
- Added heap usage monitoring for the desktop app.
- Sentry now records current and peak memory usage, uptime, growth trends, and bounded usage history.
- Added memory utilization categories for easier performance analysis.
- Monitoring samples memory immediately and periodically when supported.