{"record":{"id":"03d45bfe5a014294","repo":"Hmbown/CodeWhale","slug":"pet-checkpoint-exceeds-its-size-limit-03d45b","errorCode":null,"errorMessage":"Pet checkpoint exceeds its size limit.","messagePattern":"Pet checkpoint exceeds its size limit\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/src/core/pet-native.ts","lineNumber":58,"sourceCode":"  }\n  /** Losing a producer invalidates outstanding coverage, never the creature. */\n  disconnectEngine(): void { this.engine = new PetEngineTelemetry(); this.world.voices = []; }\n  interact(kind: PetInteraction['kind'], x: number, y: number): void { this.world.interact(kind, x, y); }\n  interactions(): string { return JSON.stringify(this.world.interactions); }\n  accept(packet: string): void { this.world.acceptTelemetry(JSON.parse(packet)); }\n  acceptLiveTail(text: string): boolean {\n    const packet = this.liveTape.readTail(text); if (!packet) return false;\n    this.world.acceptTelemetry(packet); return true;\n  }\n  resetLiveInput(): number { this.liveTape.reset(); return this.resumeEngine(); }\n  recording(withCheckpoint = false): string { return JSON.stringify(this.world.recording(withCheckpoint)); }\n  needsSegment(): boolean { return this.world.needsSegment; }\n  prepareSegment(): string { this.segment = this.world.prepareSegment(); return JSON.stringify(this.segment.recording); }\n  commitSegment(): void { if (!this.segment) throw new Error('No pet segment was prepared.'); this.segment.commit(); this.segment = undefined; }\n  checkpoint(): string { return JSON.stringify(this.world.checkpoint()); }\n  recordingChunk(index: number, completed = false): string | null { return this.world.recordingChunk(index, completed); }\n  restoreCheckpoint(text: string): void {\n    if (text.length > 512 * 1024) throw new Error('Pet checkpoint exceeds its size limit.');\n    this.restoreRecording(JSON.stringify({ ...this.world.recording(false), checkpoint: JSON.parse(text) }));\n  }\n  restoreRecording(text: string): void {\n    if (text.length > 8 * 1024 * 1024) throw new Error('Native habitat exceeds 8 MiB.');\n    const points = this.world.sim.p.map(p => [p.hx, p.hy] as [number, number]);\n    this.world = PetWorld.fromRecording(points, JSON.parse(text));\n    this.liveTape.reset();\n    this.segment = undefined; this.engineTick = Math.round(this.world.frame.timeMs * 30 / 1000); this.engine = new PetEngineTelemetry();\n  }\n  /** Resume a live host at the first unrecorded bucket. Keep every accepted\n   * interval, but never present its last observed frame as current evidence. */\n  resumeEngine(): number {\n    this.world.resumeObservation();\n    this.engineTick = Math.round(this.world.frame.timeMs * 30 / 1000);\n    this.engine = new PetEngineTelemetry();\n    this.world.voices = [];\n    return this.world.frame.timeMs;\n  }","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/core/pet-native.ts#L40-L76","documentation":"restoreCheckpoint(text) accepts a serialized checkpoint and, as a guard before parsing, enforces a hard 512 KiB limit on the input string. Larger checkpoints are rejected up front because checkpoints are meant to be small state snapshots, and oversized ones usually indicate corruption or the wrong payload being passed.","triggerScenarios":"Calling restoreCheckpoint with a string longer than 512*1024 characters — e.g. passing a full recording/habitat dump instead of a checkpoint, or a checkpoint serialized with an accidentally embedded recording.","commonSituations":"Mixing up checkpoint() output with recording() output; a producer bug that nests recordings inside checkpoints; checkpoints inflated by verbose debug fields.","solutions":["Pass the exact string returned by pet.checkpoint(), not recording output","Check text.length <= 512*1024 before calling and split/truncate the payload if it is a composite blob","Re-serialize the checkpoint compactly (strip debug fields, minify JSON)","If you genuinely need more state, store it via restoreRecording (8 MiB limit) instead"],"exampleFix":"// before\npet.restoreCheckpoint(bigBlob);\n// after\nif (bigBlob.length > 512 * 1024) throw new Error('not a checkpoint?');\npet.restoreCheckpoint(bigBlob);","handlingStrategy":"validation","validationCode":"function canRestoreCheckpoint(text) { return typeof text === 'string' && text.length <= 512 * 1024; }","typeGuard":null,"tryCatchPattern":"try {\n  pet.restoreCheckpoint(text);\n} catch (err) {\n  if (err.message === 'Pet checkpoint exceeds its size limit.') {\n    // wrong payload or corrupted checkpoint — recover from last good checkpoint\n    pet.restoreCheckpoint(lastGoodCheckpoint);\n  } else throw err;\n}","preventionTips":["Store checkpoint() and recording() outputs under distinct keys","Minify checkpoint JSON and strip debug fields before persisting","Check length before restore and keep a rolling last-good checkpoint"],"tags":["checkpoint","size-limit","validation"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}