{"record":{"id":"63a1f16f8c19af51","repo":"Hmbown/CodeWhale","slug":"pet-input-exceeds-250000-events-native","errorCode":null,"errorMessage":"Pet input exceeds 250000 events.","messagePattern":"Pet input exceeds 250000 events\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/ios/Resources/pet-native.js","lineNumber":1169,"sourceCode":"        }\n        const previous = this.sequence;\n        this.sequence = packet.sequence;\n        if (previous === undefined || packet.sequence <= previous)\n            return;\n        return packet;\n    }\n}\nexports.PetLiveTape = PetLiveTape;\nconst order = (a, b) => a < b ? -1 : a > b ? 1 : 0;\nconst keyOf = (e) => JSON.stringify([e.traceId, e.id]);\nconst isContainer = (e) => e.attributes['whalesong.container'] === true\n    || e.attributes['codewhale.container'] === true;\n/** Compile a single trace. Unknown-duration spans provide onsets, not occupancy.\n * Updates of the same trace/id replace earlier snapshots rather than double count.\n * An endpoint onset gets its own bucket; intervals use [start, end). */\nfunction compilePetTelemetry(input, durationMs = 0, firstSequence = 0, originMs = 0) {\n    if (input.length > 250_000)\n        throw new Error('Pet input exceeds 250000 events.');\n    if (!Number.isFinite(durationMs) || durationMs < 0)\n        throw new Error('Invalid pet duration.');\n    if (!Number.isSafeInteger(firstSequence) || firstSequence < 0)\n        throw new Error('Invalid first pet bucket.');\n    if (!Number.isFinite(originMs))\n        throw new Error('Invalid pet clock origin.');\n    durationMs = Math.max(0, durationMs - originMs);\n    const unique = new Map();\n    const traces = new Set();\n    for (const e of input) {\n        if (e.schemaVersion !== 1 || !e.id || !e.traceId || !model_js_1.CATEGORIES.includes(e.category)\n            || !Number.isFinite(e.startTime) || !Number.isFinite(e.endTime)\n            || e.startTime < 0 || e.endTime < e.startTime || !e.attributes)\n            throw new Error('Invalid event-v1 pet input. Import through importTrace first.');\n        traces.add(e.traceId);\n        unique.set(keyOf(e), e);\n    }\n    if (traces.size > 1)","sourceCodeStart":1151,"sourceCodeEnd":1187,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/ios/Resources/pet-native.js#L1151-L1187","documentation":"compilePetTelemetry caps its input at 250,000 trace events per compilation. Larger batches are rejected up front so the compilation (dedup map + interval bucketing) stays within predictable time and memory bounds.","triggerScenarios":"Calling compilePetTelemetry with an events array whose length exceeds 250,000 — e.g. feeding an entire day of raw spans at once, or appending without deduplicating repeated trace/id snapshots.","commonSituations":"Batching all buffered telemetry from a long session into one call; a collector that never trims; retry logic re-submitting events that were already compiled, inflating the array.","solutions":["Split the events into chunks of <=250,000 and compile each with the appropriate firstSequence offset.","Deduplicate trace/id snapshots before compiling to shrink the array.","Compile incrementally per time window instead of one giant batch.","Bound the collector's buffer and drop the oldest events beyond the cap."],"exampleFix":"// before\ncompilePetTelemetry(allDayEvents);\n// after\nfor (let i = 0; i < allDayEvents.length; i += 250000) {\n  compilePetTelemetry(allDayEvents.slice(i, i + 250000), durationMs, firstSequence + i, originMs);\n}","handlingStrategy":"validation","validationCode":"if (events.length > 250000) throw new Error('split events before compiling');\n// or chunk:\nfor (let i = 0; i < events.length; i += 250000) compilePetTelemetry(events.slice(i, i + 250000), durationMs, firstSequence + i, originMs);","typeGuard":null,"tryCatchPattern":"try { compilePetTelemetry(events, d, fs, o); }\ncatch (e) { if (e.message === 'Pet input exceeds 250000 events.') { compileInChunks(events, d, fs, o); } else throw e; }","preventionTips":["Compile telemetry incrementally per window instead of one batch per day.","Deduplicate trace/id snapshots in the collector.","Cap collector buffers at 250k with oldest-first eviction.","Watch batch sizes in metrics."],"tags":["limits","telemetry","batching"],"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-22T16:17:23.217Z"}