{"record":{"id":"be270ab1982c39ba","repo":"Hmbown/CodeWhale","slug":"runtime-event-seq-rec-seq-is-missing-a-usable-timestamp-be270a","errorCode":null,"errorMessage":"Runtime event seq ${rec.seq} is missing a usable timestamp.","messagePattern":"Runtime event seq (.+?) is missing a usable timestamp\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/src/core/codewhale.ts","lineNumber":384,"sourceCode":"    for (const event of this.events) {\n      if (event.openEnded || Math.max(event.endTime, errorOnsetOf(event)) >= cutoff) this.events[keep++] = event;\n      else {\n        this.bytes -= this.sizes.get(event) ?? 0; this.sizes.delete(event);\n        if (this.open.get(event.id) === event) this.open.delete(event.id);\n      }\n    }\n    this.events.length = keep;\n  }\n  append(records: unknown[]): void {\n    if (!records.length) return;\n    const { events, open, requests } = this;\n    const threadId = this.threadId ?? str(obj(records[0]).thread_id) ?? this.filename;\n    this.threadId = threadId;\n    let { origin, model, skippedDeltas } = this;\n    let threadName = this.threadName ?? threadId;\n    const stamp = (rec: Obj): number => {\n      const t = parseTime(rec.timestamp);\n      if (t === undefined) throw new Error(`Runtime event seq ${rec.seq} is missing a usable timestamp.`);\n      if (origin === undefined) origin = t;\n      return t - origin;\n    };\n    for (const raw of records) {\n      if (!isCodewhaleRuntimeRecord(raw)) throw new Error('Runtime import cancelled: a line is not a Codewhale runtime event record. No rows were skipped.');\n      this.recordCount++;\n      const rec = obj(raw);\n      if (rec.thread_id !== threadId) throw new Error('Runtime import contains multiple threads. Export one thread before importing.');\n      const eventName = rec.event as string;\n      if (eventName === 'item.delta') { skippedDeltas++; continue; }\n      const payload = obj(rec.payload);\n      const item = obj(payload.item);\n      const turn = obj(payload.turn);\n      const thread = obj(payload.thread);\n      const relative = stamp(rec);\n      const turnId = str(rec.turn_id) ?? str(payload.turn_id);\n      const itemId = str(rec.item_id) ?? str(item.id);\n      const agentId = 'parent';","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/core/codewhale.ts#L366-L402","documentation":"The runtime import anchors all relative event times to the first record's timestamp via an internal stamp() helper. If a record's timestamp cannot be parsed by parseTime (undefined result), the importer cannot place the event on the time axis and throws, naming the record's seq so the offending line can be located in the export.","triggerScenarios":"Importing a runtime events file where a record has a missing, null, empty, or non-ISO timestamp field (e.g. \"timestamp\": \"\" or a locale-formatted date string parseTime doesn't recognize), typically after partial writes or hand-editing the export.","commonSituations":"A crash mid-export leaving a truncated last line, logs collected with clock sync disabled producing sentinel timestamps, or a producer version emitting timestamps in a format the importer's parseTime doesn't accept.","solutions":["Open the export at the reported seq and fix or remove the record's timestamp, then re-import.","Re-export the runtime events; the corrupted line is usually from an interrupted or partial export.","Check the timestamp format: the importer expects ISO-8601 (Date.parse-compatible) strings or epoch numbers — convert exotic formats upstream.","If many records are affected, suspect a producer version mismatch and align exporter/importer versions."],"exampleFix":"// before\n{\"seq\":42,\"event\":\"item.completed\",\"timestamp\":\"\"}\n// after\n{\"seq\":42,\"event\":\"item.completed\",\"timestamp\":\"2026-09-15T10:04:11.500Z\"}","handlingStrategy":"validation","validationCode":"const bad = records.find(r => r == null || !Number.isFinite(Date.parse(r.timestamp ?? '')));\nif (bad) throw new Error(`record seq=${bad.seq} has unusable timestamp before import`);","typeGuard":"const hasTimestamp = (r: any): r is { timestamp: string | number } =>\n  r != null && (typeof r.timestamp === 'number' ? Number.isFinite(r.timestamp) : typeof r.timestamp === 'string' && !Number.isNaN(Date.parse(r.timestamp)));","tryCatchPattern":"try { trace.append(records); }\ncatch (e) {\n  const m = e.message.match(/seq (\\d+) is missing a usable timestamp/);\n  if (m) { reportCorruptLine(Number(m[1])); return null; }\n  throw e;\n}","preventionTips":["Validate timestamps (ISO-8601 or epoch) at export time in the producer.","Check for truncated final lines after copying/exporting .jsonl files.","Keep exporter and importer versions aligned so timestamp formats match."],"tags":["import","timestamp","corrupt-data"],"backgroundTag":"invalid-date-format","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"}