Hmbown/CodeWhale · error · Error

Invalid pet clock origin.

Error message

Invalid pet clock origin.

What it means

compilePetTelemetry() validates its originMs parameter, which is the clock origin subtracted from event times and duration to normalize the replay to t=0. The library throws this error when originMs is not a finite number (NaN, Infinity, or a non-numeric value), because such an origin would poison every computed timestamp.

Solutions

  1. Default the origin explicitly: const originMs = traceStartMs ?? 0; before calling.
  2. Validate Number.isFinite(originMs) at the call site and fall back to 0 when invalid.
  3. Check the source object actually has the timestamp field populated (schemaVersion 1 traces must carry it); re-import via importTrace if it is missing.
  4. Parse any non-numeric input with Number() and reject non-finite results early.

Example fix

// before
compilePetTelemetry(events, durationMs, 0, trace.startedAt); // undefined
// after
const originMs = Number.isFinite(trace.startedAt) ? trace.startedAt : 0;
compilePetTelemetry(events, durationMs, 0, originMs);
Defensive patterns

Strategy: validation

Validate before calling

if (!Number.isFinite(originMs)) originMs = 0;
compilePetTelemetry(events, durationMs, firstSequence, originMs);

Type guard

const isFiniteNumber = (v) => typeof v === 'number' && Number.isFinite(v);

Try / catch

try {
  compilePetTelemetry(events, durationMs, 0, originMs);
} catch (e) {
  if (e.message === 'Invalid pet clock origin.') {
    return compilePetTelemetry(events, durationMs, 0, 0);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling compilePetTelemetry(input, durationMs, firstSequence, originMs) with originMs = undefined/NaN (e.g. Date.now() result lost, a missing field from deserialized trace metadata), Infinity (e.g. Math.max over an empty array), or a string from JSON config.

Common situations: Trace metadata missing its start timestamp so originMs defaults to undefined; Math.min(...[]) returning Infinity for an empty trace; a versioned session file from an older schema lacking the origin field; passing a locale-formatted time string instead of epoch milliseconds.

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/733c80df43268aae. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tui/pet_watch/pet-native.js:1175

    }
}
exports.PetLiveTape = PetLiveTape;
const order = (a, b) => a < b ? -1 : a > b ? 1 : 0;
const keyOf = (e) => JSON.stringify([e.traceId, e.id]);
const isContainer = (e) => e.attributes['whalesong.container'] === true
    || e.attributes['codewhale.container'] === true;
/** Compile a single trace. Unknown-duration spans provide onsets, not occupancy.
 * Updates of the same trace/id replace earlier snapshots rather than double count.
 * An endpoint onset gets its own bucket; intervals use [start, end). */
function compilePetTelemetry(input, durationMs = 0, firstSequence = 0, originMs = 0) {
    if (input.length > 250_000)
        throw new Error('Pet input exceeds 250000 events.');
    if (!Number.isFinite(durationMs) || durationMs < 0)
        throw new Error('Invalid pet duration.');
    if (!Number.isSafeInteger(firstSequence) || firstSequence < 0)
        throw new Error('Invalid first pet bucket.');
    if (!Number.isFinite(originMs))
        throw new Error('Invalid pet clock origin.');
    durationMs = Math.max(0, durationMs - originMs);
    const unique = new Map();
    const traces = new Set();
    for (const e of input) {
        if (e.schemaVersion !== 1 || !e.id || !e.traceId || !model_js_1.CATEGORIES.includes(e.category)
            || !Number.isFinite(e.startTime) || !Number.isFinite(e.endTime)
            || e.startTime < 0 || e.endTime < e.startTime || !e.attributes)
            throw new Error('Invalid event-v1 pet input. Import through importTrace first.');
        traces.add(e.traceId);
        unique.set(keyOf(e), e);
    }
    if (traces.size > 1)
        throw new Error('Select one trace for the pet.');
    const parents = new Set([...unique.values()].filter(e => e.parentId).map(e => e.parentId));
    const events = [...unique.values()].filter(e => !isContainer(e)
        && !(e.category === 'orchestration' && parents.has(e.id)))
        .map(e => ({ ...e, startTime: e.startTime - originMs, endTime: (e.openEnded ? e.startTime : e.endTime) - originMs,
        attributes: e.attributes['whalesong.error_onset_ms'] === undefined ? e.attributes

View on GitHub (pinned to 73e0f67d83)