Skip to content

fix(crash-reporting): sample system memory before the process is gone - #18356

Merged
nwparker merged 6 commits into
mainfrom
nwparker/crash-pre-gone-system-memory
Sep 4, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/crash-pre-gone-system-memory

Conversation

@nwparker

@nwparker nwparker commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​440 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​430
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​414 $\color{#cf222e}{\Huge{\mathbf{−}}}$​87 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​327

What

Five field crash reports form cluster G4-oom: Windows renderer OOM, exit -536870904 / 0xE0000008. Real app-version distribution is 3× 1.4.194, 1× 1.4.195, 1× 1.4.188 (1.4.195_ffe54f6d self-reports App version: 1.4.188 — the filename carries the reporting version, not the crashing one). All five are win32. Widening to the reports that share the shape — host reading at or near exhaustion with a normally-sized renderer — pulls in 5 more from G2-killed and G8-misc-crashed, spanning win32, darwin and linux/arm, so 10 reports across 3 OSes.

None of them can be decided, and the reason is a diagnostic gap, not a missing counter:

  • src/main/crash-reporting/process-gone-diagnostics.ts:274 (on main) — getSystemMemoryAtGoneDetails() is the only system-memory read, and it fires inside the process-gone handler, i.e. after the corpse returned its pages.
  • src/main/crash-reporting/gone-time-system-memory.ts:7-8 (on main) admits it in the repo's own words: "this reads AFTER the crashed process's memory returned to the OS, so free/swapFree can look healthier than they were at kill time."
  • src/main/crash-reporting/process-gone-diagnostics.ts:194-205 (on main) — the existing 60 s pre-gone sampler records app.getAppMetrics() only. No host memory.

That matters here because the dead renderer returns 240-642 MB to the OS, which is the same order of magnitude as the entire remaining host headroom in 9 of the 10 reports. "The machine had 300 MB left while we were alive" and "the machine had 900 MB left and we died for another reason" produce an identical crash report today.

id platform reason totalMB freeMB swapFree rendererWS pre-gone peak
ffe54f6d win32 oom 15836 2979 306 240 376
521742b2 win32 oom 32476 3571 1962 337 426
2e3be143 win32 oom 32476 4105 2873 416 416
fbccd7fb win32 oom 98206 6923 3761 642 678
4d7e28ee win32 oom 32488 10889 34993 0 306
d1dbafb3 win32 crashed 32224 1830 1477 303 412
4c902448 darwin killed 49152 1440 – 304 464
603bc6dd darwin crashed 24576 272 – 307 386
a50a33fc linux/arm killed 7485 410 0 379 389
ee78a9b7 linux killed 128495 726 0 0 –

The change adds a second pre-gone sampler that carries a live host reading into the crash report:

  • src/main/crash-reporting/pre-gone-host-memory.ts (new) — its own 10 s setInterval, unref'd, armed at startup. Publishes systemMemoryPreGone* alongside its own systemMemoryPreGoneSampleAgeMs. 10 s and not the 60 s metric sweep because the sweep is measurably too stale: processMetricsPreGoneSampleAgeMs in the five G4 reports is 4872 / 36796 / 37332 / 38017 / 39715 ms — four of five carry a ~37 s-old sample, which cannot see a transient allocation refusal.
  • src/main/crash-reporting/swap-volume-free-space.ts (new) — one fs.statfs on the volume backing the pagefile/swapfile, published as systemMemoryPreGoneSwapVolumeFreeMB, the volume that was measured, and systemMemoryPreGoneSwapVolumeAgeMs (its own age — it resolves out of band, so it can be older than the memory numbers beside it, and the last reading is carried onto later samples rather than dropped). It is a necessary condition the investigation named — at a 127 MB available-commit floor on a Windows VM, Windows grew the pagefile to 2029 MB and nothing died — but it is not sufficient, and round 4 stopped it being labelled as if it were: a fixed-size or disabled pagefile grows into no amount of empty disk. win32 and darwin only — Linux swap is a fixed partition, a fixed-size swapfile, or zram, none of which grow into root-fs free space. It is context, not a verdict, and round 5 measured what that is worth: across all 30 win32 reports in /tmp/ct/clusters (G4-oom + G2-killed + G8-misc-crashed) swapTotal/total runs 1.06x-3.02x, never at or below 1.0 — so the one decisive label this PR can emit, available-commit-hard-capped, would have fired on zero of the machines this PR was built from. What the statfs buys is therefore narrower than 'decide the cluster': it is (a) the falsifier — a low-commit report that also shows a nearly-full pagefile volume is the one shape that survives the failed repro, and nothing in today's reports can show it; (b) the hard-capped case, rare in this sample but the only unambiguous refusal Windows exposes without a registry read; and (c) the number an analyst needs to rule out disk exhaustion, which today they must guess at. If the next batch shows the same 1.06x-3.02x band with roomy volumes, that is itself the answer — commit refusal is not the mechanism — and the statfs should then be removed rather than kept.
  • src/main/crash-reporting/system-memory-details.ts (renamed from gone-time-system-memory.ts) — every reading now carries systemMemoryPressureSignal, which never claims more than the platform's data supports: available-commit-hard-capped (win32 whose commit limit is at or below RAM, i.e. no pagefile behind it, so the floor cannot heal — the one decisive win32 case, and not expected to fire on the observed fleet: all 30 win32 field reports sit at swapTotal 1.06x-3.02x total. Its arithmetic is also slightly loose — total is ullTotalPhys while the commit limit's RAM contribution is 1-2% lower for kernel reserve, so a fixed pagefile smaller than that gap also gets the label; the downstream reading, 'this floor cannot heal', holds for a fixed pagefile too, so it is naming imprecision, not a wrong verdict), available-commit-volume-cotimed (win32 with a volume datum read on the same tick as the commit number — context beside it, not proof the pagefile could grow; see round 4), available-commit-unqualified (win32 with no co-timed volume datum), mem-available (linux with MemAvailable), none otherwise — which is always on darwin, where free/fileBacked/purgeable answer reclaimability and never pressure.
  • process-gone-diagnostics.ts / main-process-ready-runtime.ts — startPreGoneProcessMetricsSampling becomes startPreGoneCrashSampling and arms both samplers.

This PR does not fix a leak and does not prevent a crash. It is a decidability change: the next batch of these reports carries a host reading taken while the renderer was alive, plus a same-tick reading of the volume the pagefile lives on. That volume number is context, not a verdict (round 4), and the only growability verdict the branch emits, available-commit-hard-capped, matches none of the 30 win32 reports on hand (round 5). So the honest claim is narrower than "separates low commit from refused commit": the reports become falsifiable — a live host reading, its true age, and enough disk context to rule commit refusal in or out by hand — not automatically decidable. Host pressure remains a hypothesis — the live repro below failed to reproduce the kill.

Fix evidence

Every revert below was re-run against HEAD (7cd14bdbedf) for this description. Rounds 3-5 moved the code and renamed the enum, so the counts and messages recorded when each mutation was first written no longer matched the tree; the outputs here are from the current run, one mutation at a time, git status clean before and after each. Targets: src/main/crash-reporting/pre-gone-host-memory.test.ts (12 tests) for A-I and K, src/main/startup/pre-gone-crash-sampling-wiring.test.ts (1 test) for the four wiring mutations in J.

RED — production hunks reverted one at a time, tests kept

A. Drop the detail assembly (Object.assign(crashDetails, preGoneSystemMemoryDetails(nowMs)) in process-gone-diagnostics.ts:306) — nothing the sampler collects reaches a crash report:

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 7 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  ... > carries a pre-gone host reading, not only the post-mortem one
AssertionError: expected undefined to be 200
 ❯ pre-gone-host-memory.test.ts:102:51   expect(details.systemMemoryPreGoneSwapFreeMB).toBe(200)
 FAIL  ... > reports swap-volume free space so low commit can be told from refused commit
AssertionError: expected undefined to be 120
 FAIL  ... > will not let a statfs that outlived its tick qualify the win32 commit verdict
 FAIL  ... > will not let ticks with a failed host read pass a stale statfs off as co-timed
 FAIL  ... > arms the host sampler on its own unref'd 10 s timer, not the metric sweep's
 FAIL  ... > commits the host reading without waiting on the swap-volume statfs
 FAIL  ... > carries the last volume reading forward, aged, instead of dropping it
      Tests  7 failed | 5 passed (12)

B. Drop the one line that arms the host sampler (startPreGoneSystemMemorySampling(systemMemoryIntervalMs) in process-gone-diagnostics.ts:223) — this is the revert that was green across all 264 crash-reporting tests before round 2:

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  ... > arms the host sampler on its own unref'd 10 s timer, not the metric sweep's
AssertionError: expected [ 60000 ] to deeply equal [ 60000, 10000 ]
  [
    60000,
-   10000,
  ]
 ❯ pre-gone-host-memory.test.ts:293:61
      Tests  1 failed | 11 passed (12)

