{"record":{"id":"27b2ef93d6aa5918","repo":"Hmbown/CodeWhale","slug":"pet-input-exceeds-250000-events","errorCode":null,"errorMessage":"Pet input exceeds 250000 events.","messagePattern":"Pet input exceeds 250000 events\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/pet_watch/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/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/pet_watch/pet-native.js#L1151-L1187","documentation":"compilePetTelemetry() compiles a trace of pet events into buckets and caps the input at 250,000 events per compilation. Larger inputs are rejected because bucket compilation would exceed the tape's capacity (24 hours of 1-second buckets).","triggerScenarios":"Calling compilePetTelemetry with an input array longer than 250,000 events — e.g. replaying a whole tape instead of the last 24 hours, or feeding unbounded accumulated telemetry in one call.","commonSituations":"Batch-replaying an oversized or merged telemetry export; a driver that accumulated events without flushing; passing both live and persisted events into a single compile call so counts double.","solutions":["Truncate the input to the most recent 250,000 events before compiling (input.slice(-250_000)).","Compile in batches of at most 250,000 events and merge results downstream.","Deduplicate trace/id snapshots first — the compiler already replaces earlier snapshots, so duplicates inflate the count needlessly.","Raise the cap only if the 24-hour/1-second-bucket model changed."],"exampleFix":"// before\ncompilePetTelemetry(allEvents); // throws when allEvents.length > 250_000\n// after\nconst recent = allEvents.slice(-250_000);\ncompilePetTelemetry(recent);","handlingStrategy":"validation","validationCode":"function canCompile(events) {\n  return Array.isArray(events) && events.length <= 250_000;\n}\nif (!canCompile(events)) events = events.slice(-250_000);","typeGuard":"function isWithinCompileLimit(input) {\n  return Array.isArray(input) && input.length <= 250_000;\n}","tryCatchPattern":"try {\n  compilePetTelemetry(events);\n} catch (e) {\n  if (e.message.includes('250000')) {\n    compilePetTelemetry(events.slice(-250_000));\n  } else throw e;\n}","preventionTips":["Deduplicate trace/id snapshots before compiling (the compiler replaces, not adds).","Compile incrementally as events arrive, not as one giant batch.","Keep per-session event counts under 250,000 via rotation.","Split oversized exports into batches before compilation."],"tags":["input-validation","size-limit","telemetry"],"backgroundTag":"value-out-of-range","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}