From 5159eb61cb0d1d9169a514617a2c7868f286d726 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Mon, 3 Aug 2026 23:20:52 -0700 Subject: [PATCH] fix(crash-reporting): stop reporting whole-process-tree kills as renderer crashes When the OS or user kills the whole Electron tree, NetworkService and GPU emit process-gone(killed) and are correctly suppressed, then the renderer emits the same shape milliseconds later and was recorded as a genuine crash (13 false reports, F0BMK043Q2V et al). Correlate the events through a short sibling-kill window instead of widening the exit-code suppression list, so Windows exit 1 and Linux 61696 stay reportable on their own. Field offsets run -0.08s to +0.10s, so a solitary renderer kill waits for the window to settle before it persists. The suppression carries a siblingKills count on the existing process_gone_suppressed breadcrumb. Suppression is scoped to the crash *report* only. Renderer recovery still reloads: bundles F0BMQTGDEGN and F0BNCBF8Q00 show the sibling-kill shape where the reload restored the window and the same main process ran on for 37s/136s. Gating the reload there would have left a blank window with no reload, no recovery prompt, and no report, since scheduleRendererRecovery bails before arming the timer that owns the exhausted-recovery prompt. Co-authored-by: Orca --- .../process-gone-classification.test.ts | 49 ++++++++ .../process-gone-classification.ts | 17 ++- .../process-gone-recorder.test.ts | 108 ++++++++++++++++++ .../crash-reporting/process-gone-recorder.ts | 68 +++++++++-- .../process-tree-kill-window.ts | 56 +++++++++ 5 files changed, 286 insertions(+), 12 deletions(-) create mode 100644 src/main/crash-reporting/process-tree-kill-window.ts diff --git a/src/main/crash-reporting/process-gone-classification.test.ts b/src/main/crash-reporting/process-gone-classification.test.ts index 78522b76617b..7a06707ad3bb 100644 --- a/src/main/crash-reporting/process-gone-classification.test.ts +++ b/src/main/crash-reporting/process-gone-classification.test.ts @@ -336,6 +336,43 @@ describe('shouldRecordProcessGoneCrash', () => { }) ).toBe(true) }) + + it('does not report a renderer kill that shares a whole-process-tree teardown', () => { + // Windows tree kill (F0BMK043Q2V) and Linux SIGKILL (F0BMJ1PC68J) shapes. + expect( + shouldRecordProcessGoneCrash({ + source: 'renderer', + processType: 'renderer', + reason: 'killed', + exitCode: 1, + expectedTeardown: 'none', + siblingChildKills: 2 + }) + ).toBe(false) + expect( + shouldRecordProcessGoneCrash({ + source: 'renderer', + processType: 'renderer', + reason: 'killed', + exitCode: 9, + expectedTeardown: 'none', + siblingChildKills: 1 + }) + ).toBe(false) + }) + + it('keeps reporting non-killed renderer exits that coincide with child kills', () => { + expect( + shouldRecordProcessGoneCrash({ + source: 'renderer', + processType: 'renderer', + reason: 'crashed', + exitCode: 5, + expectedTeardown: 'none', + siblingChildKills: 2 + }) + ).toBe(true) + }) }) describe('shouldRecoverRendererAfterProcessGone', () => { @@ -389,4 +426,16 @@ describe('shouldRecoverRendererAfterProcessGone', () => { }) ).toBe(false) }) + + // Bundles F0BMQTGDEGN / F0BNCBF8Q00: child kills land before the renderer kill and + // the recovery reload still restored the window in the same main process. Report + // suppression must not take the reload with it. + it('still recovers a renderer kill that shares a whole-process-tree teardown', () => { + expect( + shouldRecoverRendererAfterProcessGone({ + reason: 'killed', + expectedTeardown: 'none' + }) + ).toBe(true) + }) }) diff --git a/src/main/crash-reporting/process-gone-classification.ts b/src/main/crash-reporting/process-gone-classification.ts index d3f363d13324..94926184a072 100644 --- a/src/main/crash-reporting/process-gone-classification.ts +++ b/src/main/crash-reporting/process-gone-classification.ts @@ -54,7 +54,8 @@ export function shouldRecordProcessGoneCrash({ serviceName, reason, exitCode, - expectedTeardown + expectedTeardown, + siblingChildKills = 0 }: { source: ProcessGoneSource processType?: string @@ -62,6 +63,7 @@ export function shouldRecordProcessGoneCrash({ reason: string exitCode: number | null expectedTeardown: ExpectedTeardownScope + siblingChildKills?: number }): boolean { // Why: GPU, Network Service, and Audio Service exits are recoverable Chromium // child-process churn; treating them as app crashes creates noisy user prompts. @@ -73,6 +75,12 @@ export function shouldRecordProcessGoneCrash({ if (reason !== 'killed') { return true } + // Why: when the OS or user kills the whole process tree, the Chromium children + // die the same way milliseconds from the renderer. That is teardown, not a + // renderer crash, and the exit code alone cannot tell the two apart. + if (source === 'renderer' && siblingChildKills > 0) { + return false + } // Why: Electron reports expected Chromium teardown during reload/update as // `killed` + SIGTERM or Windows control termination statuses. Treat real // crash reasons as reportable, but skip these normal termination shapes. @@ -85,6 +93,13 @@ export function shouldRecordProcessGoneCrash({ return !(source === 'renderer' && expectedTeardown === 'renderer-reload') } +// Why: deliberately ignores sibling tree kills. Suppressing a *report* on that +// signature costs one lost report; suppressing the *reload* strands the user in a +// blank window with no prompt (scheduleRendererRecovery bails synchronously, so +// the exhausted-recovery prompt never fires either). Field bundles F0BMQTGDEGN and +// F0BNCBF8Q00 show the renderer reloading and the same main process living on for +// 37s/136s after a child kill, so the reload is the only thing that recovers those. +// If the tree really is dying, the main process is gone before the 250ms timer. export function shouldRecoverRendererAfterProcessGone({ reason, expectedTeardown diff --git a/src/main/crash-reporting/process-gone-recorder.test.ts b/src/main/crash-reporting/process-gone-recorder.test.ts index 07513616046b..d9d34fb54604 100644 --- a/src/main/crash-reporting/process-gone-recorder.test.ts +++ b/src/main/crash-reporting/process-gone-recorder.test.ts @@ -14,6 +14,7 @@ import { } from './crash-breadcrumb-store' import { ProcessGoneDedupe } from './process-gone-dedupe' import { recordProcessGoneCrash, type ProcessGoneCrashEvent } from './process-gone-recorder' +import { resetProcessTreeKillWindowForTest } from './process-tree-kill-window' import { _resetTracerForTests, setActiveSink, type TracerSink } from '../observability/tracer' type CapturingSink = TracerSink & { records: unknown[]; flushMock: ReturnType } @@ -51,6 +52,7 @@ beforeEach(() => { }) afterEach(() => { + vi.useRealTimers() vi.restoreAllMocks() _resetTracerForTests() clearCrashBreadcrumbsForTest() @@ -364,3 +366,109 @@ describe('recordProcessGoneCrash', () => { await vi.waitFor(() => expect(record).toHaveBeenCalledTimes(2)) }) }) + +// Field timeline from crash bundle F0BMK043Q2V (win32 10.0.26200, 1.4.164): +// Network Service killed/1 at 22:09:38.662, GPU killed/1 at .737, renderer +// killed/1 at .746 — one `taskkill` of the tree reported as a renderer crash. +describe('recordProcessGoneCrash whole-process-tree kills', () => { + const networkServiceKill = event({ + source: 'child', + processType: 'Utility', + reason: 'killed', + exitCode: 1, + details: { + name: 'Network Service', + serviceName: 'network.mojom.NetworkService', + type: 'Utility' + } + }) + const gpuKill = event({ + source: 'child', + processType: 'GPU', + reason: 'killed', + exitCode: 1, + details: { serviceName: 'GPU', type: 'GPU' } + }) + const rendererKill = event({ reason: 'killed', exitCode: 1 }) + + beforeEach(() => { + resetProcessTreeKillWindowForTest() + }) + + it('does not report the renderer kill when the children died first', () => { + const record = vi.fn().mockResolvedValue({ id: 'report-1' }) + const dedupe = new ProcessGoneDedupe() + const nowSpy = vi.spyOn(Date, 'now') + + nowSpy.mockReturnValue(1_785_708_578_662) + recordProcessGoneCrash({ record } as never, networkServiceKill, dedupe) + nowSpy.mockReturnValue(1_785_708_578_737) + recordProcessGoneCrash({ record } as never, gpuKill, dedupe) + nowSpy.mockReturnValue(1_785_708_578_746) + recordProcessGoneCrash({ record } as never, rendererKill, dedupe) + + expect(record).not.toHaveBeenCalled() + expect(getCrashBreadcrumbSnapshot()).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + name: 'process_gone_suppressed', + data: expect.objectContaining({ source: 'renderer', siblingKills: 2 }) + }) + ]) + ) + }) + + // Field timeline from crash bundle F0BMVQ3640H: renderer killed/1 first, then + // Network Service +5ms and GPU +41ms — the same tree kill, opposite order. + it('does not report the renderer kill when the children died right after', async () => { + const record = vi.fn().mockResolvedValue({ id: 'report-1' }) + const dedupe = new ProcessGoneDedupe() + vi.useFakeTimers() + vi.setSystemTime(1_785_818_589_464) + + recordProcessGoneCrash({ record } as never, rendererKill, dedupe) + vi.advanceTimersByTime(5) + recordProcessGoneCrash({ record } as never, networkServiceKill, dedupe) + vi.advanceTimersByTime(36) + recordProcessGoneCrash({ record } as never, gpuKill, dedupe) + await vi.advanceTimersByTimeAsync(250) + + expect(record).not.toHaveBeenCalled() + expect(getCrashBreadcrumbSnapshot()).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + name: 'process_gone_suppressed', + data: expect.objectContaining({ source: 'renderer', siblingKills: 2 }) + }) + ]) + ) + }) + + it('still reports a solitary renderer kill once the sibling window settles', async () => { + const record = vi.fn().mockResolvedValue({ id: 'report-1' }) + vi.useFakeTimers() + + // Linux exit 61696 self-recovers with no child kills; it must stay reportable. + recordProcessGoneCrash( + { record } as never, + event({ reason: 'killed', exitCode: 61696 }), + new ProcessGoneDedupe() + ) + expect(record).not.toHaveBeenCalled() + await vi.advanceTimersByTimeAsync(250) + + expect(record).toHaveBeenCalledOnce() + }) + + it('ignores child kills that died with a different exit code', async () => { + const record = vi.fn().mockResolvedValue({ id: 'report-1' }) + const dedupe = new ProcessGoneDedupe() + vi.useFakeTimers() + + recordProcessGoneCrash({ record } as never, gpuKill, dedupe) + recordProcessGoneCrash({ record } as never, event({ reason: 'killed', exitCode: 9 }), dedupe) + await vi.advanceTimersByTimeAsync(250) + + expect(record).toHaveBeenCalledOnce() + }) +}) diff --git a/src/main/crash-reporting/process-gone-recorder.ts b/src/main/crash-reporting/process-gone-recorder.ts index 9725e7bdad91..7afd858fd2db 100644 --- a/src/main/crash-reporting/process-gone-recorder.ts +++ b/src/main/crash-reporting/process-gone-recorder.ts @@ -25,6 +25,11 @@ import { processGoneDedupe, type ProcessGoneDedupe } from './process-gone-dedupe' +import { + countSiblingProcessTreeKills, + observeProcessGoneKill, + PROCESS_TREE_KILL_SETTLE_MS +} from './process-tree-kill-window' import { getMainProcessLifecycleIdentity } from './main-process-lifecycle-identity' import { flushActiveSink, startSpan } from '../observability/tracer' @@ -75,6 +80,23 @@ function persistFailureData(event: ProcessGoneCrashEvent, error: unknown) { } } +function recordSuppressedProcessGone(event: ProcessGoneCrashEvent, siblingKills: number): void { + // Why: Chromium can crash-loop a recoverable child (network service seen at + // 1459/min) and each suppressed event costs a span plus a forced disk flush, + // which both floods the 30-entry ring and evicts the real pre-crash trail. + const suppressedData = processGoneBreadcrumbData(event) + recordCoalescedDurableCrashBreadcrumb({ + name: 'process_gone_suppressed', + data: siblingKills > 0 ? { ...suppressedData, siblingKills } : suppressedData, + coalesceKey: suppressedProcessGoneCoalesceKey(suppressedData), + minIntervalMs: SUPPRESSED_PROCESS_GONE_COALESCE_MS + }) +} + +function siblingProcessTreeKillCount(event: ProcessGoneCrashEvent): number { + return countSiblingProcessTreeKills({ reason: event.reason, exitCode: event.exitCode }) +} + export function recordProcessGoneCrash( store: CrashReportRecorderStore | null, event: ProcessGoneCrashEvent, @@ -83,6 +105,15 @@ export function recordProcessGoneCrash( if (!isCrashReportReason(event.reason)) { return } + if (event.reason === 'killed') { + observeProcessGoneKill({ + at: Date.now(), + source: event.source, + reason: event.reason, + exitCode: event.exitCode + }) + } + const siblingKills = siblingProcessTreeKillCount(event) if ( !shouldRecordProcessGoneCrash({ source: event.source, @@ -91,21 +122,36 @@ export function recordProcessGoneCrash( typeof event.details.serviceName === 'string' ? event.details.serviceName : undefined, reason: event.reason, exitCode: event.exitCode, - expectedTeardown: event.expectedTeardown + expectedTeardown: event.expectedTeardown, + siblingChildKills: siblingKills }) ) { - // Why: Chromium can crash-loop a recoverable child (network service seen at - // 1459/min) and each suppressed event costs a span plus a forced disk flush, - // which both floods the 30-entry ring and evicts the real pre-crash trail. - const suppressedData = processGoneBreadcrumbData(event) - recordCoalescedDurableCrashBreadcrumb({ - name: 'process_gone_suppressed', - data: suppressedData, - coalesceKey: suppressedProcessGoneCoalesceKey(suppressedData), - minIntervalMs: SUPPRESSED_PROCESS_GONE_COALESCE_MS - }) + recordSuppressedProcessGone(event, siblingKills) return } + if (event.source === 'renderer' && event.reason === 'killed') { + // Why: a tree kill can reach the renderer ~100ms before its children, so let + // the sibling window settle rather than persisting a report the next child + // event would have retracted. + const settleTimer = setTimeout(() => { + const settledSiblingKills = siblingProcessTreeKillCount(event) + if (settledSiblingKills > 0) { + recordSuppressedProcessGone(event, settledSiblingKills) + return + } + persistProcessGoneCrash(store, event, dedupe) + }, PROCESS_TREE_KILL_SETTLE_MS) + settleTimer.unref?.() + return + } + persistProcessGoneCrash(store, event, dedupe) +} + +function persistProcessGoneCrash( + store: CrashReportRecorderStore | null, + event: ProcessGoneCrashEvent, + dedupe: ProcessGoneDedupe +): void { if (!store) { recordDurableCrashBreadcrumb( 'crash_report_store_unavailable', diff --git a/src/main/crash-reporting/process-tree-kill-window.ts b/src/main/crash-reporting/process-tree-kill-window.ts new file mode 100644 index 000000000000..35a2a5ad0552 --- /dev/null +++ b/src/main/crash-reporting/process-tree-kill-window.ts @@ -0,0 +1,56 @@ +import type { ProcessGoneSource } from './process-gone-classification' + +// Why: an OS/user kill of the whole Electron tree (taskkill /T, session logout, +// a supervisor SIGKILL) reaches the Chromium children and the renderer as +// independent process-gone events; correlating them is the only way to tell that +// teardown apart from a renderer that died on its own. +export const PROCESS_TREE_KILL_WINDOW_MS = 2_000 + +// Field offsets between the first and last event of one tree kill run -0.08s to +// +0.10s, so the renderer can arrive before its children; wait this long before +// deciding a renderer kill was solitary. +export const PROCESS_TREE_KILL_SETTLE_MS = 250 + +// Why: one tree kill produces a handful of events; a deeper ring would only let a +// pre-existing child crash loop outlive the correlation window. +const MAX_TRACKED_KILLS = 16 + +type TrackedKill = { + at: number + source: ProcessGoneSource + exitCode: number | null + reason: string +} + +let trackedKills: TrackedKill[] = [] + +export function observeProcessGoneKill(kill: TrackedKill): void { + trackedKills.push(kill) + if (trackedKills.length > MAX_TRACKED_KILLS) { + trackedKills = trackedKills.slice(-MAX_TRACKED_KILLS) + } +} + +/** How many Chromium child processes died the same way inside the window — the + * signature of the whole tree going down rather than one process failing. */ +export function countSiblingProcessTreeKills({ + reason, + exitCode, + at = Date.now() +}: { + reason: string + exitCode: number | null + at?: number +}): number { + return trackedKills.filter( + (kill) => + kill.source === 'child' && + kill.reason === reason && + kill.exitCode === exitCode && + Math.abs(at - kill.at) <= PROCESS_TREE_KILL_WINDOW_MS + ).length +} + +export function resetProcessTreeKillWindowForTest(): void { + trackedKills = [] +}