{"record":{"id":"733c80df43268aae","repo":"Hmbown/CodeWhale","slug":"invalid-pet-clock-origin","errorCode":null,"errorMessage":"Invalid pet clock origin.","messagePattern":"Invalid pet clock origin\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/pet_watch/pet-native.js","lineNumber":1175,"sourceCode":"    }\n}\nexports.PetLiveTape = PetLiveTape;\nconst order = (a, b) => a < b ? -1 : a > b ? 1 : 0;\nconst keyOf = (e) => JSON.stringify([e.traceId, e.id]);\nconst isContainer = (e) => e.attributes['whalesong.container'] === true\n    || e.attributes['codewhale.container'] === true;\n/** Compile a single trace. Unknown-duration spans provide onsets, not occupancy.\n * Updates of the same trace/id replace earlier snapshots rather than double count.\n * An endpoint onset gets its own bucket; intervals use [start, end). */\nfunction compilePetTelemetry(input, durationMs = 0, firstSequence = 0, originMs = 0) {\n    if (input.length > 250_000)\n        throw new Error('Pet input exceeds 250000 events.');\n    if (!Number.isFinite(durationMs) || durationMs < 0)\n        throw new Error('Invalid pet duration.');\n    if (!Number.isSafeInteger(firstSequence) || firstSequence < 0)\n        throw new Error('Invalid first pet bucket.');\n    if (!Number.isFinite(originMs))\n        throw new Error('Invalid pet clock origin.');\n    durationMs = Math.max(0, durationMs - originMs);\n    const unique = new Map();\n    const traces = new Set();\n    for (const e of input) {\n        if (e.schemaVersion !== 1 || !e.id || !e.traceId || !model_js_1.CATEGORIES.includes(e.category)\n            || !Number.isFinite(e.startTime) || !Number.isFinite(e.endTime)\n            || e.startTime < 0 || e.endTime < e.startTime || !e.attributes)\n            throw new Error('Invalid event-v1 pet input. Import through importTrace first.');\n        traces.add(e.traceId);\n        unique.set(keyOf(e), e);\n    }\n    if (traces.size > 1)\n        throw new Error('Select one trace for the pet.');\n    const parents = new Set([...unique.values()].filter(e => e.parentId).map(e => e.parentId));\n    const events = [...unique.values()].filter(e => !isContainer(e)\n        && !(e.category === 'orchestration' && parents.has(e.id)))\n        .map(e => ({ ...e, startTime: e.startTime - originMs, endTime: (e.openEnded ? e.startTime : e.endTime) - originMs,\n        attributes: e.attributes['whalesong.error_onset_ms'] === undefined ? e.attributes","sourceCodeStart":1157,"sourceCodeEnd":1193,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/pet_watch/pet-native.js#L1157-L1193","documentation":"compilePetTelemetry() validates its originMs parameter, which is the clock origin subtracted from event times and duration to normalize the replay to t=0. The library throws this error when originMs is not a finite number (NaN, Infinity, or a non-numeric value), because such an origin would poison every computed timestamp.","triggerScenarios":"Calling compilePetTelemetry(input, durationMs, firstSequence, originMs) with originMs = undefined/NaN (e.g. Date.now() result lost, a missing field from deserialized trace metadata), Infinity (e.g. Math.max over an empty array), or a string from JSON config.","commonSituations":"Trace metadata missing its start timestamp so originMs defaults to undefined; Math.min(...[]) returning Infinity for an empty trace; a versioned session file from an older schema lacking the origin field; passing a locale-formatted time string instead of epoch milliseconds.","solutions":["Default the origin explicitly: const originMs = traceStartMs ?? 0; before calling.","Validate Number.isFinite(originMs) at the call site and fall back to 0 when invalid.","Check the source object actually has the timestamp field populated (schemaVersion 1 traces must carry it); re-import via importTrace if it is missing.","Parse any non-numeric input with Number() and reject non-finite results early."],"exampleFix":"// before\ncompilePetTelemetry(events, durationMs, 0, trace.startedAt); // undefined\n// after\nconst originMs = Number.isFinite(trace.startedAt) ? trace.startedAt : 0;\ncompilePetTelemetry(events, durationMs, 0, originMs);","handlingStrategy":"validation","validationCode":"if (!Number.isFinite(originMs)) originMs = 0;\ncompilePetTelemetry(events, durationMs, firstSequence, originMs);","typeGuard":"const isFiniteNumber = (v) => typeof v === 'number' && Number.isFinite(v);","tryCatchPattern":"try {\n  compilePetTelemetry(events, durationMs, 0, originMs);\n} catch (e) {\n  if (e.message === 'Invalid pet clock origin.') {\n    return compilePetTelemetry(events, durationMs, 0, 0);\n  }\n  throw e;\n}","preventionTips":["Default the trace origin to 0 when metadata lacks a start timestamp","Never pass Math.min/Math.max results from possibly-empty arrays unchecked","Coerce config/JSON strings with Number() and reject NaN early"],"tags":["parameter-validation","javascript"],"backgroundTag":"invalid-argument-value","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}