Hmbown/CodeWhale · error · Error

Invalid Runtime observation horizon.

Error message

Invalid Runtime observation horizon.

What it means

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.

Solutions

  1. Verify trace.metadata.sourceFormat === 'codewhale.runtime-events/v2' before calling; use the runtime importer for runtime traces, not the session importer.
  2. Check that trace.originTime parses: Number.isFinite(Date.parse(trace.originTime)). Re-import if originTime is absent.
  3. Ensure observedThrough is a finite epoch-ms number (e.g. Date.now() or a parsed timestamp), not a string or NaN.

Example fix

// before
const view = observeRuntimeRequests(anyTrace, opts.through);
// after
if (anyTrace.metadata.sourceFormat !== 'codewhale.runtime-events/v2' || !Number.isFinite(opts.through)) return;
const view = observeRuntimeRequests(anyTrace, opts.through);
Defensive patterns

Strategy: validation

Validate before calling

const ok = trace.metadata.sourceFormat === 'codewhale.runtime-events/v2'
  && Number.isFinite(Date.parse(trace.originTime ?? ''))
  && Number.isFinite(observedThrough);
if (!ok) throw new Error('trace not observable');
const view = observeRuntimeRequests(trace, observedThrough);

Type guard

const isRuntimeV2Trace = (t: any): boolean => t?.metadata?.sourceFormat === 'codewhale.runtime-events/v2' && Number.isFinite(Date.parse(t?.originTime ?? ''));

Try / catch

try { view = observeRuntimeRequests(trace, through); }
catch (e) { if (e.message.includes('observation horizon')) { log.warn('unobservable trace', trace.metadata.sourceFormat); return null; } throw e; }

Prevention

When it happens

Trigger: 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).

Common situations: 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'.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/7fd6c989279b528c. Report an issue: GitHub.

Appendix: source

Thrown at pet/ios/Resources/pet-native.js:2524

        };
    }
}
exports.CodewhaleRuntimeTrace = CodewhaleRuntimeTrace;
function fromCodewhaleRuntime(records, filename = 'Codewhale runtime', maxEvents = 250_000) {
    if (!records.length)
        throw new Error('Codewhale runtime event file is empty.');
    const trace = new CodewhaleRuntimeTrace(filename, maxEvents);
    trace.append(records);
    return trace.snapshot();
}
/** The journal owns request state until a matching terminal receipt. A live
 * driver may confirm that state only while its cursor-checked stream is healthy.
 * Ordinary open tool spans remain unknown-duration; no execution is inferred. */
function observeRuntimeRequests(trace, observedThrough) {
    const origin = Date.parse(trace.originTime ?? '');
    if (trace.metadata.sourceFormat !== 'codewhale.runtime-events/v2' || !Number.isFinite(origin)
        || !Number.isFinite(observedThrough))
        throw new Error('Invalid Runtime observation horizon.');
    const at = observedThrough - origin;
    const events = trace.events.map(e => e.openEnded && e.attributes['whalesong.waiting'] === true && at >= e.startTime
        ? { ...e, endTime: at, openEnded: false } : e);
    return { ...trace, events, duration: Math.max(trace.duration, at) };
}

};
function 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;}
global.PetNative=load('pet-native').PetNative;
})(globalThis);

View on GitHub (pinned to 433685b202)