Files
orca/src/shared/crash-report-exit-code.ts
T
Brennan Benson 8e0dad8e21 fix(crash-reporting): decode POSIX wait statuses in crash-report display and record OS session ends (#14659)
* fix(crash-reporting): decode POSIX wait statuses for display and record Windows session-end reasons

Chromium on POSIX hands render/child-process-gone the raw waitpid() status, so
crash reports read "Exit code: 61696" where exit status 241 is meant (field:
61696=exit 241, 9=SIGKILL, 133=SIGTRAP+core, darwin crashed 5=SIGTRAP). Decode
at the display layer only: the stored exitCode stays raw, Windows codes and
launch-failed launch-error codes render unchanged, and the process-gone span
gains a crash.exit_code_decoded attribute.

Also durably record a system_session_end breadcrumb (with WindowSessionEndEvent
reasons) when Windows session-end fires, so bundles can tell OS shutdown from a
user task-kill in killed/exit-1 sweeps.

* test(crash-reporting): pin the exit(0) no-suffix rendering

Adversarial mutation review: removing the exit-0 suppression in
formatCrashReportExitCode survived the suite — nothing pinned that a clean
exit(0) renders without an '(exit status 0)' suffix.

* test(crash-reporting): decode-attribute tests use synchronous child kills

Renderer killed events gain a 250ms sibling-kill settle once the
correlation branch lands, which (a) defers the span past the test's
platform stub so the decode gate reads the real host platform, and (b)
adds a deferred span that breaks the exact sink assertion. The decode
gate is source-agnostic, and a non-recoverable child kill persists
synchronously on every branch of the stack, so coverage is unchanged and
the platform stub is deterministic on any CI host.

* fix(crash-reporting): keep session-end reasons type-safe
2026-08-16 15:45:38 -07:00

26 lines
951 B
TypeScript

import { decodePosixWaitStatus, describePosixWaitStatus } from './posix-wait-status'
/**
* Renders the exit code with its POSIX wait-status meaning ("61696 (exit status
* 241)", "9 (SIGKILL)"). The raw value always stays first. Windows codes and
* launch-failed codes are not wait statuses and render unchanged.
*/
export function formatCrashReportExitCode(report: {
exitCode: number | null
platform: NodeJS.Platform
reason: string
}): string {
if (report.exitCode === null || report.exitCode === undefined) {
return 'unknown'
}
const decoded =
report.platform === 'win32' || report.reason === 'launch-failed'
? null
: decodePosixWaitStatus(report.exitCode)
// A clean exit(0) decodes to itself; the suffix would only add noise.
if (!decoded || (decoded.kind === 'exited' && report.exitCode === 0)) {
return String(report.exitCode)
}
return `${report.exitCode} (${describePosixWaitStatus(decoded)})`
}