{"record":{"id":"8d4042ae43aadf2c","repo":"Hmbown/CodeWhale","slug":"codewhale-runtime-event-file-is-empty-pet-native","errorCode":null,"errorMessage":"Codewhale runtime event file is empty.","messagePattern":"Codewhale runtime event file is empty\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/ios/Resources/pet-native.js","lineNumber":2512,"sourceCode":"            privacy: 'redact',\n            warnings: [...new Set(warnings)],\n            metadata: {\n                sourceFormat: 'codewhale.runtime-events/v2',\n                timeBasis: 'wall-clock',\n                sourceFilename: filename,\n                threadId,\n                model,\n                skippedDeltas,\n                recordCount: this.recordCount,\n                timeUnit: 'ms',\n            },\n        };\n    }\n}\nexports.CodewhaleRuntimeTrace = CodewhaleRuntimeTrace;\nfunction fromCodewhaleRuntime(records, filename = 'Codewhale runtime', maxEvents = 250_000) {\n    if (!records.length)\n        throw new Error('Codewhale runtime event file is empty.');\n    const trace = new CodewhaleRuntimeTrace(filename, maxEvents);\n    trace.append(records);\n    return trace.snapshot();\n}\n/** The journal owns request state until a matching terminal receipt. A live\n * driver may confirm that state only while its cursor-checked stream is healthy.\n * Ordinary open tool spans remain unknown-duration; no execution is inferred. */\nfunction observeRuntimeRequests(trace, observedThrough) {\n    const origin = Date.parse(trace.originTime ?? '');\n    if (trace.metadata.sourceFormat !== 'codewhale.runtime-events/v2' || !Number.isFinite(origin)\n        || !Number.isFinite(observedThrough))\n        throw new Error('Invalid Runtime observation horizon.');\n    const at = observedThrough - origin;\n    const events = trace.events.map(e => e.openEnded && e.attributes['whalesong.waiting'] === true && at >= e.startTime\n        ? { ...e, endTime: at, openEnded: false } : e);\n    return { ...trace, events, duration: Math.max(trace.duration, at) };\n}\n","sourceCodeStart":2494,"sourceCodeEnd":2530,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/ios/Resources/pet-native.js#L2494-L2530","documentation":"fromCodewhaleRuntime() builds a CodewhaleRuntimeTrace from a parsed array of runtime event records. The library refuses to construct a trace from an empty record list because downstream code (origin-time anchoring, snapshot building) assumes at least one event; an empty input would produce a trace with no origin and no events. It throws this error before any trace object is allocated.","triggerScenarios":"Calling fromCodewhaleRuntime([], ...) — e.g. a runtime event file that parses to zero JSON lines, a file containing only whitespace or comments, or a filtered/decoder step that dropped every record before the call.","commonSituations":"Exporting a Codewhale session before any runtime events were recorded, truncating a .jsonl export with a shell command that leaves only a trailing newline, or piping an empty stream into the importer.","solutions":["Check that the runtime event file is non-empty (file size > 0 and at least one parsable JSON line) before calling fromCodewhaleRuntime.","Re-export the runtime events from the Codewhale session and verify the export wrote records.","If upstream filtering can legitimately drop all rows, handle the empty case in the caller instead of invoking fromCodewhaleRuntime."],"exampleFix":"// before\nconst trace = fromCodewhaleRuntime(records, file);\n// after\nif (!records.length) { console.warn(`skipping ${file}: no runtime events`); return; }\nconst trace = fromCodewhaleRuntime(records, file);","handlingStrategy":"validation","validationCode":"if (!Array.isArray(records) || records.length === 0) throw new Error(`no runtime events in ${file}`);\nconst trace = fromCodewhaleRuntime(records, file);","typeGuard":"const hasRecords = (v: unknown): v is object[] => Array.isArray(v) && v.length > 0;","tryCatchPattern":"let trace;\ntry { trace = fromCodewhaleRuntime(records, file); }\ncatch (e) { if (e.message.includes('event file is empty')) return null; throw e; }","preventionTips":["Check file size and parseable line count before import.","Log record counts at every pipeline stage to spot filters dropping everything.","Reject empty exports at export time in the producer."],"tags":["import","empty-input","runtime-events"],"backgroundTag":"empty-result-set","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}