C. Serialize the statfs ahead of the host read (await mergeSwapVolumeFreeSpace(tick) moved before commitHostMemorySample) — the shape round 2 blocked on: a cheap host reading held hostage to a filesystem syscall, with a hung volume able to stop sampling permanently:

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 6 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  ... > arms the host sampler on its own unref'd 10 s timer, not the metric sweep's
AssertionError: expected "vi.fn()" to be called 1 times, but got 0 times
 ❯ pre-gone-host-memory.test.ts:297:30   expect(readHostMemory).toHaveBeenCalledTimes(1)
 FAIL  ... > commits the host reading without waiting on the swap-volume statfs
AssertionError: expected undefined to be 200
      Tests  6 failed | 6 passed (12)

D. Ungate the swap volume on Linux (return path.sep for every non-win32 platform) — the real statfs('/') on this machine returns 226 GB of root-fs free space, which is exactly the number that would sit next to SwapFreeMB: 0 in the two Linux cluster members and invite the wrong verdict:

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  ... > omits swap-volume free space on Linux, where swap cannot grow into free disk
AssertionError: expected { freeMB: 226379, volume: '/' } to be undefined
+ { "freeMB": 226379, "volume": "/" }
 ❯ pre-gone-host-memory.test.ts:130:51
      Tests  1 failed | 11 passed (12)

E. Round 3 — force coTimed = true (the pre-fix behaviour: any resolved statfs qualifies the verdict):

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  ... > will not let a statfs that outlived its tick qualify the win32 commit verdict
AssertionError: expected 'available-commit-volume-cotimed' to be 'available-commit-unqualified'
 FAIL  ... > will not let ticks with a failed host read pass a stale statfs off as co-timed
AssertionError: expected 'available-commit-volume-cotimed' to be 'available-commit-unqualified'
      Tests  2 failed | 10 passed (12)

F. Round 4 — drop the hard-capped gate (a commit limit at or below RAM stops being decisive):

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  ... > never reads free disk as proof the pagefile could have grown
AssertionError: expected 'available-commit-volume-cotimed' to be 'available-commit-hard-capped'
 ❯ pre-gone-host-memory.test.ts:189:7
      Tests  1 failed | 11 passed (12)

G. Round 4 — let any resolved statfs name the label again (pressureSignal(platform, merged, true) in withSwapVolumeFreeSpace, i.e. the round-3 regression re-verified against the renamed enum):

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 3 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  ... > labels the reading with the pressure verdict the platform can actually give
AssertionError: expected 'available-commit-volume-cotimed' to be 'available-commit-unqualified'
 ❯ pre-gone-host-memory.test.ts:147:7
 FAIL  ... > will not let a statfs that outlived its tick qualify the win32 commit verdict
 FAIL  ... > will not let ticks with a failed host read pass a stale statfs off as co-timed
      Tests  3 failed | 9 passed (12)

