{"record":{"id":"716b7e836b58a7a0","repo":"Hmbown/CodeWhale","slug":"codewhale-runtime-event-file-is-empty-716b7e","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/src/core/codewhale.ts","lineNumber":567,"sourceCode":"      source: 'codewhale',\n      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}\n\nexport function fromCodewhaleRuntime(records: unknown[], filename = 'Codewhale runtime', maxEvents = 250_000): Trace {\n  if (!records.length) throw new Error('Codewhale runtime event file is empty.');\n  const trace = new CodewhaleRuntimeTrace(filename, maxEvents);\n  trace.append(records); return trace.snapshot();\n}\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. */\nexport function observeRuntimeRequests(trace: Trace, observedThrough: number): Trace {\n  const origin = Date.parse(trace.originTime ?? '');\n  if (trace.metadata.sourceFormat !== 'codewhale.runtime-events/v2' || !Number.isFinite(origin)\n    || !Number.isFinite(observedThrough)) 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":549,"sourceCodeEnd":584,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/core/codewhale.ts#L549-L584","documentation":"fromCodewhaleRuntime is the top-level entry point for turning Codewhale runtime records into a Trace. An empty records array can never yield a trace, so it is rejected up front before any parsing work begins.","triggerScenarios":"Calling fromCodewhaleRuntime([]), or passing the result of reading an empty/zero-byte .jsonl file, or a filtered record list that removed every line.","commonSituations":"File exists but is empty (0 bytes) or contains only blank lines; a glob or path picked the wrong file; an upstream filter (e.g. by thread_id or event type) matched nothing; a failed export produced an empty file that was still passed on.","solutions":["Check the source file is non-empty before importing (file size > 0 and at least one JSON line).","Fix the path/glob so it points at the actual runtime events file.","Remove or relax the upstream filter that emptied the record list.","If an empty file is legitimate in your flow, handle it before calling: skip import and create a placeholder/empty trace yourself."],"exampleFix":"// before\nconst trace = fromCodewhaleRuntime(readJsonl(path));\n// after\nconst records = readJsonl(path);\nif (!records.length) return null; // or: throw new Error(`no events in ${path}`)\nconst trace = fromCodewhaleRuntime(records, path);","handlingStrategy":"try-catch","validationCode":"const records = readJsonl(path);\nif (!records.length) throw new Error(`${path} has no records; check the export`);","typeGuard":null,"tryCatchPattern":"try {\n  const trace = fromCodewhaleRuntime(records, filename);\n} catch (e) {\n  if (e.message.includes('event file is empty')) {\n    // treat as 'no data for this session'; skip or surface a user-facing warning\n  } else throw e;\n}","preventionTips":["Check file size and line count before importing; 0-byte exports should be caught at the exporter.","Validate paths/globs resolve to the intended journal file.","If filtering records upstream, assert the filtered list is non-empty before import.","Make exporters fail loudly (nonzero exit) when they write zero records."],"tags":["import","codewhale","empty-input","validation"],"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"}