Hmbown/CodeWhale · error · Error
Runtime event frame exceeds the size limit
Error message
Runtime event frame exceeds the size limit
What it means
parseEventStream() enforces a per-frame SSE size limit (2 MiB for thread events). When a single buffered event frame between boundaries exceeds maxFrameChars, it throws. This guards against runaway or malicious events exhausting memory while consuming fleetEvents/threadEvents streams.
Solutions
- Reduce the size of individual events the runtime emits (truncate tool output/diffs at the source).
- Upgrade the runtime so large payloads are chunked into smaller events or bounded fragments.
- Catch the error and skip/replay the problematic thread rather than consuming it whole.
- If legitimately needed, use a client/path variant with a larger maxFrameChars.
Example fix
// before
for await (const ev of client.threadEvents(id)) handle(ev);
// after
try {
for await (const ev of client.threadEvents(id)) handle(ev);
} catch (err) {
if (err.message.includes("exceeds the size limit")) return handleOversizedThread(id);
throw err;
} Defensive patterns
Strategy: try-catch
Try / catch
try { for await (const ev of client.threadEvents(id)) handle(ev); } catch (err) { if (err.message.includes("exceeds the size limit")) return quarantineThread(id); throw err; } Prevention
- Bound tool outputs and diffs at write time on the runtime so SSE frames stay small.
- Do not consume event streams from untrusted runtimes without this guard in place.
- Monitor for this error in production — it usually indicates oversized events that should be chunked.
When it happens
Trigger: A runtime emits one SSE event whose serialized frame (up to the blank-line boundary) exceeds 2 MiB — e.g. an enormous tool output or diff embedded in a single event during replay.
Common situations: Replaying threads that captured very large tool outputs before truncation policies existed; a buggy runtime writing an unterminated giant event; a compromised endpoint flooding frames.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
Related errors
- Chat Completions stream closed before [DONE] or…
- ${compactRuntimeError(response.status, body)}
- {err}
- {err}
- {err}
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/9759a50640849a6b.
Report an issue: GitHub.
Appendix: source
Thrown at npm/runtime-sdk/index.js:244
}
async function readErrorBody(response) {
try {
const text = await response.text();
return text.length > 4096 ? `${text.slice(0, 4096)}...` : text;
} catch {
return "";
}
}
async function* parseEventStream(body, { maxFrameChars = Infinity, requireBoundary = false } = {}) {
const decoder = new TextDecoder("utf-8", { fatal: requireBoundary });
let buffer = "";
for await (const chunk of body) {
buffer += decoder.decode(chunk, { stream: true });
let boundary;
while ((boundary = eventStreamBoundary(buffer)) !== null) {
if (boundary.index > maxFrameChars) throw new Error("Runtime event frame exceeds the size limit");
const frame = buffer.slice(0, boundary.index);
buffer = buffer.slice(boundary.index + boundary.length);
const event = parseSseFrame(frame);
if (event !== undefined) {
yield event;
}
}
if (buffer.length > maxFrameChars) throw new Error("Runtime event frame exceeds the size limit");
}
buffer += decoder.decode();
if (requireBoundary && buffer.trim()) throw new Error("Runtime event stream ended inside a frame");
const event = parseSseFrame(buffer);
if (event !== undefined) {
yield event;
}
}
function eventStreamBoundary(buffer) {View on GitHub (pinned to 433685b202)