Hmbown/CodeWhale · error · Error

Import exceeds the event limit.

Error message

Import exceeds the ${this.maxEvents.toLocaleString()} event limit.

What it means

The Runtime event store enforces a maximum number of retained events (maxEvents). push() rejects any push once the store is full, throwing the same limit message used by the session import path. Like the byte cap, it bounds memory and rendering cost.

Solutions

  1. Raise maxEvents when constructing/configuring the Runtime.
  2. Prune old events with prune(beforeWall) to free slots before pushing.
  3. Chunk the import across multiple Runtime instances.
  4. Filter out low-value records (deltas already skipped; consider other noise) before import.

Example fix

// before
const rt = new Runtime({ maxEvents: 500 });
// after
const rt = new Runtime({ maxEvents: 100000 });
Defensive patterns

Strategy: try-catch

Validate before calling

if (rt.events.length >= rt.maxEvents) rt.prune(Date.now());

Try / catch

try { rt.push(event); } catch (e) { if (e.message.startsWith('Import exceeds the')) { rt.prune(Date.now()); rt.push(event); } else throw e; }

Prevention

When it happens

Trigger: Calling runtime.push(event) when events.length already equals maxEvents; importing a runtime record stream with more non-delta events than maxEvents.

Common situations: Long-running threads producing many tool calls/approvals; importing an old large runtime export; a low maxEvents configured for embedded or test use applied to production data.

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/f809fd5aeb6cdc92. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tui/pet_watch/pet-native.js:2267

    get retainedBytes() { return this.bytes; }
    measure(event, proposed = event) {
        const safe = this.project(proposed);
        if (this.maxBytes !== Infinity) {
            const size = new TextEncoder().encode(JSON.stringify(safe)).length;
            const total = this.bytes - (this.sizes.get(event) ?? 0) + size;
            if (total > this.maxBytes)
                throw new Error('Runtime observation exceeds its retained input limit.');
            this.bytes = total;
            this.sizes.set(event, size);
        }
        for (const key of Object.keys(event))
            if (!Object.hasOwn(safe, key))
                delete event[key];
        Object.assign(event, safe);
    }
    push(event) {
        if (this.events.length >= this.maxEvents)
            throw new Error(`Import exceeds the ${this.maxEvents.toLocaleString()} event limit.`);
        this.measure(event);
        pushEvent(this.events, event);
    }
    /** Keep unfinished lifetimes plus the recent window needed by the bucketer's
     * 12-second recurrence measure. A completion may still arrive for any open item. */
    prune(beforeWall) {
        if (!Number.isFinite(beforeWall))
            throw new Error('Invalid Runtime retention horizon.');
        if (this.origin === undefined)
            return;
        const cutoff = beforeWall - this.origin;
        let keep = 0;
        for (const event of this.events) {
            if (event.openEnded || Math.max(event.endTime, (0, model_js_1.errorOnsetOf)(event)) >= cutoff)
                this.events[keep++] = event;
            else {
                this.bytes -= this.sizes.get(event) ?? 0;
                this.sizes.delete(event);

View on GitHub (pinned to 73e0f67d83)