{"record":{"id":"79fce861e150481d","repo":"Hmbown/CodeWhale","slug":"pet-recording-exceeds-its-input-limit-world","errorCode":null,"errorMessage":"Pet recording exceeds its input limit.","messagePattern":"Pet recording exceeds its input limit\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/src/core/pet-world.ts","lineNumber":91,"sourceCode":"  private lit = 1;\n  private lastActivity = 0;\n  private addressedAt = -Infinity;\n  private waitSince = -1;\n  private food: { time: number; x: number; y: number } | null = null;\n  private members = new Map<string, PodMember>();\n  private lastStill = '';\n  private origin?: PetWorldCheckpoint;\n  private segmented = false;\n  private hasTelemetry = false;\n  get startTimeMs(): number { return this.origin?.frame.timeMs ?? 0; }\n  get endTimeMs(): number { return Math.max(this.frame.timeMs, (this.tapeLog.at(-1)?.simTimeMs ?? 0) + 400); }\n  get needsSegment(): boolean {\n    return !this.segmented && this.tapeLog.length < 1024 && this.interactionLog.length < 4096\n      || this.bucketIndex >= 1024 || this.interactionIndex >= 4096;\n  }\n\n  constructor(points: [number, number][], tape: readonly PetBucket[] = [], interactions: readonly PetInteraction[] = [], expressionVersion: 1 | 2 = 2, segmented = false) {\n    if (tape.length > 216_000 || interactions.length > 100_000) throw new Error('Pet recording exceeds its input limit.');\n    this.sim = new PetSim(points, 0xC0FFEE, expressionVersion);\n    this.segmented = segmented; this.hasTelemetry = tape.length > 0;\n    this.tapeLog = structuredClone([...tape]);\n    this.interactionLog = structuredClone([...interactions]);\n    for (let i = 0; i < this.tape.length; i++) {\n      const b = this.tape[i];\n      validatePetBucket(b);\n      if (segmented ? i > 0 && b.sequence <= this.tape[i - 1].sequence : b.sequence !== i)\n        throw new Error('World requires contiguous version 1 pet buckets.');\n    }\n    for (let i = 0; i < this.interactionLog.length; i++) {\n      const e = this.interactionLog[i];\n      if (!Number.isFinite(e.timeMs) || e.timeMs < 0 || i > 0 && e.timeMs < this.interactionLog[i - 1].timeMs\n        || !['attention', 'food'].includes(e.kind) || !Number.isFinite(e.x) || !Number.isFinite(e.y)\n        || Math.abs(e.x) > 1 || Math.abs(e.y) > 1) throw new Error('Invalid pet interaction.');\n    }\n    this.hashTape(0);\n    this.frame = this.makeFrame(0);","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/core/pet-world.ts#L73-L109","documentation":"Constructor guard in PetWorld: the recording being loaded exceeds the accepted input limit (total tape/interaction log size). The world state machine loads an entire recording into memory (tapeLog, interactionLog, members map), so oversized recordings are rejected at construction rather than loaded partially.","triggerScenarios":"new PetWorld(points, tape, interactions, ...) where tape.length > 216000 or interactions.length > 100000.","commonSituations":"Loading a recording accumulated over many days without segmentation; concatenating multiple recordings into one array; a long-running session producing more than 4096 interactions without checkpointing.","solutions":["Split the recording into segments (segmented recordings) and load via fromRecording with checkpoints.","Truncate tape/interactions to the limits before constructing.","Drop or compress older buckets beyond 216000 and interactions beyond 100000."],"exampleFix":"// before\nnew PetWorld(points, hugeTape, hugeInteractions);\n// after\nconst tape = hugeTape.slice(-216000);\nconst interactions = hugeInteractions.slice(-100000);\nnew PetWorld(points, tape, interactions);","handlingStrategy":"validation","validationCode":"if (tape.length > 216000 || interactions.length > 100000) throw new Error('Recording too large to load as one world');","typeGuard":null,"tryCatchPattern":"try { world = new PetWorld(points, tape, interactions); } catch (e) { if (e.message.includes('input limit')) world = PetWorld.fromRecording(points, segmentRecording(tape, interactions)); }","preventionTips":["Use segmented recordings with checkpoints for long sessions.","Periodically trim logs during recording."],"tags":["limits","constructor"],"backgroundTag":"payload-too-large","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"}