{"record":{"id":"cd6a4f4165d84000","repo":"Hmbown/CodeWhale","slug":"invalid-interval-for-e-id-pet-native","errorCode":null,"errorMessage":"Invalid interval for ${e.id}.","messagePattern":"Invalid interval for (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/ios/Resources/pet-native.js","lineNumber":1326,"sourceCode":"}\nconst FIELDS = ['onsets', 'activeMs', 'outputTokens', 'cost', 'errors'];\n/** O(events + channels × bins), including long intervals. No span-length inner loop. */\nfunction buildPyramid(events, requestedDuration, maxBins = 16_384) {\n    if (!Number.isInteger(maxBins) || maxBins < 16 || maxBins > 1_048_576)\n        throw new Error('maxBins must be an integer in [16, 1048576].');\n    let duration = requestedDuration ?? 1;\n    for (const e of events)\n        duration = Math.max(duration, e.endTime, e.startTime, e.status === 'error' ? (0, model_js_1.errorOnsetOf)(e) : 0);\n    if (!Number.isFinite(duration) || duration < 0)\n        throw new Error('Signal duration must be finite and nonnegative.');\n    duration = Math.max(1, duration);\n    const binMs = 2 ** Math.ceil(Math.log2(Math.max(1, duration / (maxBins - 1))));\n    const length = Math.floor(duration / binMs) + 1, fine = emptyLevel(length, binMs);\n    const stride = length + 1;\n    const activeDiff = new Float64Array(model_js_1.CATEGORIES.length * stride), tokenDiff = new Float64Array(model_js_1.CATEGORIES.length * stride);\n    for (const e of events) {\n        if (!Number.isFinite(e.startTime) || !Number.isFinite(e.endTime) || e.startTime < 0 || e.endTime < e.startTime)\n            throw new Error(`Invalid interval for ${e.id}.`);\n        const channel = model_js_1.CATEGORIES.indexOf(e.category);\n        if (channel < 0)\n            throw new Error(`Unknown category for ${e.id}.`);\n        const a = Math.floor(e.startTime / binMs), b = Math.floor(e.endTime / binMs);\n        const at = channel * length, diff = channel * stride;\n        fine.onsets[at + a]++;\n        fine.cost[at + a] += e.cost ?? 0;\n        if (e.status === 'error')\n            fine.errors[at + Math.floor((0, model_js_1.errorOnsetOf)(e) / binMs)]++;\n        const d = e.endTime - e.startTime, tokens = e.outputTokens ?? 0;\n        if (d === 0) {\n            fine.outputTokens[at + a] += tokens;\n            continue;\n        }\n        if (a === b) {\n            fine.activeMs[at + a] += d;\n            fine.outputTokens[at + a] += tokens;\n        }","sourceCodeStart":1308,"sourceCodeEnd":1344,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/ios/Resources/pet-native.js#L1308-L1344","documentation":"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.","triggerScenarios":"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.","commonSituations":"Clock skew producing endTime < startTime, uninitialized timestamps (NaN), or epochs relative to different origins mixed in one array.","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."],"exampleFix":"// before\n// event id \"span-7\": startTime 500, endTime 300\nbuildPyramid(events);\n// after\nevents.find(e => e.id === 'span-7').endTime = 900;\nbuildPyramid(events);","handlingStrategy":"validation","validationCode":"const bad = events.filter(e => !Number.isFinite(e.startTime) || !Number.isFinite(e.endTime)\n  || e.startTime < 0 || e.endTime < e.startTime);\nif (bad.length) console.warn('invalid intervals:', bad.map(e => e.id));","typeGuard":null,"tryCatchPattern":"try { buildPyramid(events) } catch (err) { const m = err.message.match(/Invalid interval for (.+)\\./); if (m) fixEvent(m[1]); throw err; }","preventionTips":["Run importTrace before buildPyramid","Normalize clocks so endTime always >= startTime","Drop or fix events with NaN timestamps at ingestion"],"tags":["validation","intervals","events"],"backgroundTag":"schema-validation-failed","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}