{"record":{"id":"8446191f6bacd555","repo":"Hmbown/CodeWhale","slug":"pet-expression-version-does-not-match-its-checkpoint-native","errorCode":null,"errorMessage":"Pet expression version does not match its checkpoint.","messagePattern":"Pet expression version does not match its checkpoint\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/ios/Resources/pet-native.js","lineNumber":256,"sourceCode":"        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. */\n    prepareSegment() {\n        const dropTape = Math.max(0, this.bucketIndex), dropInputs = this.interactionIndex, previous = this.origin;\n        const tape = this.tapeLog.slice(dropTape), interactions = this.interactionLog.slice(dropInputs);","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/ios/Resources/pet-native.js#L238-L274","documentation":"Each embedded checkpoint (start and checkpoint) carries its own sim.expressionVersion, which must equal the recording's top-level expressionVersion (defaulting to 1). This error means the recording's metadata and its embedded checkpoint disagree, so restoring could mix incompatible sim encodings.","triggerScenarios":"Passing a recording whose c.sim?.expressionVersion (on start or checkpoint) differs from the top-level expressionVersion — including the case where the top level defaults to 1 while the checkpoint carries 2.","commonSituations":"Splicing a checkpoint from one recording into another; partially upgrading recordings where only the top-level version field was bumped; copy/pasting checkpoints between exports during debugging.","solutions":["Ensure the producer writes top-level expressionVersion and each checkpoint's sim.expressionVersion together.","Set the recording's top-level expressionVersion to match the checkpoint's sim.expressionVersion (or vice versa).","Re-export the whole recording from a single live PetWorld instead of assembling from parts.","If importing, reject the file at load time and ask the user to re-export from the matching app version."],"exampleFix":"// before\nrecording.expressionVersion = 2; // checkpoint still has sim.expressionVersion: 1\n// after\nrecording.expressionVersion = recording.checkpoint.sim.expressionVersion;\nconst world = PetWorld.fromRecording(points, recording);","handlingStrategy":"validation","validationCode":"const version = r.expressionVersion ?? 1;\nfor (const c of [r.start, r.checkpoint]) if (c && (c.sim?.expressionVersion ?? 1) !== version) throw new Error('version mismatch');","typeGuard":"const versionsAgree = (r: any) => {\n  const v = r.expressionVersion ?? 1;\n  return [r.start, r.checkpoint].every(c => !c || (c.sim?.expressionVersion ?? 1) === v);\n};","tryCatchPattern":"try { world = PetWorld.fromRecording(points, r); }\ncatch (e) {\n  if (e.message === 'Pet expression version does not match its checkpoint.') {\n    const cp = r.checkpoint ?? r.start;\n    r.expressionVersion = cp.sim.expressionVersion; // realign, then retry\n    world = PetWorld.fromRecording(points, r);\n  } else throw e;\n}","preventionTips":["Always export recordings from a single live PetWorld — never splice checkpoints between recordings.","Bump top-level and per-checkpoint version fields atomically in the producer.","Test imports against recordings from each supported app version."],"tags":["versioning","consistency","replay"],"backgroundTag":"schema-validation-failed","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}