{"record":{"id":"20b387745c764000","repo":"Hmbown/CodeWhale","slug":"codewhale-runtime-file-contained-only-stream-deltas-or-20b387","errorCode":null,"errorMessage":"Codewhale runtime file contained only stream deltas or unreadable records.","messagePattern":"Codewhale runtime file contained only stream deltas or unreadable records\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/src/core/codewhale.ts","lineNumber":538,"sourceCode":"        continue;\n      }\n      this.push({\n        schemaVersion: 1, id: `${eventName}:${rec.seq}`, traceId: threadId, parentId: turnId ? `turn:${turnId}` : undefined,\n        startTime: relative, endTime: relative, agentId, name: eventName, category: classify(eventName),\n        model, status: 'unknown', attributes: { 'codewhale.seq': rec.seq }, raw: rec,\n      });\n    }\n\n    this.origin = origin; this.model = model; this.threadName = threadName; this.skippedDeltas = skippedDeltas;\n  }\n  snapshot(): Trace {\n    const { events, open, requests, origin, model, skippedDeltas, filename } = this;\n    const threadId = this.threadId ?? filename, threadName = this.threadName ?? threadId;\n    const warnings: string[] = [];\n    if (skippedDeltas) warnings.push(`Dropped ${skippedDeltas.toLocaleString()} item.delta records; they are token stream fragments, not spans. Item start/end remain the source of duration.`);\n    for (const [id] of open) warnings.push(`Item ${id} started and never completed in this file; duration remains unknown.`);\n    for (const request of requests.values()) warnings.push(`Request ${request.id} has no terminal receipt; its duration remains unknown in this file.`);\n    if (!events.length) throw new Error('Codewhale runtime file contained only stream deltas or unreadable records.');\n    const base = events.reduce((m, e) => Math.min(m, e.startTime), events[0]!.startTime);\n    const normalized = events.map(event => ({ ...event, startTime: event.startTime - base, endTime: event.endTime - base,\n      attributes: { ...event.attributes, ...(event.attributes['whalesong.error_onset_ms'] !== undefined\n        ? { 'whalesong.error_onset_ms': errorOnsetOf(event) - base } : {}) } }));\n    return {\n      id: threadId,\n      name: `Codewhale runtime · ${threadName}`,\n      events: normalized,\n      duration: Math.max(1, normalized.reduce((m, e) => Math.max(m, e.endTime, e.startTime, e.status === 'error' ? errorOnsetOf(e) : 0), 0)),\n      originTime: origin !== undefined ? new Date(origin + base).toISOString() : '0 ms',\n      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,","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/core/codewhale.ts#L520-L556","documentation":"After parsing a Codewhale runtime file, the snapshot is built from span-level events (item start/end, turn lifecycle, approvals, etc.). item.delta records are intentionally dropped as token stream fragments; if nothing else remains, the file produced no representable events, and the library refuses to return an empty trace.","triggerScenarios":"Calling snapshot() (directly or via fromCodewhaleRuntime) on a file whose records were all item.delta stream fragments, or where every line failed the isCodewhaleRuntimeRecord check and was discarded.","commonSituations":"Pointing the importer at a raw token-stream log rather than the structured event journal; a runtime configured to emit only deltas; a truncated or corrupted file where readable lines were all deltas; passing the wrong file from a directory of mixed logs.","solutions":["Import the full runtime events journal (structured spans), not a token/delta stream log.","Check that the source file is the runtime-events/v2 journal and not a partial or rotated fragment.","If you only need token streams, use a stream viewer instead of this trace importer.","Verify the file has non-delta events: filter lines whose event !== 'item.delta' and confirm the count is > 0 before importing."],"exampleFix":"// before\nconst records = readJsonl('tokens.jsonl'); // all item.delta\nconst trace = fromCodewhaleRuntime(records);\n// after\nconst records = readJsonl('session.jsonl');\nif (!records.some(r => r?.event !== 'item.delta')) throw new Error('no span events in file');\nconst trace = fromCodewhaleRuntime(records);","handlingStrategy":"validation","validationCode":"const hasSpans = (records) => records.some(r => r && typeof r === 'object' && r.event !== 'item.delta');\nif (!hasSpans(records)) console.warn('file has only item.delta fragments; import will fail');","typeGuard":"const isSpanRecord = (r) => !!r && typeof r === 'object' && typeof r.event === 'string' && r.event !== 'item.delta';","tryCatchPattern":"try {\n  return fromCodewhaleRuntime(records, filename);\n} catch (e) {\n  if (e.message.includes('only stream deltas')) return null; // no traceable spans in this file\n  throw e;\n}","preventionTips":["Import the structured runtime events journal, not token-stream logs.","Check that a file contains at least one non-delta event before import.","Confirm you are pointing at the session journal file, not a rotated partial or a stream capture.","Treat delta-only files as stream data and visualize them with a stream tool instead."],"tags":["import","codewhale","empty-input","trace"],"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"}