oven-sh/bun · error · Error
workload "${name}" wrote an invalid trace
Error message
workload "${name}" wrote an invalid trace What it means
The trace file is large enough but its header magic/version words do not equal TRACE_MAGIC/1, so the file was not written by the current tracer. This guards against consuming stale or foreign data before trusting the address list.
Source
Thrown at scripts/orderfile/generate.ts:172
}
/** Write function starts for functrace.c: u64 magic, version, count, addresses. */
function writeStarts(path: string, addresses: number[]): void {
const buffer = new ArrayBuffer((STARTS_HEADER_WORDS + addresses.length) * 8);
const words = new BigUint64Array(buffer);
words[0] = STARTS_MAGIC;
words[1] = 1n;
words[2] = BigInt(addresses.length);
for (let i = 0; i < addresses.length; i++) words[STARTS_HEADER_WORDS + i] = BigInt(addresses[i]!);
writeFileSync(path, new Uint8Array(buffer));
}
/** Read a trace functrace.c wrote: first-entry addresses, slide already removed. */
function readTrace(path: string, name: string): number[] {
const raw = readFileSync(path);
if (raw.byteLength < TRACE_HEADER_WORDS * 8) throw new Error(`workload "${name}" wrote a truncated trace`);
const header = new BigUint64Array(raw.buffer, raw.byteOffset, TRACE_HEADER_WORDS);
if (header[0] !== TRACE_MAGIC || header[1] !== 1n) throw new Error(`workload "${name}" wrote an invalid trace`);
const count = Number(header[4]);
if (count === 0) throw new Error(`workload "${name}" recorded no entries — is the tracer loading?`);
const body = new BigUint64Array(raw.buffer, raw.byteOffset + TRACE_HEADER_WORDS * 8, count);
const out: number[] = new Array(count);
for (let i = 0; i < count; i++) out[i] = Number(body[i]);
return out;
}
export function generateOrderFile(options: GenerateOptions): { count: number; outPath: string } {
const buildDir = resolve(options.buildDir);
const outPath = resolve(options.outPath ?? join(buildDir, "linker.order"));
const minFunctions = options.minFunctions ?? MIN_FUNCTIONS;
const log = (message: string) => options.verbose && console.log(message);
const darwin = process.platform === "darwin";
if (process.platform !== "linux" && !(darwin && process.arch === "arm64")) {
throw new Error("the order file tracer builds on linux x86-64/arm64 or macOS arm64");
}View on GitHub (pinned to 8c5296ac45)
Solutions
- Delete stale trace files / clear the output directory before re-running
- Ensure each run uses a unique scratch out path (the generator already mkdtemp's its scratch)
- Rebuild the tracer from the current functrace.c so writer and reader agree on the format
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync, unlinkSync } from "node:fs";
// A pre-existing out file may carry an older format — remove it so only the current tracer writes it.
if (existsSync(outPath)) unlinkSync(outPath); Try / catch
try {
processTrace(out);
} catch (err) {
if (/invalid trace/.test(String(err))) {
unlinkSync(out); // discard stale-format file
return retryWorkload();
}
throw err;
} Prevention
- Always write traces into a fresh mkdtemp scratch dir (as generate.ts does) instead of a fixed reused path
- Bump the trace version constant whenever functrace.c's layout changes so mismatches are detectable
When it happens
Trigger: A stale file already exists at the BUN_FUNCTRACE_OUT path from an earlier tracer revision; two tracer versions sharing an out path; a garbage/hand-made file left where the workload expects to write.
Common situations: Re-running generate with a reused out directory after functrace.c's format changed; concurrent runs writing to the same fixed path.
Related errors
- workload "${name}" wrote a truncated trace
- workload "${name}" recorded no entries — is the tracer loadi
- workload "${workload.name}" exited ${r.status} ${r.stderr}
- traced only ${order.length} functions, expected at least ${m
- ${options.label ?? cmd[0]}: ${r.error.message}
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/419bfe0a15ca38cd.
Report an issue: GitHub.