You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Log where main's memory went when it suddenly jumps - #46734
Sometimes the hidden "brain" part of Orca suddenly uses a lot more memory, and by the time anyone looks, there is no clue what grew. Now, when that part of Orca jumps by about 300 MB within two minutes, Orca writes one short note to its own local log saying where the memory is sitting, so the next time it happens we can see the culprit.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$93
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$93
Prod
6
$\color{#1a7f37}{\Huge{\mathbf{+}}}$216
$\color{#cf222e}{\Huge{\mathbf{−}}}$8
$\color{#1a7f37}{\Huge{\mathbf{+}}}$208
What Changed
Before: a jump in the main process's memory (for example 849 MiB to 1.44 GiB) left nothing behind but the before/after size. We could not tell whether JavaScript, buffers, a background worker, or native code grew.
After: when main's working set rises 300 MB or more compared with the samples from the last two minutes (with slack for the sampler firing a little late), Orca writes one memory.main-spike record to the local trace log (logs/main.trace.ndjson). It contains numbers only:
the trigger: current and baseline working set, the rise, and the per-process-type metrics from the same sample;
V8 heap statistics (total, used, physical, malloced, external, native and detached contexts) and used size per heap space;
Chromium's own private/shared totals for the main process;
each worker thread's committed heap (largest four by role; a worker busy in native code reports the last heap it recorded instead) and what main is holding for chat delivery (reader pool and subscriber backlogs);
counts: open chats, workspaces, projects, bots, terminals.
Mechanism: the existing 60-second process-metrics sampler (already running for crash diagnostics) hands main's working set to a tiny ring of the last two minutes of readings. The check is one comparison per sample. There is no new timer. It stays quiet for the first two minutes after launch (loading a large profile is expected growth), writes at most once an hour, and does nothing when local diagnostics are turned off.
Why
A recent report showed main going from 849 MiB to 1.44 GiB. We could not reproduce it on a large test profile across two builds, so we do not know which part of main grew. Rather than guess at a fix, this makes the next occurrence name its owner. A full Chromium allocator dump or heap snapshot was ruled out for automatic capture: both need a tracing session or a pause, which would cost the most exactly when memory is already tight, so those stay manual. Writing to the existing local trace log means the record only leaves the machine if the user sends a diagnostic bundle themselves.
Linked Issue
N/A (internal investigation of a user memory report; no GitHub issue).
Visual Proof
N/A: no UI. The only output is one line in the local trace log, and only after a spike.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
main-memory-spike-capture.performance.test.ts is a perf contract: across a simulated day of steady growth (2.9 GB total, never 300 MB inside two minutes) it writes no record and never reads the counts; the launch ramp writes nothing; a 300 MB rise across two late-firing samples is caught; a synthetic 620 MB jump writes exactly one record with the expected trigger values and counts, a second jump in the same hour writes nothing, and one after the hour writes again. Typecheck, lint and changed-file checks pass on Linux. Platforms: the code reads Electron's cross-platform process metrics, Node and V8 APIs only; nothing platform-specific.
Performance
No idle cost: the existing 60-second sampler now also does one comparison against at most three stored numbers. The capture itself runs at most once an hour and only after a 300 MB jump; it reads in-process stats, Electron's per-process memory info, and each worker's heap size (each read already bounded by the existing 2-second timeout), then writes one record through the existing batched trace writer. No heap snapshot, no tracing session, no subprocess.
Risk
Low. The riskiest part is the capture running while memory is already high; it allocates only a small object of numbers and reuses reads the crash diagnostics already make. If one of the memory reads fails, the record keeps every other number and marks only that part as failed; nothing else is affected. No saved data, settings, remote hosts or mobile are touched. Back out with a plain revert.
Level: Low
AI Disclosure
Review
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
No actionable comments were generated in the recent review.
Walkthrough
The changes add main-process memory spike capture and connect it to pre-gone process sampling. Capture begins after a two-minute launch ramp when working-set growth reaches 300 MB, subject to a one-hour interval and an active trace sink. Recorded details include Node, V8, optional Chromium, worker, and registered-count metrics. The changes also expose PTY and conversation counts and add tests for gradual growth, launch ramp, late ticks, spike attributes, and interval suppression.
Merge Risk: Low · up to 82715
This adds a local diagnostic record for sudden main-process memory growth. Behavior is limited to the trace log and an hourly cap. The remaining caveat is that growth over up to about 150 seconds may trigger a record, which the record's baseline age now discloses. The risk is low.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "Log where main's memory went when it suddenly jumps" matches the main change: the PR adds a main-process memory-spike capture that writes a memory.main-spike record to the local trace log w…
Description check
The description follows the template well. It has ELI5, What Changed (before/after and mechanism), Why (including alternatives ruled out), Testing, Performance, Risk with level, and the checklist. Vis…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "Log where main's memory went when it suddenly jumps" matches the main change: the PR adds a main-process memory-spike capture that writes a memory.main-spike record to the local trace log when the working set rises by 300 MB within about two minutes. The title is specific and concise and does not list files.
Full details: Description check
Explanation
The description follows the template well. It has ELI5, What Changed (before/after and mechanism), Why (including alternatives ruled out), Testing, Performance, Risk with level, and the checklist. Visual Proof is marked N/A with a reason. The Linked Issue section is marked N/A with a reason, although the template says an issue should always exist for outside contributors. The AI Disclosure section is empty, and the final lint/typecheck/test/build checklist item is unchecked. The Performance section is filled in. Two gaps remain: the empty AI Disclosure section and the unexplained N/A for the linked issue. The 'Fixes #' line is also left blank. The description is mostly complete, so the check passes, but the author should fill in the AI Disclosure section and justify or link the issue.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
perf-scan: PR #46734 at 5be865976bc89d7d7d3340418737f1c76f7a33e0
Verdict: clean. No P0 or P1 findings. The PR adds no timer, poll, IPC or subscription. All new work either runs as an O(1) step inside the existing 60 s app.getAppMetrics() sampler, or at most once an hour behind a 300 MB rise and an active trace sink.
Range: 121f9bc731e…5be865976bc (4 commits, 6 production files). This was a static source trace only. I ran no benchmarks or timing, so no ms, CPU or heap figures are claimed.
New work: trigger, population, bound
#
Work
Trigger / rate
Population
Bound
Cost at fleet (10×)
1
observeMainMemorySample (main-memory-spike-capture.ts:31), called from process-gone-diagnostics.ts:207
The existing setInterval at process-gone-diagnostics.ts:222, every 60 s, plus one sample at startup. Main only.
One owner per app
Before arming (first 2 min): ??= and return. After: shift and min over recent (≤ 3 entries at 60 s cadence with a 2 min window), push, 3 compares. details was already computed before this PR; it's only reused.
O(1) and independent of worktrees, terminals and chats. About 1 µs per minute. Idle wakeups/s on main: base 1/60, head 1/60 (no change). Renderer and daemon are unchanged.
2
captureMainMemorySpike (:59)
Only when working set rises ≥ 300 MB within 2 min and ≥ 60 min since the last capture andhasActiveTraceSink() (a null check, tracer.ts:76).
Main
At most 1 per hour, never with no sink. A failed check doesn't update lastCaptureAtMs, but it only costs the compare.
Sync part: process.memoryUsage(), v8.getHeapStatistics(), getHeapSpaceStatistics() (about 10 spaces), and the counts closure (below). Async part: one process.getProcessMemoryInfo(), and one worker.getHeapStatistics() per live worker with the existing per-read timeout (worker-heap-sample.ts:20). Writes one span with about 50 attributes.
3
Counts closure (main-process-ready-runtime.ts:38)
Only inside #2 (≤ 1/h). Registering it at startup just stores a closure.
One Object.keys(worktreeMeta) (in-memory state, not SQLite), getRepos() (copies an array of about 12 cached rows), getBots() (cached), sessions.size, registry.size
O(worktrees) once an hour
About 1,900 keys at fleet and about 19k at 10×. A sub-ms one-shot that never repeats faster than hourly.
4
readWorkerThreadMemoryData (worker-thread-diagnostics.ts:117) and the live set moved to module scope (:51)
Reuses readLiveWorkerHeaps, the same per-worker read the existing heap sampler already makes. installWorkerThreadDiagnostics is called once (index.ts:73), so moving live to module scope adds no second owner. Dead workers are still pruned on read.
Same cost as one existing sampler tick, at most hourly
Dormant code made to run for everyone: none at steady state. The only previously dormant path now reachable is a worker-heap read plus getProcessMemoryInfo on a spike. That isn't new for everyone: it needs a ≥ 300 MB rise and an opt-in trace sink, and it's capped at 1 per hour. Cold cost: one async Chromium memory query, one heap-stat read per live worker (bounded by the existing timeout), and one Object.keys over worktree meta. That's a single-digit-ms-class one-shot by count. It wasn't timed.
Startup / migration: no persisted state, schema or migration. New imports on the main startup graph are node:v8 (built in), observability/tracer, worker-thread-diagnostics (already eager, index.ts:65), pty-registry (already imported by the pty IPC modules) and structured-agent-session-registry (already eager via main-process-ipc-bootstrap.ts:17). Eager module count grows by 1 (the new 157-line file) and no SDKs are added. At startup the first sample sets armedAtMs and returns.
Regression classes touched
Fixed-cadence poll / new idle wakeups: matched and disproved. No new timer. The work runs inside the existing 60 s interval, and the wakeup count is unchanged.
Expensive code newly reachable past a gate: matched and disproved. The worker-heap and allocator reads sit behind a rise threshold, a 1 h cooldown and a sink check, at most 1 per hour.
Per-entity state outlives the entity: the module-level recent array is bounded by the 2 min window (≤ 3 entries; a backward wall-clock jump of J only delays pruning by about J/60 s entries). The module-level live set keeps its existing pruning. Disproved.
Eager startup imports: matched and disproved (above).
Sync fs/SQLite on main: none added. The counts read in-memory state.
Six questions
Unused work before the gate: reviewed. The cheap threshold check runs before any collection, and details was already built.
Ownership multiplication: reviewed. One sampler, one module-level state, one install.
Thread/storage: reviewed. Main thread: sync V8/process stats plus Object.keys at most hourly. No SQLite or fs.
Growth/progress: reviewed. The window array is bounded, and the hourly cooldown applies even if the span fails.
Execution host: reviewed. getProcessMemoryInfo is guarded with typeof. Nothing is per-SSH-host and nothing spawns.
Obsolete work stops: reviewed. The capture is a one-shot promise, and worker reads have the existing timeout. No timers to clear.
Residual gaps: I didn't time a spike capture on a large real profile. The pricing above is by source count only.
Range: 5294a4ad6af...d36bcca3df0. Citations are from the target ref. Review was static only: no benchmarks or suites were run. Prices use the reference fleet: 750+ worktrees, a few hundred PTYs, 100+ agents/chats.
Findings
No P0/P1 perf findings. The PR adds no timer, poll, listener, IPC or subprocess. The steady path adds O(≤3) arithmetic to an existing 60 s main-process tick. The capture path is gated by a ≥300 MB rise, an active trace sink and a 1-hour cooldown. Its work does not grow with worktrees, terminals, chats or history.
New work: trigger × population × bound
#
Work
Trigger / thread
Population
Bound
1
observeMainMemorySample (main-memory-spike-capture.ts:33-63): compare once against arming time, shift old samples, take a min over recent, push 1 sample, then check 3 gates
Existing setInterval in startPreGoneCrashSampling (process-gone-diagnostics.ts:222), every 60 s, Electron main. No new caller.
Every desktop user, 1 owner per process
recent is pruned to window + slack = 150 s, so it holds ≤3 entries at 60 s. details was already computed by the base and is reused, not rebuilt. Constant ~µs per minute. Idle wakeups/s on main: base 1/60, target 1/60, so unchanged. Renderer and daemon are untouched.
2
captureMainMemorySpike: process.memoryUsage, v8.getHeapStatistics, getHeapSpaceStatistics, the counts closure, then async process.getProcessMemoryInfo plus readWorkerThreadMemoryData, then one startSpan/end NDJSON record
Main working set rises ≥300 MB above the min of the last ~150 s, andhasActiveTraceSink(), and ≥60 min since the last capture. Not armed during the first 2 min after launch.
Users with local tracing on, which is the default unless CI or ORCA_DIAGNOSTICS_DISABLED. At most 1 per hour.
≤24 per day even if the working set oscillates. One span with ~60 attributes (process-metric buckets, ~10 V8 spaces, 5 counts, ≤4 worker rows).
getAllWorktreeMeta returns the live state object without cloning (metadata-lineage-operations.ts:89). Object.keys is O(worktrees): ~750 keys at fleet, ~7,500 at 10×, about 1 ms at most, once per hour. Constant at 10× in the sense that it never repeats faster than once per hour.
2b
readWorkerThreadMemoryData (worker-thread-diagnostics.ts:117): worker.getHeapStatistics() per live worker (with timeout, worker-heap-sample.ts:20-42), readRetention, mainHeapSpaces
Live worker threads (a handful, not per worktree or chat)
The same reads already run every 60 s (10 s under pressure) in the base sampleHeaps. This adds ≤1 extra read per worker per hour, and the existing per-worker timeout bounds it.
Dormant code made reachable for everyone
process.getProcessMemoryInfo() has a new caller on main. It is async, so the OS memory query runs off the JS thread. Estimated cold cost: about 1 ms or less. It runs only on a spike and at most once per hour.
readLiveWorkerHeaps / readRetention are now reachable from the spike path. They are not dormant: the base already runs them on the worker-heap sampler for every user with a live worker. With no live workers, live is empty and the cost is trivial.
No gate was removed, loosened or bypassed. The base already had both the 60 s sampler and the worker sampler running for everyone. The new work sits behind three new, stricter gates.
Startup / migration
Startup: startProcessCrashObservers gains only a closure assignment (setMainMemorySpikeCounts), with no reads at install time. The import graph gains main-memory-spike-capture.ts (small, plus the builtin node:v8). Its imports tracer, worker-thread-diagnostics (already imported by src/main/index.ts), structured-agent-session-registry (already imported by main-process-ipc-bootstrap.ts) and pty-registry are all already on the main startup graph. No new SDKs or adapters are loaded eagerly.
The first sample at launch (startPreGoneCrashSampling → immediate samplePreGoneProcessMetrics) only sets armedAtMs. Migration: none. No persisted state, schema or store change.
Regression classes touched
Class
Disposition
Fixed-cadence poll / new idle wakeups
Matched and disproved. No new timer: the code piggybacks on the existing 60 s interval. Main wakeups/s are unchanged (1/60), renderer and daemon 0 → 0.
Expensive code newly reachable past a gate
Matched and disproved. No gate was removed. New work runs only behind rise + sink + 1 h cooldown, priced above at ≤1 per hour.
Per-entity state outlives the entity
Matched and disproved. live moved from a closure in installWorkerThreadDiagnostics to module scope. Its lifetime is the same (process-long, installed once). Pruning of threadId === -1 is unchanged in readLiveWorkerHeaps. recent is time-pruned to ≤3 entries.
Unbounded fan-out
Matched and disproved. Promise.all over live workers is a handful of items with per-read timeouts, as in the base.
Sync fs/SQLite on main
No matching code. The spike path has no fs or SQLite; the trace sink write is the existing batched sink.
Eager startup imports
Matched and disproved. All transitive modules are already loaded at startup (see above).
Unused work before the skip gate: Reviewed. The steady path reuses the already-built details. Every capture read happens after the three gates, and hasActiveTraceSink() is checked before any read. The perf contract asserts that the counts closure is never called over a day without a spike.
Ownership multiplication: Reviewed. There is one module-level owner per main process, with no per-row, per-pane, per-worktree or per-host instances.
Thread / storage: Reviewed. Everything runs on Electron main: sync V8 and memoryUsage reads (µs) plus O(worktrees) Object.keys, at most once per hour. getProcessMemoryInfo and the worker heap reads are async. There is no SQLite.
Growth / progress: Reviewed. recent is bounded by time. Minor non-issue: if the wall clock jumps backwards, the head-only prune stalls and recent can grow by about one 16-byte entry per minute for the length of the skew. It drains once the clock catches up. That is bounded by skew, not by uptime, so it is not a finding.
Execution host: Reviewed. app.getAppMetrics, getProcessMemoryInfo and V8 stats are all in-process on mac, Linux and Windows. No SSH or remote round trips, no subprocesses. Remote hosts and mobile are not affected.
Obsolete work / release: Reviewed. The fire-and-forget capture holds one span until two async reads settle, and the worker read timeout bounds that. Nothing is retained after span.end(). No teardown is needed because there is no timer of its own.
Non-runtime: pnpm-lock.yaml still adds @pnpm/exe@12.18.0 to packageManagerDependencies, even though commit 9aa93b8 says it drops an unrelated lockfile change. It has no app-runtime cost, but it may change pnpm self-install or download behaviour in CI. Worth confirming it was intended.
Evidence: source-proven counts and bounds only. I read main-memory-spike-capture.performance.test.ts (no capture work over a day without a spike, one record per hour) but did not run it. No timing, CPU or heap was measured.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
Problem: a reported jump in main's memory (849 MiB to 1.44 GiB) left no clue which part of main grew, and it did not reproduce on a large test profile.
User-facing change: none visible. After a jump of 300 MB or more within two minutes, main writes one line of numbers (memory breakdown and counts) to the local trace log, at most once an hour and never during the first two minutes after launch.
Fixed during review
A failed memory read no longer discards the rest of the record; each part fails on its own.
The two-minute window kept dropping the sample from two ticks ago, because the sampler fires a few ms late; it now keeps that sample. A test with late timestamps covers it.
Removed an unrelated lockfile change.
PR body corrected in two places.
Deferred (reviewer agreed)
Growth spread over longer than about two minutes still writes no record. The trigger shape was specified for this work.
A brief macOS memory dip followed by a rebound could log a false spike. It is local, hourly-limited and records its baseline, so it costs little.
Perf contract: no record and no counts read over a simulated day without a spike; the launch ramp writes nothing; a spike writes exactly one record; late-firing samples are still compared.
Full perf-scan: clean, posted above. It was a source read; nothing was timed.
Blinded regression audit on the change merged onto main: SAFE.
QA: covered by tests (qa=tests). There is no UI, and nothing depends on a real app run beyond the APIs the tests stub.
Range: 4177a78fc7f...8271507ae13. Read-only static trace. No benchmarks were run. Grading assumes the reference fleet: about 1,900 worktrees at 10×, a few hundred PTYs, 100+ agents, and several worker threads.
Findings
None. Nothing at P0 or P1.
New work: trigger × population × bound
#
Work
Trigger / cadence
Population
Bound / cost
1
observeMainMemorySample() called from samplePreGoneProcessMetrics (process-gone-diagnostics.ts:204-208)
The existing 60 s setInterval in startPreGoneCrashSampling, which is unref'd and already runs for every user. No new timer.
Every desktop main process, 1 per process
Per tick: one time-window prune, a min-scan over recent, and one push. The window is 150 s at a 60 s cadence, so recent holds ≤3 entries. That is O(1): a few comparisons per minute on main. details was already computed. The PR only moves it into a local variable.
Main working set rises ≥300 MB over the minimum of the last ~150 s. The sampler must have been armed for 2 min after the first sample. The trace sink must be active. At most one capture per 60 min (lastCaptureAtMs).
Everyone. The local trace sink is on by default (observability/index.ts: localFileEnabled: true even without consent), so this path is live for all users, not dormant.
≤1 per hour per process. Work done in one capture is listed below.
Object.keys(store.getAllWorktreeMeta()) reads the in-memory state.worktreeMeta (no SQLite or fs). That is one array of about 1,900 strings at 10× fleet, so <1 ms once per hour. getRepos() covers about 12–120 repos and getBots() is small. registry.size and sessions.size are O(1).
one worker.getHeapStatistics() per live worker (a handful), with a 2 s timeout each
The same readers already run on the existing worker-heap sampling loop, which starts for everyone once any worker spawns. This adds at most one extra pass per hour. readRetention walks the reader and subscriber retention registries, which hold one entry per live reader or subscriber. Promise.all covers a handful of workers, so fan-out is bounded by the worker count.
2e
span.end() → one NDJSON line, about 60–80 attributes
per capture
local trace file
About 2–4 KB per hour at worst. The file's existing rotation and caps apply.
3
live worker set moved from function scope to module scope (worker-thread-diagnostics.ts:51)
—
installWorkerThreadDiagnostics has one production caller (index.ts:73)
Lifetime is unchanged: still one set per process. Dead entries are still pruned in readLiveWorkerHeaps, which both callers now go through.
4
registeredPtyCount() and openConversationCount() accessors
only through 2b
—
O(1) .size
Dormant code made live for everyone: only #2, the capture path. It is live for every user because the local trace sink is on by default. The pieces it reaches either already run for everyone (worker heap and retention readers, process metrics) or are constant-time V8 and Node stats. Cold cost per capture is a few ms on main plus one getHeapStatistics message per worker on the worker threads, at most once per hour. That is a one-off, non-repeating cost and not a finding. It does not remove or loosen any existing gate.
Idle wakeups/s, main, before → after: unchanged. The PR adds no timer, poll, subscription or IPC; it piggybacks on the existing 60 s tick. The renderer and daemon are untouched. The only new timers are the existing 2 s per-worker read timeouts, which exist only during a capture and are cleared in finally.
Startup / migration: no migration, schema or persistence writes. New imports on the main startup graph are main-memory-spike-capture.ts (pulls in node:v8, tracer and worker-thread-diagnostics, all already eager through index.ts), pty-registry (already eager) and structured-agent-session-registry (79 lines, already imported by many eager bot modules). Eager module growth is about one small module. At launch startProcessCrashObservers installs a closure and does no extra work.
Regression classes touched
Fixed-cadence poll / new idle wakeups: matched (it hooks the 60 s sampler) and disproved. No new timer. Per-tick work is O(≤3).
Expensive code newly reachable past a gate: matched. The capture runs by default, but it is gated by a ≥300 MB rise, a 60 min cooldown and an active trace sink. Its contents are constant or already-running readers (see 2a–2e). Disproved.
Per-entity state outlives the entity: module-scope live set and recent array. live prunes dead workers (threadId −1). recent is pruned by time window to ≤3 entries. Edge case: if the wall clock jumps backwards by D, entries stamped in the "future" are not pruned until the clock catches up. That leaves at most D/60 s entries (1,440 for a 1-day jump), adding ≤1,440 comparisons per minute until it self-heals. That is bounded and self-healing, so it is not a finding. Disproved.
Unbounded fan-out:Promise.all over live workers, bounded by the worker count. Disproved.
Sync fs/SQLite on main: none added. The store reads come from in-memory state. Disproved.
Eager startup imports: see above. About one small module, no SDK. Disproved.
Six questions
Unused work before the skip gate: reviewed. The per-tick work before the threshold check is O(≤3) comparisons. All reads happen after the threshold, cooldown and sink gates.
Ownership multiplies: reviewed. One sampler and one capture state per main process. No per-row, per-pane or per-worktree owner.
Thread / storage: reviewed. Main pays constant V8/Node stats plus about 1,900 Object.keys once per hour. Workers each pay one getHeapStatistics. No SQLite or fs on main beyond the trace sink's existing batched file write.
Growth / progress: reviewed. Every bound is constant or tied to the worker count. The counts are O(worktrees) and run only on capture.
Execution host: reviewed. Desktop main only. getProcessMemoryInfo is feature-checked, so this is platform-neutral. No SSH/WSL round trips and no per-host work.
Obsolete work stops: reviewed. A capture is one-shot and the worker reads time out after 2 s. No new long-lived resource besides the ≤3-entry array. The sampler timer's teardown is unchanged.
Coverage and residual gaps
Paths traced: process-gone-diagnostics.ts (sampler + hook), main-memory-spike-capture.ts, worker-thread-diagnostics.ts (live scope, readLiveWorkerHeaps, readWorkerThreadMemoryData), worker-heap-sample.ts, main-process-ready-runtime.ts, pty-registry.ts, structured-agent-session-conversation-reads.ts, structured-agent-session-registry.ts, tracer.ts / observability/index.ts (sink default), and the store getters (getAllWorktreeMeta, getBots, getRepos). Host: mac static reading only. The capture's Windows/Linux behavior relies on Electron APIs that are feature-checked. Not run: main-memory-spike-capture.performance.test.ts and any timing. All costs above are source-proven counts, not measurements.
Problem: a reported jump in main's memory (849 MiB to 1.44 GiB) left no clue which part of main grew, and it did not reproduce on a large test profile.
User-facing change: none visible. After a jump of 300 MB or more within two minutes, main writes one line of numbers (memory breakdown and counts) to the local trace log, at most once an hour and never during the first two minutes after launch.
Fixed during review
A failed memory read no longer discards the rest of the record; each part fails on its own.
The two-minute window kept dropping the sample from two ticks ago, because the sampler fires a few ms late; it now keeps that sample. A test with late timestamps covers it.
Removed an unrelated lockfile change.
The record now gives the real age of the baseline reading instead of claiming a fixed two-minute window.
PR body corrected in two places.
Deferred (reviewer agreed)
Growth spread over longer than about two minutes still writes no record. The trigger shape was specified for this work.
A brief macOS memory dip followed by a rebound could log a false spike. It is local, hourly-limited and records its baseline, so it costs little.
Perf contract: no record and no counts read over a simulated day without a spike; the launch ramp writes nothing; a spike writes exactly one record; late-firing samples are still compared.
Full perf-scan: clean, posted above. It was a source read; nothing was timed.
Blinded regression audit on the change merged onto main: SAFE.
Reference comparison: the change follows the common pattern for spike capture (lowest reading in a recent window, a cooldown, one trace record). Intended differences: it reuses the existing one-minute sampler instead of adding a timer, and it does not list which operations were running.
QA: covered by tests (qa=tests). There is no UI, and nothing depends on a real app run beyond the APIs the tests stub.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Sometimes the hidden "brain" part of Orca suddenly uses a lot more memory, and by the time anyone looks, there is no clue what grew. Now, when that part of Orca jumps by about 300 MB within two minutes, Orca writes one short note to its own local log saying where the memory is sitting, so the next time it happens we can see the culprit.
What Changed
Before: a jump in the main process's memory (for example 849 MiB to 1.44 GiB) left nothing behind but the before/after size. We could not tell whether JavaScript, buffers, a background worker, or native code grew.
After: when main's working set rises 300 MB or more compared with the samples from the last two minutes (with slack for the sampler firing a little late), Orca writes one
memory.main-spikerecord to the local trace log (logs/main.trace.ndjson). It contains numbers only:process.memoryUsage()(RSS, heap, external, array buffers);Mechanism: the existing 60-second process-metrics sampler (already running for crash diagnostics) hands main's working set to a tiny ring of the last two minutes of readings. The check is one comparison per sample. There is no new timer. It stays quiet for the first two minutes after launch (loading a large profile is expected growth), writes at most once an hour, and does nothing when local diagnostics are turned off.
Why
A recent report showed main going from 849 MiB to 1.44 GiB. We could not reproduce it on a large test profile across two builds, so we do not know which part of main grew. Rather than guess at a fix, this makes the next occurrence name its owner. A full Chromium allocator dump or heap snapshot was ruled out for automatic capture: both need a tracing session or a pause, which would cost the most exactly when memory is already tight, so those stay manual. Writing to the existing local trace log means the record only leaves the machine if the user sends a diagnostic bundle themselves.
Linked Issue
N/A (internal investigation of a user memory report; no GitHub issue).
Visual Proof
N/A: no UI. The only output is one line in the local trace log, and only after a spike.
Testing
main-memory-spike-capture.performance.test.tsis a perf contract: across a simulated day of steady growth (2.9 GB total, never 300 MB inside two minutes) it writes no record and never reads the counts; the launch ramp writes nothing; a 300 MB rise across two late-firing samples is caught; a synthetic 620 MB jump writes exactly one record with the expected trigger values and counts, a second jump in the same hour writes nothing, and one after the hour writes again. Typecheck, lint and changed-file checks pass on Linux. Platforms: the code reads Electron's cross-platform process metrics, Node and V8 APIs only; nothing platform-specific.Performance
No idle cost: the existing 60-second sampler now also does one comparison against at most three stored numbers. The capture itself runs at most once an hour and only after a 300 MB jump; it reads in-process stats, Electron's per-process memory info, and each worker's heap size (each read already bounded by the existing 2-second timeout), then writes one record through the existing batched trace writer. No heap snapshot, no tracing session, no subprocess.
Risk
Low. The riskiest part is the capture running while memory is already high; it allocates only a small object of numbers and reuses reads the crash diagnostics already make. If one of the memory reads fails, the record keeps every other number and marks only that part as failed; nothing else is affected. No saved data, settings, remote hosts or mobile are touched. Back out with a plain revert.
Level: Low
AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)