Crash reports

What the app knows about its own last crash. The reporting happens in a second process, because the one thing a faulting process cannot do is finish writing — so every command here either reads a file or arms a handler, and none of them runs inside a process that is already failing.

Registered by the macOS runtime as createCrashReporterPlugin({ root, guard, native }), with the app's data root and the guard it started at launch — so window.crust.invoke("crash-reporter", …) works in an app that names no plugin.

The two halves

halfwherewhat it does
the C handlersrc/platform/darwin/crash.ts, shim/111_crash.cwrites a fixed 84-byte record, then _exit(70)
the guardsrc/runtime-crash-guard.tswatches the app's pid, reads that record when the pid is gone, appends the crash

The handler may not format, allocate or measure anything — the process has already faulted — so the record is fixed-size and the reading side does all the work.

file, in the app's data directoryholds
crash-record.binmagic CRSH, i32 signal, i32 si_code, u64 address, a 64-byte NUL-padded handler name
crashes.logone JSON object per line, appended by the guard
last-crash.jsonthe most recent crash, rewritten every time

All three are created 0600, and each write chmods an existing file back to 0600 — a log an older build left world-readable is still out there, so the mode is set on both paths, not only at creation. A crash artefact carries the signal, the fault address, the handler and the app's paths, which is nobody else's business on the machine.

A crash the handler recorded always leaves exit status 70. A clean exit leaves the record empty, so the guard writes nothing.

Starting the guard

const guard = startCrashGuard({ appDataDir });

The macOS runtime makes that call itself, from nativePlugins, with the app's data directory — so an app takes no step to get crash records, and the plugin answers not-implemented naming startCrashGuard() only when that call threw. The guard is a second process polling liveness every 100 ms. It polls rather than calling waitpid, because it did not spawn the process it watches, so it cannot reap it and cannot read a wait status; the record is therefore the only trustworthy signal that an exit was a fault.

What that second process is depends on how the app runs. In a source checkout it is bun src/runtime-crash-guard.ts --guard --pid <n> --root <dir>. A compiled binary carries no readable copy of that file — import.meta.path is /$bunfs/root/crust-app there — so the guard is the app's own executable launched again with CRUST_CRASH_GUARD=<pid>, CRUST_CRASH_GUARD_ROOT=<dir> and CRUST_CRASH_GUARD_SINCE=<process start time> in its environment — --pid, --root and --since are the argv forms a hand-run guard uses. startApp reads that marker before the single-instance lock, so that launch is the guard rather than a rejected duplicate: it opens no window, binds no port and starts no second copy. The start time stops a reused pid from recording an old crash; the pid and root travel in argv as well, so ps names what a guard is watching.

Commands

commandargumentsanswer
lastnone{ crash, root } — crash is null when nothing crashed
list{ limit? }{ crashes, root }, oldest first
report{ message, stack? }{ ok: true, crash, root } — one record, written now
configure{ dir? }{ ok: true, dir, root }, or { ok: false, code: "outside-data-root" }
clearnone{ ok: false, code: "page-cannot-clear", message, root } — always a refusal
installnone{ armed, reason, record, root }
uninstallnone{ armed: false, reason }

A record is { type, signal, code, address, at, handler, exitCode }. type is "signal" for a fault the guard watched die and "webview" for an error the page caught and reported, and it is how the two halves are told apart. signal is a name such as SIGSEGV, null when the record named a signal this build does not map; code is si_code, where 1 (SEGV_MAPERR) and 2 (SEGV_ACCERR) are the two a real fault produces; address is hex, 0x0 when the kernel supplied none. A "webview" record carries message and, when the page supplied one, stack, and its signal/code/address/exitCode are null because nothing faulted.

The page's own reports

report is the other half, and the ordinary case: an onerror in a render loop never faults the process, so no guard can ever see it. The page caught the error itself, so it says so:

window.addEventListener("error", (event) => {
	window.crust.invoke("crash-reporter", "report", {
		message: event.message || "Unknown error",
		stack: event.error?.stack,
	});
});

One record lands in the same crashes.log and last-crash.json the guard writes, with the same layout, the same rotation and the same 0600, so last and list answer it with no second reader. type: "webview" is what separates it from the guard's "signal".

An over-long message or stack is truncated, never refused — losing a crash because its stack was long is the worst behaviour available. The value keeps its head and ends with … [truncated <n> chars], and the whole value still fits the cap, so a report cannot grow the record it lands in. The log keeps the newest MAX_CRASH_RECORDS (200) and drops the oldest, because a log that only grows is a leak.

configure({ dir }) repoints where records land, refused outside the app's data root — a record carries the app's own paths, so writing one wherever a page names is a containment hole, not a feature. It takes no url: Butter's plugin POSTs every crash to an endpoint, and that is a privacy decision the app makes, not one a plugin makes for it. An app that wants its reports uploaded reads them with list and sends them itself.

report and configure both need the guard, like the rest: without it they answer not-implemented naming startCrashGuard(), because a record nothing reads is not worth writing.

install arms the handlers so the next fault writes a record. uninstall restores the default disposition, so a fault is a plain fault again.

Reading, and why a page cannot clear

last and list are the page-facing way to read crashes: last is the newest record, list is every record oldest first. Neither deletes anything.

clear never deletes from a page. It answers a named refusal, because the page is the process whose bug produced the crash, so letting it erase the evidence is the wrong shape:

{
	"ok": false,
	"code": "page-cannot-clear",
	"message": "crash-reporter.clear: a page cannot delete its own crash evidence; the runtime calls clearCrashes(<root>) instead",
	"root": "<root>"
}

The runtime is the only caller that can clear, through clearCrashes(root) in src/runtime-crash-store.ts — documented there as runtime-only. A page that wants the list shorter asks its host, which is the same rule as every other write that outlives the window.

The pending record is not part of this at all: clearCrashes removes crashes.log and last-crash.json, and the guard may still read crash-record.bin.

The refusal that matters

Without a running guard, last, list and clear answer not-implemented naming startCrashGuard() — never an empty list. An empty list reads as "no crashes", which is exactly the wrong conclusion when nothing has been watching.

Without the darwin signal unit, install and uninstall answer not-implemented naming armCrashHandlers().

Limits

The guard records the fault's signal, si_code, address and handler name. It does not capture a backtrace or symbolicate: those need a debugger, and a process that has already faulted cannot start one.