{"record":{"id":"21ce65b26a121f10","repo":"Hmbown/CodeWhale","slug":"invalid-runtime-observation-horizon-codewhale","errorCode":null,"errorMessage":"Invalid Runtime observation horizon.","messagePattern":"Invalid Runtime observation horizon\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/src/core/codewhale.ts","lineNumber":578,"sourceCode":"        timeUnit: 'ms',\n      },\n    };\n  }\n}\n\nexport function fromCodewhaleRuntime(records: unknown[], filename = 'Codewhale runtime', maxEvents = 250_000): Trace {\n  if (!records.length) throw new Error('Codewhale runtime event file is empty.');\n  const trace = new CodewhaleRuntimeTrace(filename, maxEvents);\n  trace.append(records); return trace.snapshot();\n}\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. */\nexport function observeRuntimeRequests(trace: Trace, observedThrough: number): Trace {\n  const origin = Date.parse(trace.originTime ?? '');\n  if (trace.metadata.sourceFormat !== 'codewhale.runtime-events/v2' || !Number.isFinite(origin)\n    || !Number.isFinite(observedThrough)) 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","sourceCodeStart":560,"sourceCodeEnd":584,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/core/codewhale.ts#L560-L584","documentation":"observeRuntimeRequests closes open-ended waiting requests in a trace as of an observation time. It requires a trace produced by the Codewhale runtime importer (sourceFormat 'codewhale.runtime-events/v2'), a parseable originTime, and a finite observedThrough timestamp; anything else makes the observedThrough-origin offset meaningless, so the call is rejected.","triggerScenarios":"Calling observeRuntimeRequests with a trace from another importer; passing observedThrough as NaN/undefined; a trace whose originTime is missing or not an ISO date string Date.parse can parse.","commonSituations":"Feeding a hand-built or synthetically constructed trace object; passing a wall-clock string in a different field or a numeric epoch where an ISO timestamp is expected; forgetting that originTime must be set on the trace; reusing a trace from an older runtime format.","solutions":["Pass a trace produced by fromCodewhaleRuntime (metadata.sourceFormat === 'codewhale.runtime-events/v2').","Ensure the trace has a valid originTime ISO string that Date.parse can convert.","Pass observedThrough as a finite timestamp parseable the same way (e.g. Date.parse of the same clock/format).","Guard the inputs before calling (see validationCode) and fall back to the unmodified trace when they fail."],"exampleFix":"// before\ntrace = observeRuntimeRequests(trace, 'now');\n// after\nconst origin = Date.parse(trace.originTime ?? '');\nconst observedThrough = Date.parse(wallClockIso);\nif (trace.metadata.sourceFormat === 'codewhale.runtime-events/v2' &&\n    Number.isFinite(origin) && Number.isFinite(observedThrough)) {\n  trace = observeRuntimeRequests(trace, observedThrough);\n}","handlingStrategy":"validation","validationCode":"function canObserve(trace, observedThrough) {\n  const origin = Date.parse(trace?.originTime ?? '');\n  return trace?.metadata?.sourceFormat === 'codewhale.runtime-events/v2'\n    && Number.isFinite(origin) && Number.isFinite(observedThrough);\n}","typeGuard":"const isCodewhaleTrace = (t) => !!t && typeof t === 'object' && t.metadata?.sourceFormat === 'codewhale.runtime-events/v2' && typeof t.originTime === 'string' && Number.isFinite(Date.parse(t.originTime));","tryCatchPattern":"try {\n  trace = observeRuntimeRequests(trace, observedThrough);\n} catch (e) {\n  if (e.message.includes('observation horizon')) {\n    console.warn('trace is not a codewhale.runtime-events/v2 trace or horizon invalid; using unmodified trace');\n  } else throw e;\n}","preventionTips":["Only call observeRuntimeRequests on traces produced by fromCodewhaleRuntime.","Always derive observedThrough from the same clock/format as originTime (Date.parse-compatible ISO).","Guard against undefined/NaN observedThrough from failed date parsing before calling.","Keep traces in the v2 format; migrate hand-built traces to the importer instead of constructing them manually."],"tags":["codewhale","validation","trace","timestamp"],"backgroundTag":"invalid-argument-value","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"}