{"record":{"id":"9c21e6c1017fe679","repo":"Hmbown/CodeWhale","slug":"invalid-pet-checkpoint","errorCode":null,"errorMessage":"Invalid pet checkpoint.","messagePattern":"Invalid pet checkpoint\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/pet_watch/pet-native.js","lineNumber":253,"sourceCode":"    }\n    recording(withCheckpoint = true, completed = false) {\n        const tapeEnd = completed ? this.bucketIndex + 1 : this.tapeLog.length;\n        const inputEnd = completed ? this.interactionIndex : this.interactionLog.length;\n        const history = this.historyDigest(tapeEnd, inputEnd);\n        return { petReplayVersion: this.segmented ? 2 : 1, expressionVersion: this.sim.expressionVersion,\n            tape: this.tapeLog.slice(0, tapeEnd), interactions: this.interactionLog.slice(0, inputEnd).map(e => ({ ...e })),\n            ...(this.origin ? { start: { ...structuredClone(this.origin), hasTelemetry: this.hasTelemetry, history } } : {}),\n            ...(withCheckpoint ? { checkpoint: { ...this.checkpoint(), history } } : {}) };\n    }\n    static fromRecording(points, value) {\n        const r = value;\n        if (!r || ![1, 2].includes(r.petReplayVersion) || !Array.isArray(r.tape) || !Array.isArray(r.interactions))\n            throw new Error('Invalid pet recording.');\n        const version = r.expressionVersion === undefined ? 1 : r.expressionVersion;\n        if (![1, 2].includes(version))\n            throw new Error('Unsupported pet expression version.');\n        if (r.checkpoint !== undefined && !r.checkpoint || r.start !== undefined && !r.start)\n            throw new Error('Invalid pet checkpoint.');\n        for (const c of [r.start, r.checkpoint])\n            if (c && (c.sim?.expressionVersion ?? 1) !== version)\n                throw new Error('Pet expression version does not match its checkpoint.');\n        if (r.petReplayVersion === 1 && (r.start || r.checkpoint && r.checkpoint.petCheckpointVersion !== 1))\n            throw new Error('Invalid legacy pet recording.');\n        if (r.petReplayVersion === 2 && (!r.start || r.start.petCheckpointVersion !== 2 || r.start.historyStart !== r.start.tick))\n            throw new Error('The recording segment is missing its starting checkpoint.');\n        const first = r.start && PetWorld.restore(points, r.tape, r.interactions, r.start);\n        const world = r.checkpoint ? PetWorld.restore(points, r.tape, r.interactions, r.checkpoint) : first ?? new PetWorld(points, r.tape, r.interactions, version);\n        if (first) {\n            if (!world.segmented || world.tick < first.tick || r.checkpoint && r.checkpoint.historyStart !== first.tick)\n                throw new Error('Pet segment checkpoints do not agree.');\n            world.origin = first.checkpoint();\n        }\n        return world;\n    }\n    /** Retire only consumed input. The exact origin makes each archived segment\n     * independently replayable; no particle, random stream or score is reset. */","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/pet_watch/pet-native.js#L235-L271","documentation":"fromRecording allows start and checkpoint keys to be absent, but if a key is present it must be a truthy checkpoint object. A recording carrying `start: null` or `checkpoint: null` (present but empty) is internally inconsistent — the producer intended a segmented/checkpointed recording but the data is missing — so this error is thrown.","triggerScenarios":"Calling `PetWorld.fromRecording(points, r)` where r.start or r.checkpoint is explicitly present but null/undefined/0/'' (e.g. `{start: null}` or `{checkpoint: undefined}` serialized as a present-but-falsy key).","commonSituations":"Serialization layers that write null for missing optional fields; hand-merging segment files; a producer bug that wrote the keys without populating them; JSON round-trips through schemas that normalize undefined to null.","solutions":["Remove the falsy start/checkpoint keys entirely from the recording object before restoring.","Restore the missing checkpoint from the segment archive that produced it.","Re-record or re-export the segment from a live world via prepareSegment().","Fix the producer/serialization step to omit empty optional keys instead of writing null."],"exampleFix":"// before\nconst r = JSON.parse(raw); // { ..., start: null, checkpoint: {...} }\nconst world = PetWorld.fromRecording(points, r); // throws\n// after\nconst r = JSON.parse(raw);\nif (r.start === null) delete r.start;\nif (r.checkpoint === null) delete r.checkpoint;\nconst world = PetWorld.fromRecording(points, r);","handlingStrategy":"validation","validationCode":"if ('start' in r && !r.start) delete r.start;\nif ('checkpoint' in r && !r.checkpoint) delete r.checkpoint;","typeGuard":"const hasCheckpoint = (r, k) => !(k in r) || (r[k] !== null && typeof r[k] === 'object');","tryCatchPattern":"try {\n  world = PetWorld.fromRecording(points, r);\n} catch (err) {\n  if (err.message === 'Invalid pet checkpoint.')\n    world = PetWorld.fromRecording(points, { ...r, start: undefined, checkpoint: undefined });\n  else throw err;\n}","preventionTips":["Configure serializers to omit empty optional keys instead of writing null.","Strip null-valued optional keys after JSON.parse before restoring.","Fix producers that write placeholder checkpoint keys.","Treat present-but-null checkpoints as a corruption signal and re-export."],"tags":["deserialization","validation","null"],"backgroundTag":"schema-validation-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}