Hmbown/CodeWhale · error · Error

Invalid Runtime observation horizon.

Error message

Invalid Runtime observation horizon.

What it means

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.

Solutions

  1. Pass a trace produced by fromCodewhaleRuntime (metadata.sourceFormat === 'codewhale.runtime-events/v2').
  2. Ensure the trace has a valid originTime ISO string that Date.parse can convert.
  3. Pass observedThrough as a finite timestamp parseable the same way (e.g. Date.parse of the same clock/format).
  4. Guard the inputs before calling (see validationCode) and fall back to the unmodified trace when they fail.

Example fix

// before
trace = observeRuntimeRequests(trace, 'now');
// after
const origin = Date.parse(trace.originTime ?? '');
const observedThrough = Date.parse(wallClockIso);
if (trace.metadata.sourceFormat === 'codewhale.runtime-events/v2' &&
    Number.isFinite(origin) && Number.isFinite(observedThrough)) {
  trace = observeRuntimeRequests(trace, observedThrough);
}
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

const isCodewhaleTrace = (t) => !!t && typeof t === 'object' && t.metadata?.sourceFormat === 'codewhale.runtime-events/v2' && typeof t.originTime === 'string' && Number.isFinite(Date.parse(t.originTime));

Try / catch

try {
  trace = observeRuntimeRequests(trace, observedThrough);
} catch (e) {
  if (e.message.includes('observation horizon')) {
    console.warn('trace is not a codewhale.runtime-events/v2 trace or horizon invalid; using unmodified trace');
  } else throw e;
}

Prevention

When it happens

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

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

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@433685b202 (2026-09-15). Data as JSON: /api/errors/21ce65b26a121f10. Report an issue: GitHub.

Appendix: source

Thrown at pet/src/core/codewhale.ts:578

        timeUnit: 'ms',
      },
    };
  }
}

export function fromCodewhaleRuntime(records: unknown[], filename = 'Codewhale runtime', maxEvents = 250_000): Trace {
  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. */
export function observeRuntimeRequests(trace: Trace, observedThrough: number): Trace {
  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) };
}

View on GitHub (pinned to 433685b202)