{"record":{"id":"0fd3a2e89bed4056","repo":"Hmbown/CodeWhale","slug":"invalid-runtime-observation-horizon","errorCode":null,"errorMessage":"Invalid Runtime observation horizon.","messagePattern":"Invalid Runtime observation horizon\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/pet_watch/pet-native.js","lineNumber":2524,"sourceCode":"        };\n    }\n}\nexports.CodewhaleRuntimeTrace = CodewhaleRuntimeTrace;\nfunction fromCodewhaleRuntime(records, filename = 'Codewhale runtime', maxEvents = 250_000) {\n    if (!records.length)\n        throw new Error('Codewhale runtime event file is empty.');\n    const trace = new CodewhaleRuntimeTrace(filename, maxEvents);\n    trace.append(records);\n    return trace.snapshot();\n}\n/** The journal owns request state until a matching terminal receipt. A live\n * driver may confirm that state only while its cursor-checked stream is healthy.\n * Ordinary open tool spans remain unknown-duration; no execution is inferred. */\nfunction observeRuntimeRequests(trace, observedThrough) {\n    const origin = Date.parse(trace.originTime ?? '');\n    if (trace.metadata.sourceFormat !== 'codewhale.runtime-events/v2' || !Number.isFinite(origin)\n        || !Number.isFinite(observedThrough))\n        throw new Error('Invalid Runtime observation horizon.');\n    const at = observedThrough - origin;\n    const events = trace.events.map(e => e.openEnded && e.attributes['whalesong.waiting'] === true && at >= e.startTime\n        ? { ...e, endTime: at, openEnded: false } : e);\n    return { ...trace, events, duration: Math.max(trace.duration, at) };\n}\n\n};\nfunction load(id){id=id.replace(/^\\.\\//,'').replace(/\\.js$/,'');if(cache[id])return cache[id];if(!factories[id])throw Error('Missing core module');const e=cache[id]={};factories[id](e,load);return e;}\nglobal.PetNative=load('pet-native').PetNative;\n})(globalThis);\n","sourceCodeStart":2506,"sourceCodeEnd":2535,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/pet_watch/pet-native.js#L2506-L2535","documentation":"Thrown by `observeRuntimeRequests` in pet-native.js when the observation-horizon preconditions fail: the trace's `sourceFormat` metadata is not `codewhale.runtime-events/v2`, or either `trace.originTime` or the `observedThrough` timestamp cannot be parsed to a finite number. The function needs a valid origin and horizon to compute live 'waiting' durations.","triggerScenarios":"Calling `observeRuntimeRequests(trace, observedThrough)` with a trace produced by another format (not runtime-events/v2), a trace whose `originTime` is null/undefined/malformed, or `observedThrough` that is undefined, NaN, or not a parseable date value (Date.parse fails).","commonSituations":"Feeding a v1 or legacy trace file to the live-observation API; an originTime written as a non-ISO string; passing a Date object where a numeric/ISO timestamp is expected; clock/horizon value never initialized because the driver never observed the stream.","solutions":["Confirm the trace was loaded from a `codewhale.runtime-events/v2` file; re-import with the correct source format.","Ensure `trace.originTime` is a parseable timestamp (ISO 8601 or epoch ms) before calling.","Ensure `observedThrough` is a finite epoch-milliseconds number, e.g. `Date.now()` or `Date.parse(...)` validated with Number.isFinite.","Guard the call site: check `trace.metadata.sourceFormat` and both timestamps with Number.isFinite before invoking."],"exampleFix":"// before\nconst snapshot = observeRuntimeRequests(trace, lastPollTime);\n// after\nconst at = Date.parse(trace.originTime ?? '');\nif (trace.metadata.sourceFormat !== 'codewhale.runtime-events/v2' || !Number.isFinite(at) || !Number.isFinite(lastPollTime)) {\n  throw new Error('trace lacks a valid runtime-events/v2 origin or observation horizon');\n}\nconst snapshot = observeRuntimeRequests(trace, lastPollTime);","handlingStrategy":"type-guard","validationCode":"const origin = Date.parse(trace.originTime ?? '');\nif (trace.metadata.sourceFormat !== 'codewhale.runtime-events/v2') {\n  throw new Error('observeRuntimeRequests requires a codewhale.runtime-events/v2 trace');\n}\nif (!Number.isFinite(origin) || !Number.isFinite(observedThrough)) {\n  throw new Error('originTime and observedThrough must be finite epoch timestamps');\n}","typeGuard":"function canObserve(trace, observedThrough) {\n  return trace.metadata?.sourceFormat === 'codewhale.runtime-events/v2'\n    && Number.isFinite(Date.parse(trace.originTime ?? ''))\n    && Number.isFinite(observedThrough);\n}","tryCatchPattern":"try {\n  const snapshot = observeRuntimeRequests(trace, observedThrough);\n} catch (e) {\n  if (e.message === 'Invalid Runtime observation horizon.') {\n    console.error('trace lacks a valid v2 origin/horizon; live observation unavailable');\n  } else throw e;\n}","preventionTips":["Only call observe* on traces imported from codewhale.runtime-events/v2 files.","Pass observedThrough as epoch milliseconds (Number.isFinite-checked), never a Date object or unparsed string.","Validate originTime parses right after import, before any observation call.","Initialize the observation horizon when the driver stream opens, not lazily."],"tags":["trace-import","timestamp","validation"],"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-22T11:17:16.035Z"}