{"record":{"id":"9759a50640849a6b","repo":"Hmbown/CodeWhale","slug":"runtime-event-frame-exceeds-the-size-limit","errorCode":null,"errorMessage":"Runtime event frame exceeds the size limit","messagePattern":"Runtime event frame exceeds the size limit","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"npm/runtime-sdk/index.js","lineNumber":244,"sourceCode":"}\n\nasync function readErrorBody(response) {\n  try {\n    const text = await response.text();\n    return text.length > 4096 ? `${text.slice(0, 4096)}...` : text;\n  } catch {\n    return \"\";\n  }\n}\n\nasync function* parseEventStream(body, { maxFrameChars = Infinity, requireBoundary = false } = {}) {\n  const decoder = new TextDecoder(\"utf-8\", { fatal: requireBoundary });\n  let buffer = \"\";\n  for await (const chunk of body) {\n    buffer += decoder.decode(chunk, { stream: true });\n    let boundary;\n    while ((boundary = eventStreamBoundary(buffer)) !== null) {\n      if (boundary.index > maxFrameChars) throw new Error(\"Runtime event frame exceeds the size limit\");\n      const frame = buffer.slice(0, boundary.index);\n      buffer = buffer.slice(boundary.index + boundary.length);\n      const event = parseSseFrame(frame);\n      if (event !== undefined) {\n        yield event;\n      }\n    }\n    if (buffer.length > maxFrameChars) throw new Error(\"Runtime event frame exceeds the size limit\");\n  }\n  buffer += decoder.decode();\n  if (requireBoundary && buffer.trim()) throw new Error(\"Runtime event stream ended inside a frame\");\n  const event = parseSseFrame(buffer);\n  if (event !== undefined) {\n    yield event;\n  }\n}\n\nfunction eventStreamBoundary(buffer) {","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/npm/runtime-sdk/index.js#L226-L262","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nfor await (const ev of client.threadEvents(id)) handle(ev);\n// after\ntry {\n  for await (const ev of client.threadEvents(id)) handle(ev);\n} catch (err) {\n  if (err.message.includes(\"exceeds the size limit\")) return handleOversizedThread(id);\n  throw err;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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."],"tags":["sse","size-limit","streaming","memory-guard"],"backgroundTag":"payload-too-large","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}