{"record":{"id":"7fd6c989279b528c","repo":"Hmbown/CodeWhale","slug":"invalid-runtime-observation-horizon-pet-native","errorCode":null,"errorMessage":"Invalid Runtime observation horizon.","messagePattern":"Invalid Runtime observation horizon\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/ios/Resources/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/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/ios/Resources/pet-native.js#L2506-L2535","documentation":"observeRuntimeRequests() derives a wall-clock observation window from a trace. It requires the trace to have been built from sourceFormat 'codewhale.runtime-events/v2', a parseable originTime, and a finite observedThrough timestamp. If any of these is missing, relative event times cannot be computed against the observation horizon, so it throws rather than silently mis-mapping event times.","triggerScenarios":"Calling observeRuntimeRequests with (a) a trace whose metadata.sourceFormat is not 'codewhale.runtime-events/v2' (e.g. a session-based trace from fromCodewhaleSession), (b) a trace with missing/unparseable originTime, or (c) observedThrough being NaN/undefined (e.g. Date.parse failure upstream).","commonSituations":"Passing a session-journal trace where a runtime-events trace is expected, a v1 runtime export read by code expecting v2, or computing observedThrough from a bad clock string like '' or 'now'.","solutions":["Verify trace.metadata.sourceFormat === 'codewhale.runtime-events/v2' before calling; use the runtime importer for runtime traces, not the session importer.","Check that trace.originTime parses: Number.isFinite(Date.parse(trace.originTime)). Re-import if originTime is absent.","Ensure observedThrough is a finite epoch-ms number (e.g. Date.now() or a parsed timestamp), not a string or NaN."],"exampleFix":"// before\nconst view = observeRuntimeRequests(anyTrace, opts.through);\n// after\nif (anyTrace.metadata.sourceFormat !== 'codewhale.runtime-events/v2' || !Number.isFinite(opts.through)) return;\nconst view = observeRuntimeRequests(anyTrace, opts.through);","handlingStrategy":"validation","validationCode":"const ok = trace.metadata.sourceFormat === 'codewhale.runtime-events/v2'\n  && Number.isFinite(Date.parse(trace.originTime ?? ''))\n  && Number.isFinite(observedThrough);\nif (!ok) throw new Error('trace not observable');\nconst view = observeRuntimeRequests(trace, observedThrough);","typeGuard":"const isRuntimeV2Trace = (t: any): boolean => t?.metadata?.sourceFormat === 'codewhale.runtime-events/v2' && Number.isFinite(Date.parse(t?.originTime ?? ''));","tryCatchPattern":"try { view = observeRuntimeRequests(trace, through); }\ncatch (e) { if (e.message.includes('observation horizon')) { log.warn('unobservable trace', trace.metadata.sourceFormat); return null; } throw e; }","preventionTips":["Only feed runtime-importer traces to observeRuntimeRequests, never session traces.","Parse observedThrough with Date.parse and check Number.isFinite at the boundary.","Pin exporter/importer versions so sourceFormat stays v2."],"tags":["import","version-mismatch","timestamp"],"backgroundTag":"incompatible-source-type","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"}