Hmbown/CodeWhale · error · Error

Pet input exceeds 250000 events.

Error message

Pet input exceeds 250000 events.

What it means

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.

Solutions

  1. Split the events into chunks of <=250,000 and compile each with the appropriate firstSequence offset.
  2. Deduplicate trace/id snapshots before compiling to shrink the array.
  3. Compile incrementally per time window instead of one giant batch.
  4. Bound the collector's buffer and drop the oldest events beyond the cap.

Example fix

// before
compilePetTelemetry(allDayEvents);
// after
for (let i = 0; i < allDayEvents.length; i += 250000) {
  compilePetTelemetry(allDayEvents.slice(i, i + 250000), durationMs, firstSequence + i, originMs);
}
Defensive patterns

Strategy: validation

Validate before calling

if (events.length > 250000) throw new Error('split events before compiling');
// or chunk:
for (let i = 0; i < events.length; i += 250000) compilePetTelemetry(events.slice(i, i + 250000), durationMs, firstSequence + i, originMs);

Try / catch

try { compilePetTelemetry(events, d, fs, o); }
catch (e) { if (e.message === 'Pet input exceeds 250000 events.') { compileInChunks(events, d, fs, o); } else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/63a1f16f8c19af51. Report an issue: GitHub.

Appendix: source

Thrown at pet/ios/Resources/pet-native.js:1169

        }
        const previous = this.sequence;
        this.sequence = packet.sequence;
        if (previous === undefined || packet.sequence <= previous)
            return;
        return packet;
    }
}
exports.PetLiveTape = PetLiveTape;
const order = (a, b) => a < b ? -1 : a > b ? 1 : 0;
const keyOf = (e) => JSON.stringify([e.traceId, e.id]);
const isContainer = (e) => e.attributes['whalesong.container'] === true
    || e.attributes['codewhale.container'] === true;
/** Compile a single trace. Unknown-duration spans provide onsets, not occupancy.
 * Updates of the same trace/id replace earlier snapshots rather than double count.
 * An endpoint onset gets its own bucket; intervals use [start, end). */
function compilePetTelemetry(input, durationMs = 0, firstSequence = 0, originMs = 0) {
    if (input.length > 250_000)
        throw new Error('Pet input exceeds 250000 events.');
    if (!Number.isFinite(durationMs) || durationMs < 0)
        throw new Error('Invalid pet duration.');
    if (!Number.isSafeInteger(firstSequence) || firstSequence < 0)
        throw new Error('Invalid first pet bucket.');
    if (!Number.isFinite(originMs))
        throw new Error('Invalid pet clock origin.');
    durationMs = Math.max(0, durationMs - originMs);
    const unique = new Map();
    const traces = new Set();
    for (const e of input) {
        if (e.schemaVersion !== 1 || !e.id || !e.traceId || !model_js_1.CATEGORIES.includes(e.category)
            || !Number.isFinite(e.startTime) || !Number.isFinite(e.endTime)
            || e.startTime < 0 || e.endTime < e.startTime || !e.attributes)
            throw new Error('Invalid event-v1 pet input. Import through importTrace first.');
        traces.add(e.traceId);
        unique.set(keyOf(e), e);
    }
    if (traces.size > 1)

View on GitHub (pinned to 433685b202)