Hmbown/CodeWhale · error · Error

Invalid Runtime observation horizon.

Error message

Invalid Runtime observation horizon.

What it means

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.

Solutions

  1. Confirm the trace was loaded from a `codewhale.runtime-events/v2` file; re-import with the correct source format.
  2. Ensure `trace.originTime` is a parseable timestamp (ISO 8601 or epoch ms) before calling.
  3. Ensure `observedThrough` is a finite epoch-milliseconds number, e.g. `Date.now()` or `Date.parse(...)` validated with Number.isFinite.
  4. Guard the call site: check `trace.metadata.sourceFormat` and both timestamps with Number.isFinite before invoking.

Example fix

// before
const snapshot = observeRuntimeRequests(trace, lastPollTime);
// after
const at = Date.parse(trace.originTime ?? '');
if (trace.metadata.sourceFormat !== 'codewhale.runtime-events/v2' || !Number.isFinite(at) || !Number.isFinite(lastPollTime)) {
  throw new Error('trace lacks a valid runtime-events/v2 origin or observation horizon');
}
const snapshot = observeRuntimeRequests(trace, lastPollTime);
Defensive patterns

Strategy: type-guard

Validate before calling

const origin = Date.parse(trace.originTime ?? '');
if (trace.metadata.sourceFormat !== 'codewhale.runtime-events/v2') {
  throw new Error('observeRuntimeRequests requires a codewhale.runtime-events/v2 trace');
}
if (!Number.isFinite(origin) || !Number.isFinite(observedThrough)) {
  throw new Error('originTime and observedThrough must be finite epoch timestamps');
}

Type guard

function canObserve(trace, observedThrough) {
  return trace.metadata?.sourceFormat === 'codewhale.runtime-events/v2'
    && Number.isFinite(Date.parse(trace.originTime ?? ''))
    && Number.isFinite(observedThrough);
}

Try / catch

try {
  const snapshot = observeRuntimeRequests(trace, observedThrough);
} catch (e) {
  if (e.message === 'Invalid Runtime observation horizon.') {
    console.error('trace lacks a valid v2 origin/horizon; live observation unavailable');
  } else throw e;
}

Prevention

When it happens

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

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

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/0fd3a2e89bed4056. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tui/pet_watch/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 73e0f67d83)