{"record":{"id":"de81333054d2650a","repo":"Hmbown/CodeWhale","slug":"live-pet-input-exceeds-its-tail-limit-native","errorCode":null,"errorMessage":"Live pet input exceeds its tail limit.","messagePattern":"Live pet input exceeds its tail limit\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/ios/Resources/pet-native.js","lineNumber":1136,"sourceCode":"        throw new Error('Pet tape exceeds 24 hours.');\n    return rows.map((row, i) => { validatePetBucket(row); if (row.sequence !== i)\n        throw new Error('Non-contiguous pet tape.'); return row; });\n}\n/** A live file must advance before its contents count as a new observation.\n * Existing bytes, duplicate samples and a restarted sequence establish a\n * baseline; they never replay an old onset or human request. Drivers supply a\n * bounded tail and reset this cursor after suspension or a new attachment. */\nclass PetLiveTape {\n    sequence;\n    reset() { this.sequence = undefined; }\n    readTail(text) {\n        if (!text) {\n            this.reset();\n            return;\n        }\n        if (text.length > 262_144) {\n            this.reset();\n            throw new Error('Live pet input exceeds its tail limit.');\n        }\n        if (!text.endsWith('\\n'))\n            return;\n        const line = text.trimEnd().split('\\n').at(-1);\n        if (!line)\n            return;\n        let packet;\n        try {\n            packet = JSON.parse(line);\n            validatePetBucket(packet);\n        }\n        catch (error) {\n            this.reset();\n            throw error;\n        }\n        const previous = this.sequence;\n        this.sequence = packet.sequence;\n        if (previous === undefined || packet.sequence <= previous)","sourceCodeStart":1118,"sourceCodeEnd":1154,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/ios/Resources/pet-native.js#L1118-L1154","documentation":"PetLiveTape.accept() only accepts a bounded tail of live file input (256 KiB). If the supplied text exceeds that limit, the cursor is reset (establishing a baseline) and the input is rejected, so an unbounded read can never flood the live pipeline.","triggerScenarios":"Calling accept() with a string longer than 262,144 characters — usually from reading the whole live tape file instead of its tail, or from a file that grew huge between polls.","commonSituations":"A driver reading the full file on first poll instead of a bounded tail; a file watcher passing the entire changed file; very large accumulated tape due to missing rotation.","solutions":["Read only the trailing bytes/tail of the live file (bounded to <=256 KiB) before calling accept().","Track your own file offset and pass only the newly appended chunk.","Reset the live cursor after suspension or re-attachment, then re-accept from a fresh bounded tail.","Rotate the underlying tape file so it stays small."],"exampleFix":"// before\nlive.accept(await readFile(path, 'utf8'));\n// after\nconst text = await readFile(path, 'utf8');\nlive.accept(text.slice(-262144)); // or track offset and pass only the new chunk","handlingStrategy":"try-catch","validationCode":"if (typeof chunk === 'string' && chunk.length > 262144) chunk = chunk.slice(-262144); // or track offset and pass only new bytes\nlive.accept(chunk);","typeGuard":null,"tryCatchPattern":"try { live.accept(text); }\ncatch (e) { if (e.message === 'Live pet input exceeds its tail limit.') { live.reset(); live.accept(text.slice(-262144)); } else throw e; }","preventionTips":["Track a file offset and pass only newly appended bytes.","On first poll or re-attach, read a bounded tail, never the whole file.","Reset the PetLiveTape cursor after suspension or re-attachment.","Keep the live tape rotated and small."],"tags":["limits","streaming","file"],"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-22T21:17:16.096Z"}