H. Round 4 — drop the volume carry-forward (withCarriedSwapVolume returns its argument unchanged, so the next tick's sample loses the field):

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  ... > carries the last volume reading forward, aged, instead of dropping it
AssertionError: expected undefined to be 42
 ❯ pre-gone-host-memory.test.ts:356:59
      Tests  1 failed | 11 passed (12)

I. Round 4 — restore the Object.keys(details).length === 0 guard (an all-failed reading commits again, shipping disk numbers with no host memory beside them):

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  ... > publishes no pre-gone host keys when every memory field failed to read
AssertionError: expected [ …(5) ] to deeply equal []
+ [ "systemMemoryPreGoneSampleAgeMs", "systemMemoryPreGoneSwapVolumeAgeMs",
+   "systemMemoryPreGonePressureSignal", "systemMemoryPreGoneSwapVolumeFreeMB",
+   "systemMemoryPreGoneSwapVolume" ]
 ❯ pre-gone-host-memory.test.ts:338:89
      Tests  1 failed | 11 passed (12)

J. Rounds 3-4 — the startup wiring, four mutations, each run alone against src/main/startup/pre-gone-crash-sampling-wiring.test.ts. Deleting startPreGoneCrashSampling() from main-process-ready-runtime.ts:128 was green across 691 tests before round 3; moving it to a never-called sibling export in the same file was green across all 9 before round 4.

delete the line                                   AssertionError: expected +0 to be 1        (:37)
move to `export function armCrashSamplingLater()` AssertionError: expected +0 to be 1        (:37)
  — verified in both placements, before and after the entry function
wrap in `if (!is.dev) { ... }`                    AssertionError: expected '…' to contain
                                                  '\n  startPreGoneCrashSampling()'          (:41)
      Tests  1 failed (1)     [each, alone]

K. Round 5 — restore sample-identity co-timing (const coTimed = preGoneSample === issuedFor, the exact pre-fix line) — a statfs issued at t=0 and resolving at t=25 s across two ticks whose host read returned null is named co-timed again:

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
 FAIL  ... > will not let ticks with a failed host read pass a stale statfs off as co-timed
AssertionError: expected 'available-commit-volume-cotimed' to be 'available-commit-unqualified'
 ❯ pre-gone-host-memory.test.ts:274:57
      Tests  1 failed | 11 passed (12)

GREEN — production restored, git status clean

$ ./node_modules/.bin/vitest run src/main/crash-reporting/ src/main/startup/
 RUN  v4.1.11 /private/tmp/fix-pre-gone-system-memory
 Test Files  1 failed | 72 passed | 1 skipped (74)
      Tests  1 failed | 697 passed | 6 skipped (704)

The one failure is environment-dependent and re-verified as failing identically on origin/main's copies of both directories: src/main/startup/ensure-virtual-display.test.ts > reports failure when a stale socket blocks the Xvfb rebind times out at 5000 ms with this branch's src/main/startup and src/main/crash-reporting checked out from origin/main (Tests 1 failed | 32 passed (33)). It needs a working Xvfb rebind. Scoped to what this PR touches:

$ ./node_modules/.bin/vitest run src/main/crash-reporting/ src/main/startup/pre-gone-crash-sampling-wiring.test.ts
 Test Files  27 passed (27)
      Tests  272 passed (272)
$ ./node_modules/.bin/tsc --noEmit -p config/tsconfig.node.json
(exit 0, no output)
$ ./node_modules/.bin/oxlint src/main/crash-reporting src/main/startup
(exit 0, no output)
$ ./node_modules/.bin/oxfmt --check <all 8 changed files>
All matched files use the correct format.  Finished in 8ms on 8 files using 16 threads.

The round-5 fleet measurement, re-run for this description over /tmp/ct/clusters/{G4-oom,G2-killed,G8-misc-crashed}, every win32 report carrying both systemMemoryTotalMB and systemMemorySwapTotalMB — 30 reports, swapTotal/total from 1.063x (3bcc6490 69065/64969 and 5f2c5754 34492/32444) to 3.021x (ffe54f6d 47836/15836), zero at or below 1.0. This is the number that says available-commit-hard-capped would have fired on none of them.

Live reproduction — it FAILED, and that failure is why the swap-volume field exists

A Windows VM (win-lowspec) was driven to 127 MB available commit for 25 s with the renderer actively parsing terminal output. It did not die. Windows grew the pagefile mid-hold: 127 → 2029 MB available commit with nothing released.

So "low available commit kills Orca" is falsified as stated. The field mechanism needs commit refusal — a machine whose pagefile cannot expand (fixed-size pagefile, or a full system drive). That is precisely why this PR ships systemMemoryPreGoneSwapVolumeFreeMB rather than only getSystemMemoryInfo().

Claims NOT proven — stated explicitly rather than padded

  • Host pressure is not proven to be the cause of any of the 10 reports. The repro failed (above). This PR makes the hypothesis testable on the next batch; it does not settle it.
  • No memory-growth mechanism is identified. Across all 14 highwater diagnostic bundles (19 distinct profiles), Pearson r(outsideHeapMB, terminal estBufferKB) = −0.08; r(domNodes) = −0.03, r(managers) = +0.12, r(blinkMB) = −0.27. Subtracting every Orca-attributable counter from outsideHeapMB leaves median 532 MB unattributed (median 67% of privateMB). Nothing the renderer can count explains it. That work is not in this PR.
  • The renderer heap ceiling is explicitly NOT touched. renderer-heap-headroom.ts (RENDERER_HEAP_CAP_MB = 4096, the totalmem() gate) is unchanged: the highest usedHeapMB in any pre-crash sample across the 5 G4 bundles is 164 MB, i.e. 3.9% of the limit. The prior round's ceiling hypothesis is falsified by the artifacts.
  • A refusal shorter than 10 s stays invisible. No polling cadence fixes that; the module comment says so.
  • 4d7e28ee is probably misfiled. Network Service + GPU dead within 24 ms and the main process replaced 78 s later reads as a whole-tree external kill, not a renderer OOM. It is the one report in the table with healthy host memory.

ELI5

When Orca's window process gets killed for running out of memory, we write down how much memory the whole computer had left — but we write it down after the dead process has already handed its memory back. That is like checking whether a car park is full only after the crashed car has been towed away: there is always a space now, so the note is useless.

To the user this looked like Orca's window suddenly going blank and reloading, on machines that were low on memory. When we read the reports afterwards we could not tell whether the computer had genuinely run dry or something else killed us, because every report said the machine looked fine.

This change takes the same reading every 10 seconds while Orca is still alive, so the crash report carries a snapshot from just before the death as well as the one after. On Windows and Mac it also records how much free disk the swap file could grow into, because "low memory" only actually kills you when the swap file has nowhere left to expand — that disk number is a clue for a human reading the report, not something the report decides on its own. It fixes no bug by itself — it means the next round of these reports will actually be readable.

Trade-offs

Not none. Three real costs, all borne by every user on every platform:

  1. A second main-process interval timer for the life of the app. Every 10 s: one synchronous process.getSystemMemoryInfo() (a GlobalMemoryStatusEx / /proc/meminfo-class read). The timer is unref'd so it never holds the process open. This is a permanent, if small, background cost that did not exist before — the previous sampler ran at 60 s.
  2. A recurring fs.statfs syscall on win32 and darwin (not Linux), also every 10 s. It is awaited off the critical path — the memory reading is committed first and the volume value merges in afterwards — so a slow or hung volume cannot stall or skip host sampling. But it is a new periodic filesystem call, on a laptop, forever. A hung statfs leaks one pending promise and suppresses further volume reads for the life of the process — the latch that guards re-entry has no timeout and nothing outside test reset clears it. That fails safe (the verdict degrades to available-commit-unqualified, it does not go wrong), and the memory reading keeps updating regardless, but volume sampling cannot recover without an app restart.
  3. The volume value can be older than the memory numbers printed beside it — the statfs resolves out of band, and while it is pending the latch above makes every tick skip the merge, so its lag is bounded by the last started read, not the last tick. It is not treated as slow-moving (round 3 falsified that: volume free space is precisely what moves fast during a pagefile-growth storm). Instead it ships with its own systemMemoryPreGoneSwapVolumeAgeMs, and only a statfs that answers before the next sampling tick is named in the label (available-commit-volume-cotimed); otherwise the reading stays available-commit-unqualified. Round 5 found that guarantee was not absolute as first written — it compared sample object identity, and a tick whose host read fails leaves the sample in place, so a statfs resolving 25 s and two failed ticks later still read as co-timed. It is now a monotonic tick counter, which those ticks bump regardless (revert K above). Round 4 added carry-forward, so the field no longer disappears from the ticks in between — the last reading rides along at its true age, never re-qualifying the label. The cost is that during a storm the label says less exactly when the read is slowest — a smaller claim rather than a wrong one.

Newly swallowed errors: three, all bounded. commitHostMemorySample catches so a failed read cannot erase the last good sample (a test pins that a throwing host read leaves the process-metric sample intact); mergeSwapVolumeFreeSpace catches so a statfs failure cannot take down a reading that is already committed; statfsSwapVolumeFreeSpace catches the statfs itself. A fourth catch (readElectronSystemMemoryInfo) is pre-existing, relocated from gone-time-system-memory.ts. None can suppress a crash report, but the third is not cosmetic: a persistent statfs refusal (locked-down ACL, AppLocker/EDR policy on C:\, a UNC SystemRoot) yields undefined forever, so the label sits at available-commit-unqualified for the app's life with nothing in the report saying why the volume datum is missing.

No user-facing behaviour change, no UI, no new IPC, no renderer code, no wire opcode. The new details are additive optional fields on an existing crash-report payload, so old servers ignore them and old clients never see them. Two of the new details are strings, not numbers — systemMemoryPreGonePressureSignal (a fixed enum) and systemMemoryPreGoneSwapVolume (a drive label, separator-trimmed so redaction sees no path). Both are assigned after sanitizeCrashReportDetails; neither carries user content.

Adversarial review

6 rounds. Rounds 1-5 each returned blocking findings; round 6 re-reviewed HEAD (7cd14bdbedf) and returned clean. So it did converge, but only on the sixth pass, and three findings were closed by disclosure rather than by code — they are listed as such below, with the residual risk and who carries it. Nothing unresolved has been moved into "Follow-ups".

Round 1 — 3 blocking, all fixed in 17a50c18a53:

  • The shipped field set could not decide the cluster. getSystemMemoryInfo() gives the current commit limit but not pagefile expandability, and the investigation's own repro showed the pagefile growing 127 → 2029 MB mid-hold. Fixed: added swap-volume-free-space.ts.
  • On macOS the six new fields carry no pressure signal at all, per the repo's own documented analysis — a future analyst would table freeMB: 272 from a healthy Mac as evidence of exhaustion. Fixed: every reading now ships systemMemoryPressureSignal, which is none on darwin.
  • 60 s cadence puts the reading ~37 s before the kill in 4 of 5 reports. Fixed: host memory got its own 10 s timer and its own age field.

Round 2 — 4 blocking, all fixed in 9105ba1c7df:

  • The single line that arms the sampler was untested — the reviewer deleted it and all 264 crash-reporting tests stayed green. Fixed: revert B above now goes red on literal interval values, both timers' unref, and an end-to-end 10 s tick.
  • SwapVolumeFreeMB was published on Linux, where swap cannot grow into root-fs free space. Fixed: win32/darwin only; revert D above pins it.
  • The cheap host read was held hostage to statfs — worst case exactly during the paging storm this targets. Fixed: commit-then-merge; revert C above pins it.
  • The PR narrative described a superseded commit ("13 lines, 1 file, no new module, numeric fields only"). Fixed: this description is written against HEAD.

Round 3 — 2 blocking, both fixed in 7f186c4ed40:

  • A stale statfs could raise the win32 verdict to the decisive available-commit. The volume reading merged into whatever sample was current at resolution time, and no age field exposed the gap. Executed: a statfs issued at t=0 on a healthy host resolving at t=20 s of pressure emitted SwapFreeMB: 200 beside SwapVolumeFreeMB: 40000, labelled available-commit, SampleAgeMs: 0 — which reads as "the pagefile had room, so this was not a commit refusal", the opposite conclusion, on exactly the win32 G4-oom reports this PR exists to decide. Fixed: the sample now stamps the tick that issued the statfs, published as systemMemoryPreGoneSwapVolumeAgeMs, and only a statfs answering on its own tick may qualify the verdict. Revert E above.
  • The branch's only production entry point was untested. Deleting startPreGoneCrashSampling() from main-process-ready-runtime.ts:128 left 691 tests across crash-reporting/ and startup/ green — while a comment in the new test file told the next reader that case was covered. Fixed: a source-level wiring test (the pattern this repo already uses for arm-once ready-phase lines). The misleading comment is deleted. Revert J above.

Round 4 — 1 blocking, fixed in 815a0f3dd5f:

  • Free disk space was being read as proof the pagefile could grow. pressureSignal() promoted the win32 reading to the decisive available-commit on the mere presence of a co-timed volume number. Round 3 had closed only the time axis; growability stayed open, and the branch concedes both ways it fails — a fixed-size or disabled pagefile grows into no amount of empty disk (the live repro names exactly that as one of the two refusal mechanisms, and the pagefile maximum is unread), and swapVolumeAnchor measures SystemRoot's volume, which a relocated pagefile does not live on. Executed on 7f186c4ed40: a host with total 16000 / swapTotal 16100 (commit limit ≈ RAM), 180 MB available commit and 812 GB free disk emitted PressureSignal: 'available-commit' with SwapVolumeAgeMs: 0. Fixed: the volume datum is renamed for what it is — available-commit-volume-cotimed, context beside the commit number, asserting no verdict. The one growability fact this API can establish takes the decisive label instead: Windows' commit limit is RAM + pagefile, so swapTotal <= total means no pagefile exists to grow → available-commit-hard-capped. Reverts F and G above.

Round 4 non-blocking — 3 fixed, 2 answered:

  • The volume field vanished on the very next tick, because commitHostMemorySample replaces the sample wholesale — so during a storm (statfs slower than 10 s) the field was present roughly half the ticks. Fixed: carry-forward at its true SwapVolumeAgeMs, never re-qualifying the label. Revert H above.
  • A reading whose every memory field failed still committed, shipping SampleAgeMs + PressureSignal + the volume fields with no host memory numbers beside them. Fixed: the guard now ignores the unconditionally-appended label. Revert I above. (Low field probability — getSystemMemoryInfo() does not return non-finite fields.)
  • The wiring test was a whole-file grep. Moving startPreGoneCrashSampling() into a never-called sibling export in the same file left all assertions green while the branch went inert. A behavioural test would have to mock ~15 ready-phase collaborators (state.store, RpcDispatcher, browserManager, the plugin/automation initializers…) to reach one line. Fixed within the pattern instead: assertions are now scoped to the body of initializeReadyRuntimeServices itself, and the test moved to src/main/startup/pre-gone-crash-sampling-wiring.test.ts, beside the file it pins, matching the 4 existing *-wiring.test.ts precedents.
  • The PR undercounted newly swallowed errors. Correct — three, not two; the statfs catch was uncounted, and a persistent refusal is not cosmetic. Both now stated in Trade-offs.
  • macOS pays a statfs for a datum no verdict reads. Accepted and disclosed, not removed — see the disclosed-limitation list below.

Round 5 — 1 blocking, and it was a description defect, not a code defect. Fixed in this description:

  • The "What" section promised a separation the diff provably cannot make on the observed population. It claimed the change delivers "the pagefile-growth headroom that separates 'commit was low' from 'commit was refused'" — but round 4 had deliberately demoted the volume datum to context, leaving available-commit-hard-capped as the only growability verdict, and that label requires swapTotal <= total. Re-measured for this description across all three clusters: 30 win32 field reports, swapTotal/total between 1.063x and 3.021x, zero at or below 1.0 — the decisive label fires on none of the machines this PR was built from, while a permanent 10 s statfs on every win32 and darwin user was being justified by it. Fixed in the description, not by dropping the syscall: the What section now states that the volume number is context only, that hard-capped is the sole verdict and is not expected to fire on this fleet, and re-justifies the statfs on the three things it can honestly buy — the falsifier shape (low commit plus a nearly-full volume, invisible today), the rare hard-capped case, and letting an analyst rule disk exhaustion out by hand. It also commits to a kill criterion: if the next batch shows the same band with roomy volumes, commit refusal is not the mechanism and the statfs should be removed.

Round 5 non-blocking — 1 fixed in 7cd14bdbedf, the rest carried into the disclosed list:

  • Trade-off 3's "only a statfs that answers on its own tick is named in the label" was not absolute. commitHostMemorySample returns false without replacing preGoneSample when the host read fails, so the sample's object identity was frozen and preGoneSample === issuedFor still held after intervening ticks — a statfs issued at t=0 and resolving at t=25 s shipped available-commit-volume-cotimed beside SwapVolumeAgeMs: 25000. Bounded (that label asserts no verdict since round 4) and near-zero field probability (GlobalMemoryStatusEx effectively never fails), but the invariant was wrong. Fixed rather than disclosed, because it is four lines: co-timing is now a monotonic tick counter bumped by every call to samplePreGoneSystemMemory. Revert K above.
  • The evidence block said oxfmt --check <the four changed files> while the diff has 8. Fixed; all 8 are clean.

Round 6 — clean. Re-reviewed HEAD (7cd14bdbedf) with no new blocking findings, which is what "converged" means here. No commit followed it; the only change since round 5 is this description.

Accepted as disclosed limitations — NOT fixed

These are open in the shipped code. They were judged not worth the change they would cost, and each is stated in Trade-offs or the What section as well.

  1. One never-resolving statfs disables volume sampling for the process lifetime. swapVolumeReadInFlight has no timeout and is cleared only by the test-reset helper. Who carries it: any win32 or darwin user whose swap volume hangs (dead network mount as SystemRoot, a wedged filer). Residual risk: their crash reports lose the volume field entirely and sit at available-commit-unqualified until they restart Orca. It fails safe — the verdict degrades, it does not go wrong, and the host memory reading keeps updating — but it cannot self-heal.
  2. A persistent statfs refusal is silent. statfsSwapVolumeFreeSpace swallows the error and returns undefined forever. Who carries it: win32 users behind a locked-down ACL, AppLocker/EDR policy on C:\, or a UNC SystemRoot. Residual risk: the report shows no volume field and nothing explaining why it is missing, so an analyst cannot distinguish "not measured" from "not applicable".
  3. macOS pays a real recurring statfs for a datum no verdict reads. swapVolumeAnchor returns path.sep on darwin, so a real statfs('/') runs every 10 s for the life of the app and publishes SwapVolumeFreeMB + SwapVolume: "/", yet pressureSignal is hardcoded none on darwin and can never be upgraded by it. Who carries it: every Mac user. Residual risk: a permanent background syscall bought for human-readable context only. Kept because macOS swapfiles genuinely do grow into /, so the number is honest context for a darwin OOM; dropping it would remove data, not a wrong claim.
  4. available-commit-hard-capped infers "no pagefile" from swapTotal <= total, where total is ullTotalPhys while the commit limit's RAM contribution is ~1-2% lower for kernel reserve. A small fixed pagefile inside that gap also gets the label. The downstream conclusion ("this floor cannot heal") holds for a fixed pagefile too, so it is naming imprecision, not a wrong verdict. Tightening it needs the pagefile maximum — follow-up 4.
  5. The wiring test does not pin the word "unconditionally". Inserting if (is.dev) { return } immediately before the call keeps it green (deletion, if (!is.dev)-guarding, commenting out, and sibling-export moves in both placements all go red — revert J above). Closing it needs a source-grep for preceding early returns, which would fire on unrelated refactors. Residual risk: a future refactor could add an early return above the arm point and ship an inert sampler.
  6. startPreGoneCrashSampling() sits after several awaits in initializeReadyRuntimeServices (main-process-ready-runtime.ts:128), so a rejection anywhere earlier leaves the sampler unarmed and every crash report loses its only live host reading. This is the exact position the pre-existing startPreGoneProcessMetricsSampling() already occupied, so moving it is a change to shared startup ordering rather than a fix to this branch, and it is not a regression. Left alone deliberately.
  7. The Windows fallback anchor is drive-relative, not a volume root. With SystemRoot unset, swapVolumeAnchor falls back to SystemDrive and path.win32.parse('C:').root is 'C:', so statfs('C:') resolves against the current directory on that drive. SystemRoot is normally set and failure degrades to undefined; impact is low. Relatedly, volumeLabel('/') returns "/", which reads oddly against that field's own "separator-trimmed so redaction sees no path" comment (harmless — a bare separator is not a path).
  8. A refusal shorter than 10 s stays invisible, and the whole hypothesis is unproven — see "Claims NOT proven" above.

Rebutted, not fixed (2)

  • "Reuse host-memory.ts:86's memory_pressure -Q to close the darwin gap." Declined with evidence. That reader is reached only through on-demand paths (memory:getSnapshot IPC and one PTY foreground-process read); there is no periodic snapshot, so there is no cached value to reuse for free (grep setInterval src/main/memory/*.ts is empty — the reviewer verified this half of the rebuttal independently). Adopting it means spawning /usr/bin/memory_pressure on a main-process timer for the app's lifetime, and its module-global support latch is shared with the memory UI. One statfs per 10 s is microseconds and no process; a subprocess spawn per tick is not. The reviewer conceded the tradeoff is arguable; what was not acceptable was shipping the gap silently, so darwin now ships PressureSignal: 'none' in the data itself.
  • "Two test files duplicate the electron mock." Declined: vi.mock is hoisted per file and cannot be shared without a setup module; this directory already has 26 focused test files that each re-declare it.

Follow-ups

  1. Attribute the unattributed outside-heap memory. 19 highwater profiles put a median 532 MB (min 393, max 1168) of renderer footprint outside V8 and Blink with zero attribution to any Orca subsystem the renderer can count. terminals.estBufferKB is refuted as the grower (r = −0.08; the profile with 74.5 MB of buffers sits 12th of 19 on outside-heap, while the largest at 1178 MB holds 4.6 MB). Closing this needs something the renderer does not have today — performance.measureUserAgentSpecificMemory() breakdown, or GPU/canvas-mapped accounting.
  2. Fix the highwater census arming rule. It never armed for a single member of this cluster: renderer-memory-sampling.ts:18 arms at 60%/80% of the heap limit and :27 at 600/1000 MB private, while these sessions peak at 3.9% and 475 MB. emittedPrivateHighwaterMarks is also a session-lifetime one-shot, so a mark crossed hours earlier is spent and the crash-adjacent state is never profiled.
  3. outsideHeapMB is systematically over-reported. renderer-memory-sampling.ts:134-145 excludes V8's committed-but-unused reserve (totalHeap − usedHeap), median 53 MB here, ~9% of the reported figure. Also, the privateMB ≥ 600 trigger guarantees outside-heap looks like most of privateMB in any profile that fires with a small heap — a property of the trigger, not only of the leak.
  4. Pagefile maximum size is still unread. It would settle "can this pagefile grow at all" outright, but it needs a registry read, and docs/reference/windows-edr-posture.md rules out per-operation interpreter spawning for telemetry. Needs a native or non-spawning path.
  5. Correlate the pre-kill renderer stall with the freeze clusters. fbccd7fb shows a 180 s gap with no renderer_memory sample from either renderer 38 s before the OOM; 4d7e28ee shows a 242 s gap with no spans of any kind. A stalled main thread immediately before the kill appears in 2 of 5 — it may be the same event seen from two angles.
  6. Re-triage 4d7e28ee as an external tree-kill, not a renderer OOM, once the "record our own tree-kill invocations" follow-up lands. External vs self tree-kill is byte-identical in the reports today.
  7. A refusal shorter than 10 s remains invisible. If the next batch still cannot decide the cluster, the next step is an allocation-failure hook rather than a faster poll.

…t present

Round-1 review said the shipped field set could not decide G4-oom. Fixed.

Decisive field (blocking #1). The investigation's own win-lowspec repro
falsified "low available commit kills": at a 127 MB commit floor Windows grew
the pagefile to 2029 MB and nothing died, and it named the missing datum —
pagefile-growth headroom / system-drive free space. `getSystemMemoryInfo()`
gives neither. Added `swap-volume-free-space.ts`: one `fs.statfs` on the volume
backing the pagefile (SystemRoot on Windows, the root fs elsewhere, resolved
via `path.parse().root`), published as `systemMemoryPreGoneSwapVolumeFreeMB`.
Together with the already-emitted commit limit that separates "commit was low"
from "commit was refused". Pagefile *max* size needs a registry read; skipped
deliberately — per-operation interpreter spawning is exactly what
docs/reference/windows-edr-posture.md says not to add for telemetry.

Darwin honesty (blocking #2). Every reading now carries
`systemMemoryPressureSignal`: `available-commit` on Windows (swapFree is
ullAvailPageFile), `mem-available` on Linux when MemAvailable is present,
`none` otherwise — which is always on darwin. A future analyst cannot now table
`freeMB: 272` from a healthy Mac as evidence of exhaustion, because the same
record says the platform gave no pressure verdict. Partial rebuttal on the
suggested reuse: `host-memory.ts:86` was considered and rejected as a periodic
source. It spawns `/usr/bin/memory_pressure` per call, and the sampler this PR
needs runs every 10 s for the app's lifetime; a subprocess at that cadence is
worse than the gap it closes. The reviewer conceded this tradeoff is arguable —
what was not acceptable was shipping the darwin gap silently, so it is now in
the data, not only in a comment.

Staleness (blocking #3). Confirmed the measurement: four of five G4 reports
carried a ~37 s-old sample (4872/36796/37332/38017/39715 ms). Host memory no
longer rides the 60 s process-metrics sweep; `pre-gone-host-memory.ts` samples
it on its own 10 s timer with its own `systemMemoryPreGoneSampleAgeMs`. One
GlobalMemoryStatusEx-class call plus one statfs is cheap enough at that rate. A
refusal shorter than the interval stays invisible and the module comment says
so — no polling cadence fixes that.

Non-blocking, all taken: renamed `gone-time-system-memory.ts` ->
`system-memory-details.ts` with the now-false "reads AFTER the crash" framing
scoped to the gone-time caller; pre-gone host keys moved out of the
`processMetrics` namespace to `systemMemoryPreGone*`, so the string-surgery
`preGoneDetailKey` helper is gone and a `systemMemory` prefix scan sees both
reads; the bare catch no longer spans both halves of the sample, and a test
pins that a throwing host read leaves the process-metric sample intact; the
inert second test is replaced by three that go red without this change
(verified: swap-volume, pressure-signal and cadence assertions all fail when
the production hunks are reverted).

Rebuttal, non-blocking #5 (duplicated electron mock across two test files):
declined. `vi.mock` is hoisted per file, so the mock cannot be shared without a
setup module, and this directory already has 26 focused test files that each
re-declare it. Splitting by concern is the local convention.

`startPreGoneProcessMetricsSampling` is renamed `startPreGoneCrashSampling`
since it now starts two samplers.
…the host read

Round-2 review blocked on four items. All four addressed.

WHAT THIS BRANCH ACTUALLY DOES, AT HEAD (blocking #4). The commit-1 message
("13 lines, 1 production file, no new module, new optional numeric fields
only", `processMetricsPreGoneSystemMemory*` keys, a `preGoneDetailKey` helper,
a `pre-gone-system-memory.test.ts`) describes a superseded revision; every one
of those claims is false now, so it must not be used as the PR description.
The change against origin/main is: 3 new production modules
(`pre-gone-host-memory.ts`, `system-memory-details.ts`,
`swap-volume-free-space.ts`), 1 deleted (`gone-time-system-memory.ts`), plus
edits to `process-gone-diagnostics.ts` and `main-process-ready-runtime.ts` and
2 test files. It adds a second main-process interval timer that runs for the
life of the app: every 10 s one synchronous GlobalMemoryStatusEx-class read,
and on win32/darwin one `fs.statfs` on the swap-backing volume. Details are
`systemMemoryPreGone*`, and two of them are STRINGS, not numbers:
`systemMemoryPreGonePressureSignal` (enum) and `systemMemoryPreGoneSwapVolume`
(a drive label, separator-trimmed so it is not a path). Both are assigned after
`sanitizeCrashReportDetails`; neither carries user content.

Arming is now tested (blocking #1). The reviewer deleted
`startPreGoneSystemMemorySampling(...)` from `startPreGoneCrashSampling` and
all 264 tests stayed green — confirmed and fixed. `pre-gone-host-memory.test.ts`
now calls `startPreGoneCrashSampling()` with production defaults and asserts
both `setInterval` calls, their literal periods `[60_000, 10_000]`, that both
timers are unref'd, and that advancing 10 s takes a fresh host sample that
reaches `buildProcessGoneCrashDetails` with `SampleAgeMs: 0`. Verified red on
revert: deleting the arming line -> 1 failure; changing the interval constant
to 30_000 -> 1 failure (the old assertion compared the constant to itself and
caught neither). The tautological `10_000 < 60_000 / 2` test is gone,
superseded by this one.

Swap volume is win32/darwin only (blocking #2). On Linux swap is a fixed
partition, a fixed-size swapfile, or zram; none grow into root-fs free space,
so `SwapVolumeFreeMB: 380000` beside `SwapFreeMB: 0` would have invited exactly
the wrong verdict on the two Linux cluster members. `swapVolumeAnchor` returns
undefined off win32/darwin, so no field and no statfs at all. The comment
claiming "elsewhere swap is on the root fs" was wrong and is gone. The Windows
anchor is still the DEFAULT pagefile volume, so the measured volume now ships
with the number (`systemMemoryPreGoneSwapVolume: 'C:'`) instead of being
implied. The honesty label covers it: win32 reads `available-commit` only when
the volume datum is present, and `available-commit-unqualified` otherwise —
which also fixes non-blocking #5, where the synchronous gone-time read claimed
a verdict its own fields could not support.

Host read no longer waits on statfs (blocking #3). `samplePreGoneSystemMemory`
now commits the synchronous memory reading first and merges volume free space
in afterwards, so the cadence is 10 s regardless of disk-metadata latency and a
hung volume can no longer stop host sampling — precisely the paging-storm case
this exists for. The in-flight latch now guards only the statfs. Verified red
on revert to the serialized shape (2 failures). A stale-but-slow-moving volume
value merging into a newer memory sample is deliberate and commented.

Non-blocking #3 (reset does not invalidate an in-flight sample): fixed with a
generation counter bumped by `resetPreGoneSystemMemorySamplingForTest`, so a
late statfs cannot repopulate a reset sample. Separately, the volume read now
only runs after a host sample committed, which removes the real `statfs('/')`
side effect from `process-gone-diagnostics.test.ts` entirely.

REBUTTAL, darwin `memory_pressure` reuse (non-blocking #2): declined, with
evidence. `readDarwinAvailableMemory` at src/main/memory/host-memory.ts:87 is
reached only via `collectHostMemory` <- `runSnapshot` <- `collectMemorySnapshot`,
whose only callers are the `memory:getSnapshot` IPC handler and
orca-runtime-pty-foreground-process-reads.ts:170 — both on demand. There is no
periodic snapshot, so there is no cached reading to reuse for free; adopting it
means spawning `/usr/bin/memory_pressure` on a main-process timer for the life
of the app, and its module-global `darwinAvailabilitySupported` latch is shared
with the memory UI. The gap is not hidden: darwin ships
`PressureSignal: 'none'` in the data, and the module comment now cites the
existing reader and why it is not used here rather than claiming Orca lacks
one.

Verified: `vitest src/main/crash-reporting src/main/startup src/main/memory` =
769 passed / 6 skipped (crash-reporting re-run 5x, no flake);
`tsc --noEmit -p config/tsconfig.node.json` 0; `oxlint` 0; `oxfmt --check` 0.
@coderabbitai

coderabbitai Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change replaces gone-time system memory capture with pre-gone host sampling. It adds platform-aware system memory details and swap-volume free-space reporting. A separate 10-second sampler caches host readings and asynchronously enriches them with volume data. Process-gone crash details now include current and pre-gone memory data. Startup uses the renamed sampling API. Tests cover platform signals, timer behavior, asynchronous reads, failure handling, and detail-key isolation.

Merge Risk: 🔵 Low · up to 9105b

This diagnostic change adds pre-exit host memory data to crash reports, but Windows reports may overstate available commit capacity when a pagefile is located on another volume. The impact is limited to crash-diagnostic interpretation.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description provides detailed ELI5, change rationale, testing evidence, trade-offs, limitations, and follow-ups. However, it omits required template items, including a linked issue under "Linked I… Add a valid linked issue after Fixes #. Add a Visual Proof section containing exactly N/A and a brief reason because there is no UI or interaction change. Add or complete the Testing, AI Disclosure, Review, Agent skill upstream boundary…
✅ Passed checks (3 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 and concisely describes the main change: sampling system memory before the process exits.
Full details: Description check

Explanation

The description provides detailed ELI5, change rationale, testing evidence, trade-offs, limitations, and follow-ups. However, it omits required template items, including a linked issue under "Linked Issue", the exact N/A Visual Proof statement with a reason, and the required checklist sections.

Resolution

Add a valid linked issue after Fixes #. Add a Visual Proof section containing exactly N/A and a brief reason because there is no UI or interaction change. Add or complete the Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections, including the required test and validation status.

  • Fix all pre-merge checks with AI
✨ 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: Team

Run ID: 1964b8a9-eb9a-472d-9e31-645ba9c3ca80

📥 Commits

Reviewing files that changed from the base of the PR and between 720c329 and 9105ba1.

📒 Files selected for processing (8)
  • src/main/crash-reporting/gone-time-system-memory.ts
  • src/main/crash-reporting/pre-gone-host-memory.test.ts
  • src/main/crash-reporting/pre-gone-host-memory.ts
  • src/main/crash-reporting/process-gone-diagnostics.test.ts
  • src/main/crash-reporting/process-gone-diagnostics.ts
  • src/main/crash-reporting/swap-volume-free-space.ts
  • src/main/crash-reporting/system-memory-details.ts
  • src/main/startup/main-process-ready-runtime.ts
💤 Files with no reviewable changes (1)
  • src/main/crash-reporting/gone-time-system-memory.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.

[`${SYSTEM_MEMORY_KEY_PREFIX}SwapVolumeFreeMB`]: volume.freeMB,
[`${SYSTEM_MEMORY_KEY_PREFIX}SwapVolume`]: volume.volume
}
merged[`${SYSTEM_MEMORY_KEY_PREFIX}PressureSignal`] = pressureSignal(platform, merged)

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep the Windows pressure signal unqualified until the pagefile volume is known.

Line 129 sets available-commit when the sampler measures SystemRoot or SystemDrive. That is only the default pagefile volume. A relocated pagefile can lack growth space while the measured volume has free space. This makes systemMemoryPressureSignal assert a qualified condition that was not established.

Keep available-commit-unqualified unless the reader identifies an active growable pagefile volume. Update the related assertion in src/main/crash-reporting/pre-gone-host-memory.test.ts.

Proposed fix
-  merged[`${SYSTEM_MEMORY_KEY_PREFIX}PressureSignal`] = pressureSignal(platform, merged)
+  // The measured default volume does not prove the active pagefile location.
+  merged[`${SYSTEM_MEMORY_KEY_PREFIX}PressureSignal`] = pressureSignal(platform, details)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
merged[`${SYSTEM_MEMORY_KEY_PREFIX}PressureSignal`] = pressureSignal(platform, merged)
// The measured default volume does not prove the active pagefile location.
merged[`${SYSTEM_MEMORY_KEY_PREFIX}PressureSignal`] = pressureSignal(platform, details)

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Live pre-gone host-memory sampler — pre-gone-host-memory.ts adds an unref'd 10 s interval that commits the synchronous process.getSystemMemoryInfo() read before awaiting the volume statfs, publishing systemMemoryPreGone* details plus a sample-age field. The in-flight latch and samplingGeneration guard keep a slow/hung statfs from stalling or corrupting the cheap host read.
  • Swap-volume free space — swap-volume-free-space.ts measures the volume the pagefile/swapfile grows into (win32 via SystemRoot/SystemDrive root, darwin via /), emitted as systemMemoryPreGoneSwapVolumeFreeMB + the measured drive label. Linux is deliberately excluded.
  • Pressure-signal taxonomy — system-memory-details.ts (renamed from gone-time-system-memory.ts) tags every reading with systemMemoryPressureSignal (available-commit / available-commit-unqualified / mem-available / none), upgraded from -unqualified once the volume datum merges in.
  • Startup arming — startPreGoneProcessMetricsSampling becomes startPreGoneCrashSampling, arming both samplers; buildProcessGoneCrashDetails appends the pre-gone host details.

The rename is clean (no stale references to getSystemMemoryAtGoneDetails, startPreGoneProcessMetricsSampling, or gone-time-system-memory), the platform semantics match Electron's SystemMemoryInfo surface (swapTotal/swapFree win32/linux only, available linux, fileBacked/purgeable darwin), the new string fields are fixed-enum or drive-label values with no user content, and the tests assert literal interval values and exact counts (not tautologies). Verified: 690 tests pass across src/main/crash-reporting/ and src/main/startup/; oxlint clean.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Round-3 adversarial review, 2 blocking. Both fixed with mutation-verified
tests.

1. `mergeSwapVolumeFreeSpace` merged the volume reading into whatever sample
   was current at RESOLUTION time, and `pressureSignal` then upgraded win32
   from `available-commit-unqualified` to the decisive `available-commit` on
   the strength of it. The `swapVolumeReadInFlight` latch makes every
   intervening tick skip the merge, so the lag is as old as the last STARTED
   statfs, not the last tick — and no age field exposed it, because
   `systemMemoryPreGoneSampleAgeMs` describes only the synchronous memory read.

   Reviewer's executed scenario: a statfs issued at t=0 on a healthy host
   (40 GB free) resolving at t=20 s of commit pressure emitted
   `SwapFreeMB: 200` beside `SwapVolumeFreeMB: 40000`, labelled
   `available-commit`, with `SampleAgeMs: 0`. That reads as "the pagefile had
   room, so this was not a commit refusal" — the opposite conclusion, wearing
   the branch's highest-confidence label, on exactly the win32 G4-oom reports
   this exists to decide.

   The datum still ships (it is the only pagefile-expandability signal there
   is), but now:
   - the sample carries `swapVolumeSampledAtMs` — the tick that ISSUED the
     statfs, never the one it resolved on — surfaced as
     `systemMemoryPreGoneSwapVolumeAgeMs`;
   - only a statfs that answers on its own tick may qualify the verdict.
     `withSwapVolumeFreeSpace` takes `coTimed`; false keeps
     `available-commit-unqualified`.
   The next tick issues a fresh statfs, so the verdict recovers on its own.

2. The branch's sole production entry point — `startPreGoneCrashSampling()` at
   main-process-ready-runtime.ts:128 — was untested. Deleting it left 691
   tests across crash-reporting/ and startup/ green, while a comment in the
   new test file claimed that gap was why the test was written. This is pure
   instrumentation, so that one line is the whole of its value in the shipped
   app. Added a source-level wiring test (the pattern this repo already uses
   for arm-once ready-phase lines) that pins the import, exactly one call, the
   call at statement indent, and that `main-process-ready.ts` awaits the
   function it lives in. The misleading comment is gone.

Mutation-verified — each goes red alone:
  coTimed -> always true                     1 failed (verdict)
  drop swapVolumeSampledAtMs age             1 failed (verdict test)
  delete startPreGoneCrashSampling()         1 failed (wiring)
  wrap it in `if (!is.dev) { ... }`          1 failed (wiring)

Verified: tsc -p config/tsconfig.node.json exit 0; oxlint
src/main/crash-reporting src/main/startup exit 0; 268 tests in
crash-reporting/ pass. Across crash-reporting/ + startup/ + memory/: 769
passed, 2 failed — both environment-dependent and failing identically on the
unmodified tree (Xvfb rebind, and a whole-repo glob census that times out).

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Co-timed verdict gating — mergeSwapVolumeFreeSpace now captures issuedFor = preGoneSample before the await, then computes coTimed = preGoneSample === issuedFor, so a statfs that outlived the tick that issued it can no longer promote the win32 verdict past available-commit-unqualified.
  • Per-sample volume age — the sample now stamps swapVolumeSampledAtMs (the tick that issued the statfs, never the one it resolved on) and preGoneSystemMemoryDetails publishes systemMemoryPreGoneSwapVolumeAgeMs, so an out-of-band volume read carries its own staleness instead of masquerading as fresh.
  • Regression coverage — a new test drives a hung statfs across two ticks, asserts the stale volume ships with its own age and an unqualified verdict, then asserts the next tick's co-timed read recovers to available-commit; a source-level test pins the single startPreGoneCrashSampling() arming call and its import in the ready-phase composition.

The object-identity comparison is the right tool here: commitHostMemorySample allocates a fresh sample object per successful tick, so identity change is exactly "a newer memory reading displaced the one the statfs was issued for". The stale-merge path still ships the volume datum but degrades the verdict rather than inverting it, matching the fail-safe intent from round 3. Verified: src/main/crash-reporting/ 268 tests pass, oxlint clean on the touched files.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

…lity

The win32 reading was promoted to the decisive `available-commit` whenever a
co-timed volume number merely existed, which the data cannot support: a fixed
or disabled pagefile grows into no amount of empty disk, its maximum is
unreadable here, and the measured volume is only the DEFAULT pagefile drive. A
host with 180 MB of available commit, a commit limit at RAM and 812 GB free
read as "the pagefile had room" — the opposite conclusion, under the branch's
most confident label.

The volume datum is now named for what it is (`available-commit-volume-cotimed`,
context beside the commit number), and the one decisive win32 case — a commit
limit at or below RAM, i.e. no pagefile behind it — gets its own label.

Also: carry the last volume reading onto the sample that replaces it, aged and
non-qualifying, so a statfs slower than one tick no longer makes the field
vanish from the reports it exists for; don't commit a reading whose every
memory field failed, which shipped an age and a disk-free number with no host
memory beside them; and move the startup wiring test beside the file it pins,
scoped to the ready-phase entry's own body so the call cannot satisfy it from
a sibling export nothing calls.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Split the win32 pressure signal — the single available-commit verdict is now two values: available-commit-hard-capped (commit limit at or below RAM, so no pagefile exists to grow into — the one decisive case) and available-commit-volume-cotimed (a co-timed volume datum that is context beside the commit number, never a verdict), with a new pagefileBacksCommit helper comparing swapTotal > total.
  • Carried swap-volume reading — withCarriedSwapVolume keeps a slow/hung statfs from making the swap-volume field vanish on the tick that replaces the sample: the last reading rides forward at its true swapVolumeSampledAtMs, and because it merges with coTimed = false it can never re-qualify the label.
  • Empty-reading guard — commitHostMemorySample now rejects a reading whose only key is the unconditionally-appended systemMemoryPressureSignal, so a field-less read no longer ships an age plus a disk-free figure with no memory numbers beside them.
  • Wiring test relocated and scoped — moved to src/main/startup/pre-gone-crash-sampling-wiring.test.ts beside its target, asserting the single startPreGoneCrashSampling() call inside the initializeReadyRuntimeServices body rather than a whole-file grep.

The swapTotal <= total ⟹ "no pagefile" inference matches ullTotalPageFile = RAM + pagefile semantics, degrades safely to available-commit-unqualified when either field is absent, and stays conservative the other way (a pagefile that is merely fixed-size and full still reads as unqualified, not hard-capped). Verified: 271 tests pass across src/main/crash-reporting/ plus the wiring test.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

A tick whose host read fails leaves the pre-gone sample object in place, so
the identity check still read a 25 s-late statfs as co-timed.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes — the single commit since the last review tightens the statfs co-timing guard.

  • Tick-based co-timing — mergeSwapVolumeFreeSpace now compares the statfs's issuing tick against a monotonic sampleTick (incremented on every samplePreGoneSystemMemory call, including ones whose host read fails) instead of sample-object identity. A stale statfs can no longer read as available-commit-volume-cotimed when intervening ticks left the sample object untouched.
  • Regression test — a new test drives a hung statfs across two failed host reads and asserts the verdict degrades to available-commit-unqualified with the volume's true 25 s age.

The fix is correct and matches its stated intent: sampleTick advances on every sampling call, so issuedOnTick === sampleTick holds only when the statfs resolved with no intervening tick. The resetPreGoneSystemMemorySamplingForTest path correctly leaves the counter untouched (the generation guard already blocks cross-reset merges, and monotonicity is exactly what makes the equality test sound). Verified pre-gone-host-memory.test.ts passes (12 tests).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit cc9e9ed into main Sep 4, 2026
28 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…stablyai#18356)

* fix(crash-reporting): sample system memory before the renderer dies

* fix(crash-reporting): make the pre-gone host sample decisive, not just present

Round-1 review said the shipped field set could not decide G4-oom. Fixed.

Decisive field (blocking stablyai#1). The investigation's own win-lowspec repro
falsified "low available commit kills": at a 127 MB commit floor Windows grew
the pagefile to 2029 MB and nothing died, and it named the missing datum —
pagefile-growth headroom / system-drive free space. `getSystemMemoryInfo()`
gives neither. Added `swap-volume-free-space.ts`: one `fs.statfs` on the volume
backing the pagefile (SystemRoot on Windows, the root fs elsewhere, resolved
via `path.parse().root`), published as `systemMemoryPreGoneSwapVolumeFreeMB`.
Together with the already-emitted commit limit that separates "commit was low"
from "commit was refused". Pagefile *max* size needs a registry read; skipped
deliberately — per-operation interpreter spawning is exactly what
docs/reference/windows-edr-posture.md says not to add for telemetry.

Darwin honesty (blocking stablyai#2). Every reading now carries
`systemMemoryPressureSignal`: `available-commit` on Windows (swapFree is
ullAvailPageFile), `mem-available` on Linux when MemAvailable is present,
`none` otherwise — which is always on darwin. A future analyst cannot now table
`freeMB: 272` from a healthy Mac as evidence of exhaustion, because the same
record says the platform gave no pressure verdict. Partial rebuttal on the
suggested reuse: `host-memory.ts:86` was considered and rejected as a periodic
source. It spawns `/usr/bin/memory_pressure` per call, and the sampler this PR
needs runs every 10 s for the app's lifetime; a subprocess at that cadence is
worse than the gap it closes. The reviewer conceded this tradeoff is arguable —
what was not acceptable was shipping the darwin gap silently, so it is now in
the data, not only in a comment.

Staleness (blocking stablyai#3). Confirmed the measurement: four of five G4 reports
carried a ~37 s-old sample (4872/36796/37332/38017/39715 ms). Host memory no
longer rides the 60 s process-metrics sweep; `pre-gone-host-memory.ts` samples
it on its own 10 s timer with its own `systemMemoryPreGoneSampleAgeMs`. One
GlobalMemoryStatusEx-class call plus one statfs is cheap enough at that rate. A
refusal shorter than the interval stays invisible and the module comment says
so — no polling cadence fixes that.

Non-blocking, all taken: renamed `gone-time-system-memory.ts` ->
`system-memory-details.ts` with the now-false "reads AFTER the crash" framing
scoped to the gone-time caller; pre-gone host keys moved out of the
`processMetrics` namespace to `systemMemoryPreGone*`, so the string-surgery
`preGoneDetailKey` helper is gone and a `systemMemory` prefix scan sees both
reads; the bare catch no longer spans both halves of the sample, and a test
pins that a throwing host read leaves the process-metric sample intact; the
inert second test is replaced by three that go red without this change
(verified: swap-volume, pressure-signal and cadence assertions all fail when
the production hunks are reverted).

Rebuttal, non-blocking stablyai#5 (duplicated electron mock across two test files):
declined. `vi.mock` is hoisted per file, so the mock cannot be shared without a
setup module, and this directory already has 26 focused test files that each
re-declare it. Splitting by concern is the local convention.

`startPreGoneProcessMetricsSampling` is renamed `startPreGoneCrashSampling`
since it now starts two samplers.

* fix(crash-reporting): test the arming, gate the swap volume, unblock the host read

Round-2 review blocked on four items. All four addressed.

WHAT THIS BRANCH ACTUALLY DOES, AT HEAD (blocking stablyai#4). The commit-1 message
("13 lines, 1 production file, no new module, new optional numeric fields
only", `processMetricsPreGoneSystemMemory*` keys, a `preGoneDetailKey` helper,
a `pre-gone-system-memory.test.ts`) describes a superseded revision; every one
of those claims is false now, so it must not be used as the PR description.
The change against origin/main is: 3 new production modules
(`pre-gone-host-memory.ts`, `system-memory-details.ts`,
`swap-volume-free-space.ts`), 1 deleted (`gone-time-system-memory.ts`), plus
edits to `process-gone-diagnostics.ts` and `main-process-ready-runtime.ts` and
2 test files. It adds a second main-process interval timer that runs for the
life of the app: every 10 s one synchronous GlobalMemoryStatusEx-class read,
and on win32/darwin one `fs.statfs` on the swap-backing volume. Details are
`systemMemoryPreGone*`, and two of them are STRINGS, not numbers:
`systemMemoryPreGonePressureSignal` (enum) and `systemMemoryPreGoneSwapVolume`
(a drive label, separator-trimmed so it is not a path). Both are assigned after
`sanitizeCrashReportDetails`; neither carries user content.

Arming is now tested (blocking stablyai#1). The reviewer deleted
`startPreGoneSystemMemorySampling(...)` from `startPreGoneCrashSampling` and
all 264 tests stayed green — confirmed and fixed. `pre-gone-host-memory.test.ts`
now calls `startPreGoneCrashSampling()` with production defaults and asserts
both `setInterval` calls, their literal periods `[60_000, 10_000]`, that both
timers are unref'd, and that advancing 10 s takes a fresh host sample that
reaches `buildProcessGoneCrashDetails` with `SampleAgeMs: 0`. Verified red on
revert: deleting the arming line -> 1 failure; changing the interval constant
to 30_000 -> 1 failure (the old assertion compared the constant to itself and
caught neither). The tautological `10_000 < 60_000 / 2` test is gone,
superseded by this one.

Swap volume is win32/darwin only (blocking stablyai#2). On Linux swap is a fixed
partition, a fixed-size swapfile, or zram; none grow into root-fs free space,
so `SwapVolumeFreeMB: 380000` beside `SwapFreeMB: 0` would have invited exactly
the wrong verdict on the two Linux cluster members. `swapVolumeAnchor` returns
undefined off win32/darwin, so no field and no statfs at all. The comment
claiming "elsewhere swap is on the root fs" was wrong and is gone. The Windows
anchor is still the DEFAULT pagefile volume, so the measured volume now ships
with the number (`systemMemoryPreGoneSwapVolume: 'C:'`) instead of being
implied. The honesty label covers it: win32 reads `available-commit` only when
the volume datum is present, and `available-commit-unqualified` otherwise —
which also fixes non-blocking stablyai#5, where the synchronous gone-time read claimed
a verdict its own fields could not support.

Host read no longer waits on statfs (blocking stablyai#3). `samplePreGoneSystemMemory`
now commits the synchronous memory reading first and merges volume free space
in afterwards, so the cadence is 10 s regardless of disk-metadata latency and a
hung volume can no longer stop host sampling — precisely the paging-storm case
this exists for. The in-flight latch now guards only the statfs. Verified red
on revert to the serialized shape (2 failures). A stale-but-slow-moving volume
value merging into a newer memory sample is deliberate and commented.

Non-blocking stablyai#3 (reset does not invalidate an in-flight sample): fixed with a
generation counter bumped by `resetPreGoneSystemMemorySamplingForTest`, so a
late statfs cannot repopulate a reset sample. Separately, the volume read now
only runs after a host sample committed, which removes the real `statfs('/')`
side effect from `process-gone-diagnostics.test.ts` entirely.

REBUTTAL, darwin `memory_pressure` reuse (non-blocking stablyai#2): declined, with
evidence. `readDarwinAvailableMemory` at src/main/memory/host-memory.ts:87 is
reached only via `collectHostMemory` <- `runSnapshot` <- `collectMemorySnapshot`,
whose only callers are the `memory:getSnapshot` IPC handler and
orca-runtime-pty-foreground-process-reads.ts:170 — both on demand. There is no
periodic snapshot, so there is no cached reading to reuse for free; adopting it
means spawning `/usr/bin/memory_pressure` on a main-process timer for the life
of the app, and its module-global `darwinAvailabilitySupported` latch is shared
with the memory UI. The gap is not hidden: darwin ships
`PressureSignal: 'none'` in the data, and the module comment now cites the
existing reader and why it is not used here rather than claiming Orca lacks
one.

Verified: `vitest src/main/crash-reporting src/main/startup src/main/memory` =
769 passed / 6 skipped (crash-reporting re-run 5x, no flake);
`tsc --noEmit -p config/tsconfig.node.json` 0; `oxlint` 0; `oxfmt --check` 0.

* fix(crash-reporting): stop a stale statfs qualifying the commit verdict

Round-3 adversarial review, 2 blocking. Both fixed with mutation-verified
tests.

1. `mergeSwapVolumeFreeSpace` merged the volume reading into whatever sample
   was current at RESOLUTION time, and `pressureSignal` then upgraded win32
   from `available-commit-unqualified` to the decisive `available-commit` on
   the strength of it. The `swapVolumeReadInFlight` latch makes every
   intervening tick skip the merge, so the lag is as old as the last STARTED
   statfs, not the last tick — and no age field exposed it, because
   `systemMemoryPreGoneSampleAgeMs` describes only the synchronous memory read.

   Reviewer's executed scenario: a statfs issued at t=0 on a healthy host
   (40 GB free) resolving at t=20 s of commit pressure emitted
   `SwapFreeMB: 200` beside `SwapVolumeFreeMB: 40000`, labelled
   `available-commit`, with `SampleAgeMs: 0`. That reads as "the pagefile had
   room, so this was not a commit refusal" — the opposite conclusion, wearing
   the branch's highest-confidence label, on exactly the win32 G4-oom reports
   this exists to decide.

   The datum still ships (it is the only pagefile-expandability signal there
   is), but now:
   - the sample carries `swapVolumeSampledAtMs` — the tick that ISSUED the
     statfs, never the one it resolved on — surfaced as
     `systemMemoryPreGoneSwapVolumeAgeMs`;
   - only a statfs that answers on its own tick may qualify the verdict.
     `withSwapVolumeFreeSpace` takes `coTimed`; false keeps
     `available-commit-unqualified`.
   The next tick issues a fresh statfs, so the verdict recovers on its own.

2. The branch's sole production entry point — `startPreGoneCrashSampling()` at
   main-process-ready-runtime.ts:128 — was untested. Deleting it left 691
   tests across crash-reporting/ and startup/ green, while a comment in the
   new test file claimed that gap was why the test was written. This is pure
   instrumentation, so that one line is the whole of its value in the shipped
   app. Added a source-level wiring test (the pattern this repo already uses
   for arm-once ready-phase lines) that pins the import, exactly one call, the
   call at statement indent, and that `main-process-ready.ts` awaits the
   function it lives in. The misleading comment is gone.

Mutation-verified — each goes red alone:
  coTimed -> always true                     1 failed (verdict)
  drop swapVolumeSampledAtMs age             1 failed (verdict test)
  delete startPreGoneCrashSampling()         1 failed (wiring)
  wrap it in `if (!is.dev) { ... }`          1 failed (wiring)

Verified: tsc -p config/tsconfig.node.json exit 0; oxlint
src/main/crash-reporting src/main/startup exit 0; 268 tests in
crash-reporting/ pass. Across crash-reporting/ + startup/ + memory/: 769
passed, 2 failed — both environment-dependent and failing identically on the
unmodified tree (Xvfb rebind, and a whole-repo glob census that times out).

* fix(crash-reporting): stop free disk standing in for pagefile growability

The win32 reading was promoted to the decisive `available-commit` whenever a
co-timed volume number merely existed, which the data cannot support: a fixed
or disabled pagefile grows into no amount of empty disk, its maximum is
unreadable here, and the measured volume is only the DEFAULT pagefile drive. A
host with 180 MB of available commit, a commit limit at RAM and 812 GB free
read as "the pagefile had room" — the opposite conclusion, under the branch's
most confident label.

The volume datum is now named for what it is (`available-commit-volume-cotimed`,
context beside the commit number), and the one decisive win32 case — a commit
limit at or below RAM, i.e. no pagefile behind it — gets its own label.

Also: carry the last volume reading onto the sample that replaces it, aged and
non-qualifying, so a statfs slower than one tick no longer makes the field
vanish from the reports it exists for; don't commit a reading whose every
memory field failed, which shipped an age and a disk-free number with no host
memory beside them; and move the startup wiring test beside the file it pins,
scoped to the ready-phase entry's own body so the call cannot satisfy it from
a sibling export nothing calls.

* fix(crash-reporting): co-time the statfs by tick, not sample identity

A tick whose host read fails leaves the pre-gone sample object in place, so
the identity check still read a 25 s-late statfs as co-timed.
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