Hmbown/CodeWhale · error · Error
Invalid interval for
Error message
Invalid interval for ${e.id}. What it means
During pyramid accumulation each event must have a valid interval: finite startTime and endTime, startTime >= 0, and endTime >= startTime. An event violating these invariants aborts the build with this message, identifying the offending event by id. This is a second line of defense for callers who bypass the event-v1 import validation.
Solutions
- Fix the event with the id named in the message so its interval is finite, nonnegative, and ordered.
- Validate events with importTrace before feeding them to buildPyramid.
- Normalize all events to one time origin so relative comparisons hold.
Example fix
// before // event id "span-7": startTime 500, endTime 300 buildPyramid(events); // after events.find(e => e.id === 'span-7').endTime = 900; buildPyramid(events);
Defensive patterns
Strategy: validation
Validate before calling
const bad = events.filter(e => !Number.isFinite(e.startTime) || !Number.isFinite(e.endTime)
|| e.startTime < 0 || e.endTime < e.startTime);
if (bad.length) console.warn('invalid intervals:', bad.map(e => e.id)); Try / catch
try { buildPyramid(events) } catch (err) { const m = err.message.match(/Invalid interval for (.+)\./); if (m) fixEvent(m[1]); throw err; } Prevention
- Run importTrace before buildPyramid
- Normalize clocks so endTime always >= startTime
- Drop or fix events with NaN timestamps at ingestion
When it happens
Trigger: Calling buildPyramid with events whose startTime is NaN/Infinity, negative, or whose endTime precedes startTime — typically hand-built events or those from a non-importTrace source.
Common situations: Clock skew producing endTime < startTime, uninitialized timestamps (NaN), or epochs relative to different origins mixed in one array.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Invalid interval for
- Unknown category for
- Unknown category for
- 1
- A pinned task provider requires an explicit model
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/cd6a4f4165d84000.
Report an issue: GitHub.
Appendix: source
Thrown at pet/ios/Resources/pet-native.js:1326
}
const FIELDS = ['onsets', 'activeMs', 'outputTokens', 'cost', 'errors'];
/** O(events + channels × bins), including long intervals. No span-length inner loop. */
function buildPyramid(events, requestedDuration, maxBins = 16_384) {
if (!Number.isInteger(maxBins) || maxBins < 16 || maxBins > 1_048_576)
throw new Error('maxBins must be an integer in [16, 1048576].');
let duration = requestedDuration ?? 1;
for (const e of events)
duration = Math.max(duration, e.endTime, e.startTime, e.status === 'error' ? (0, model_js_1.errorOnsetOf)(e) : 0);
if (!Number.isFinite(duration) || duration < 0)
throw new Error('Signal duration must be finite and nonnegative.');
duration = Math.max(1, duration);
const binMs = 2 ** Math.ceil(Math.log2(Math.max(1, duration / (maxBins - 1))));
const length = Math.floor(duration / binMs) + 1, fine = emptyLevel(length, binMs);
const stride = length + 1;
const activeDiff = new Float64Array(model_js_1.CATEGORIES.length * stride), tokenDiff = new Float64Array(model_js_1.CATEGORIES.length * stride);
for (const e of events) {
if (!Number.isFinite(e.startTime) || !Number.isFinite(e.endTime) || e.startTime < 0 || e.endTime < e.startTime)
throw new Error(`Invalid interval for ${e.id}.`);
const channel = model_js_1.CATEGORIES.indexOf(e.category);
if (channel < 0)
throw new Error(`Unknown category for ${e.id}.`);
const a = Math.floor(e.startTime / binMs), b = Math.floor(e.endTime / binMs);
const at = channel * length, diff = channel * stride;
fine.onsets[at + a]++;
fine.cost[at + a] += e.cost ?? 0;
if (e.status === 'error')
fine.errors[at + Math.floor((0, model_js_1.errorOnsetOf)(e) / binMs)]++;
const d = e.endTime - e.startTime, tokens = e.outputTokens ?? 0;
if (d === 0) {
fine.outputTokens[at + a] += tokens;
continue;
}
if (a === b) {
fine.activeMs[at + a] += d;
fine.outputTokens[at + a] += tokens;
}View on GitHub (pinned to 433685b202)