From 4e8c023a5505d1cacd8acc7ca343f3b3cff7c04e Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sun, 31 May 2026 06:50:34 -0700 Subject: [PATCH] fix: bound submitted crash report ids (#4172) --- src/main/ipc/crash-reporting.test.ts | 24 ++++++++++++++++++++ src/main/ipc/crash-reporting.ts | 33 +++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/main/ipc/crash-reporting.test.ts b/src/main/ipc/crash-reporting.test.ts index 2a1f59e57..5049f64c2 100644 --- a/src/main/ipc/crash-reporting.test.ts +++ b/src/main/ipc/crash-reporting.test.ts @@ -24,6 +24,7 @@ vi.mock('./feedback', () => ({ })) import { + _getCrashReportingStateSizesForTests, _resetRendererErrorReportDedupeForTests, registerCrashReportingHandlers } from './crash-reporting' @@ -221,6 +222,29 @@ describe('registerCrashReportingHandlers', () => { expect(markSent).not.toHaveBeenCalled() }) + it('bounds submitted report ids by evicting the oldest successful sends', async () => { + registerCrashReportingHandlers({ + getById: vi.fn(async (reportId: string) => report('pending', reportId)), + dismiss: vi.fn(), + markSent: vi.fn(async (reportId: string) => report('sent', reportId)), + markDismissedSent: vi.fn(), + listRecent: vi.fn(async () => []), + record: vi.fn(), + formatDiagnosticText: vi.fn() + } as never) + + for (let i = 0; i < 260; i += 1) { + await handlers.get('crashReports:submit')?.(null, { + reportId: `crash-${i}`, + submitAnonymously: true, + githubLogin: null, + githubEmail: null + }) + } + + expect(_getCrashReportingStateSizesForTests().submittedReportIds).toBe(256) + }) + it('records a deduped renderer error boundary report through the crash store', async () => { const recorded = report('pending', 'react-render') const recordMock = vi.fn(async () => recorded) diff --git a/src/main/ipc/crash-reporting.ts b/src/main/ipc/crash-reporting.ts index c96953222..6e289e645 100644 --- a/src/main/ipc/crash-reporting.ts +++ b/src/main/ipc/crash-reporting.ts @@ -1,3 +1,5 @@ +/* oxlint-disable max-lines -- Why: crash-reporting IPC handlers share one + dedupe/submission state machine and one crash-store contract. */ import os from 'node:os' import { app, clipboard, ipcMain } from 'electron' import { @@ -18,6 +20,7 @@ const recentRendererErrorReportKeys = new Map() const RENDERER_ERROR_DEDUPE_MS = 10 * 60 * 1000 const MAX_RENDERER_ERROR_KEY_AGE_MS = RENDERER_ERROR_DEDUPE_MS * 2 const MAX_RECENT_RENDERER_ERROR_REPORT_KEYS = 256 +const MAX_SUBMITTED_REPORT_IDS = 256 const REACT_ERROR_BOUNDARY_SURFACES = new Set([ 'app-root', @@ -121,6 +124,20 @@ function getRendererErrorReportKey(args: ReactErrorBoundaryReportArgs): string { }).slice(0, 12_000) } +function rememberSubmittedReportId(reportId: string): void { + // Why: report ids are IPC input. Keep duplicate-send suppression useful for + // recent reports without retaining every id a broken renderer can vary. + submittedReportIds.delete(reportId) + submittedReportIds.add(reportId) + while (submittedReportIds.size > MAX_SUBMITTED_REPORT_IDS) { + const oldestId = submittedReportIds.keys().next().value + if (oldestId === undefined) { + break + } + submittedReportIds.delete(oldestId) + } +} + async function recordRendererErrorReport( store: CrashReportStore, args: unknown @@ -180,6 +197,20 @@ async function recordRendererErrorReport( export function _resetRendererErrorReportDedupeForTests(): void { recentRendererErrorReportKeys.clear() + submittedReportIds.clear() + inFlightSubmissions.clear() +} + +export function _getCrashReportingStateSizesForTests(): { + submittedReportIds: number + inFlightSubmissions: number + recentRendererErrorReportKeys: number +} { + return { + submittedReportIds: submittedReportIds.size, + inFlightSubmissions: inFlightSubmissions.size, + recentRendererErrorReportKeys: recentRendererErrorReportKeys.size + } } async function getLatestPendingReport( @@ -290,7 +321,7 @@ export function registerCrashReportingHandlers(store: CrashReportStore): void { if (!result.ok) { return { ...result, report } } - submittedReportIds.add(report.id) + rememberSubmittedReportId(report.id) if (report.status === 'dismissed') { try { // Why: startup prompts are dismissed before the user can send from