{"record":{"id":"4bfeef0946581d1b","repo":"Hmbown/CodeWhale","slug":"pet-replay-exceeds-24-hours-select-a-shorter-trace","errorCode":null,"errorMessage":"Pet replay exceeds 24 hours; select a shorter trace.","messagePattern":"Pet replay exceeds 24 hours; select a shorter trace\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/pet_watch/pet-native.js","lineNumber":1206,"sourceCode":"        throw new Error('Select one trace for the pet.');\n    const parents = new Set([...unique.values()].filter(e => e.parentId).map(e => e.parentId));\n    const events = [...unique.values()].filter(e => !isContainer(e)\n        && !(e.category === 'orchestration' && parents.has(e.id)))\n        .map(e => ({ ...e, startTime: e.startTime - originMs, endTime: (e.openEnded ? e.startTime : e.endTime) - originMs,\n        attributes: e.attributes['whalesong.error_onset_ms'] === undefined ? e.attributes\n            : { ...e.attributes, 'whalesong.error_onset_ms': (0, model_js_1.errorOnsetOf)(e) - originMs } }))\n        .sort((a, b) => a.startTime - b.startTime || order(a.id, b.id));\n    let lastOnset = 0;\n    for (const e of events) {\n        durationMs = Math.max(durationMs, e.endTime);\n        lastOnset = Math.max(lastOnset, e.startTime);\n    }\n    const failures = events.filter(e => e.category === 'error' || e.status === 'error').map(model_js_1.errorOnsetOf).sort((a, b) => a - b);\n    if (failures.length)\n        lastOnset = Math.max(lastOnset, failures[failures.length - 1]);\n    const count = Math.max(1, Math.ceil(durationMs / exports.PET_BIN_MS), Math.floor(lastOnset / exports.PET_BIN_MS) + 1);\n    if (count - firstSequence > 216_000 || count > pet_sim_js_1.PET_MAX_SECONDS * 2.5)\n        throw new Error('Pet replay exceeds 24 hours; select a shorter trace.');\n    const index = new signal_js_1.IntervalIndex(events), result = [];\n    const recent = [], names = new Map();\n    let next = 0, expired = 0, nextFailure = 0;\n    for (let sequence = firstSequence; sequence < count; sequence++) {\n        const start = sequence * exports.PET_BIN_MS, end = start + exports.PET_BIN_MS;\n        // A trailing window only: appending future events cannot rewrite earlier bins.\n        while (next < events.length && events[next].startTime < end) {\n            const e = events[next++];\n            // A liveness pulse continues an operation; it is not a repeated tool call.\n            if (e.attributes['whalesong.continuation'] === true)\n                continue;\n            recent.push(e);\n            names.set(e.name, (names.get(e.name) ?? 0) + 1);\n        }\n        while (expired < recent.length && recent[expired].startTime < end - 12_000) {\n            const name = recent[expired++].name, n = names.get(name) - 1;\n            if (n)\n                names.set(name, n);","sourceCodeStart":1188,"sourceCodeEnd":1224,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/pet_watch/pet-native.js#L1188-L1224","documentation":"compilePetTelemetry() computes the number of replay bins (count) from durationMs and the last error onset and rejects replays that would exceed roughly 24 hours (more than 216,000 bins of PET_BIN_MS, or beyond PET_MAX_SECONDS * 2.5 counting from firstSequence). The pet audio simulation is bounded, so very long traces cannot be compiled.","triggerScenarios":"Compiling a trace whose duration (after subtracting originMs) exceeds the ~24h limit; a trace with a huge error-onset timestamp (e.g. an epoch-ms value not normalized) inflating lastOnset and thus count; forgetting to pass originMs so absolute timestamps are treated as durations.","commonSituations":"Selecting an overnight/long-running session trace; a bug where errorOnsetOf returns an absolute epoch time instead of a relative offset; originMs omitted or 0 while events carry epoch-millisecond timestamps, making durationMs appear enormous.","solutions":["Select a shorter trace (as the message says) or trim the input to a bounded time window before compiling.","Verify originMs is passed and equals the trace start so durations are relative, not epoch-scale.","Check errorOnsetOf values are relative offsets; normalize absolute timestamps before compiling.","If long replays are legitimately needed, raise the limit in pet_sim (PET_MAX_SECONDS) consciously — don't patch the caller."],"exampleFix":"// before\ncompilePetTelemetry(events, sessionEnd - 0, 0); // durationMs is epoch-scale\n// after\nconst originMs = events[0].startTime;\ncompilePetTelemetry(events, sessionEnd - originMs, 0, originMs);","handlingStrategy":"validation","validationCode":"const MAX_BINS = 216_000;\nconst originMs = events[0]?.startTime ?? 0;\nconst dur = Math.max(0, durationMs - originMs);\nif (Math.ceil(dur / PET_BIN_MS) > MAX_BINS) {\n  throw new UserFacingError('Trace too long for pet replay');\n}","typeGuard":null,"tryCatchPattern":"try {\n  return compilePetTelemetry(events, durationMs, first, originMs);\n} catch (e) {\n  if (e.message.includes('exceeds 24 hours')) {\n    return compilePetTelemetry(trimToWindow(events, MAX_DURATION_MS), Math.min(durationMs, MAX_DURATION_MS), first, originMs);\n  }\n  throw e;\n}","preventionTips":["Always pass a correct originMs so durations are relative, not epoch-scale","Verify error onsets are relative offsets, not absolute timestamps","Trim or chunk long traces to a bounded window before compiling"],"tags":["limit","duration"],"backgroundTag":"value-out-of-range","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}