Hmbown/CodeWhale · error · Error

Pet input exceeds 250000 events.

Error message

Pet input exceeds 250000 events.

What it means

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).

Solutions

  1. Truncate the input to the most recent 250,000 events before compiling (input.slice(-250_000)).
  2. Compile in batches of at most 250,000 events and merge results downstream.
  3. Deduplicate trace/id snapshots first — the compiler already replaces earlier snapshots, so duplicates inflate the count needlessly.
  4. Raise the cap only if the 24-hour/1-second-bucket model changed.

Example fix

// before
compilePetTelemetry(allEvents); // throws when allEvents.length > 250_000
// after
const recent = allEvents.slice(-250_000);
compilePetTelemetry(recent);
Defensive patterns

Strategy: validation

Validate before calling

function canCompile(events) {
  return Array.isArray(events) && events.length <= 250_000;
}
if (!canCompile(events)) events = events.slice(-250_000);

Type guard

function isWithinCompileLimit(input) {
  return Array.isArray(input) && input.length <= 250_000;
}

Try / catch

try {
  compilePetTelemetry(events);
} catch (e) {
  if (e.message.includes('250000')) {
    compilePetTelemetry(events.slice(-250_000));
  } else throw e;
}

Prevention

When it happens

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

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

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/27b2ef93d6aa5918. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tui/pet_watch/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 73e0f67d83)