{"record":{"id":"508cebfe613d6296","repo":"Hmbown/CodeWhale","slug":"runtime-observation-exceeds-its-retained-input-limit","errorCode":null,"errorMessage":"Runtime observation exceeds its retained input limit.","messagePattern":"Runtime observation exceeds its retained input limit\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/pet_watch/pet-native.js","lineNumber":2256,"sourceCode":"    origin;\n    model;\n    threadId;\n    threadName;\n    constructor(filename = 'Codewhale runtime', maxEvents = 250_000, project = event => event, maxBytes = Infinity) {\n        this.filename = filename;\n        this.maxEvents = maxEvents;\n        this.project = project;\n        this.maxBytes = maxBytes;\n    }\n    get retainedEvents() { return this.events.length; }\n    get retainedBytes() { return this.bytes; }\n    measure(event, proposed = event) {\n        const safe = this.project(proposed);\n        if (this.maxBytes !== Infinity) {\n            const size = new TextEncoder().encode(JSON.stringify(safe)).length;\n            const total = this.bytes - (this.sizes.get(event) ?? 0) + size;\n            if (total > this.maxBytes)\n                throw new Error('Runtime observation exceeds its retained input limit.');\n            this.bytes = total;\n            this.sizes.set(event, size);\n        }\n        for (const key of Object.keys(event))\n            if (!Object.hasOwn(safe, key))\n                delete event[key];\n        Object.assign(event, safe);\n    }\n    push(event) {\n        if (this.events.length >= this.maxEvents)\n            throw new Error(`Import exceeds the ${this.maxEvents.toLocaleString()} event limit.`);\n        this.measure(event);\n        pushEvent(this.events, event);\n    }\n    /** Keep unfinished lifetimes plus the recent window needed by the bucketer's\n     * 12-second recurrence measure. A completion may still arrive for any open item. */\n    prune(beforeWall) {\n        if (!Number.isFinite(beforeWall))","sourceCodeStart":2238,"sourceCodeEnd":2274,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/pet_watch/pet-native.js#L2238-L2274","documentation":"The Runtime importer retains events under a byte budget (maxBytes). measure() projects each event to its retained shape, serializes it, and adds its size to the running total. If the total would exceed maxBytes, the import throws instead of silently dropping data. This enforces a hard memory bound on runtime observation retention.","triggerScenarios":"Pushing an event into a Runtime whose accumulated retained bytes plus the new event's serialized size exceed maxBytes; typically during import of a large runtime event stream or after many pushes into a long-lived Runtime instance.","commonSituations":"Importing a very large runtime export with the default byte budget; building one Runtime across many threads/sessions until the budget is exhausted; setting a small maxBytes for testing and forgetting it in production code.","solutions":["Increase the Runtime's maxBytes budget to accommodate the expected stream size.","Call prune(beforeWall) to drop completed events outside the retention window before pushing more.","Import the runtime stream in chunks into separate Runtime instances.","Serialize/drop large payload fields before pushing events."],"exampleFix":"// before\nconst rt = new Runtime({ maxBytes: 1024 * 1024 });\n// after\nconst rt = new Runtime({ maxBytes: 64 * 1024 * 1024 });","handlingStrategy":"try-catch","validationCode":"const approxBytes = (e) => new TextEncoder().encode(JSON.stringify(e)).length;\nif (approxBytes(event) > runtime.maxBytes) trimEvent(event);","typeGuard":null,"tryCatchPattern":"try { rt.push(event); } catch (e) { if (e.message.includes('retained input limit')) { rt.prune(Date.now()); rt.push(event); } else throw e; }","preventionTips":["Set maxBytes well above the expected stream size.","Prune periodically during long imports.","Strip large payload fields before pushing.","Monitor rt.bytes growth in long-lived runtimes."],"tags":["memory","limit","runtime"],"backgroundTag":"payload-too-large","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}