{"record":{"id":"8b91521bca7173b5","repo":"different-ai/openwork","slug":"agent-context-diagnostics-response-too-large","errorCode":"agent_context_diagnostics_response_too_large","errorMessage":"Agent context diagnostics response exceeded the 1 MiB limit.","messagePattern":"Agent context diagnostics response exceeded the 1 MiB limit\\.","errorType":"exception","errorClass":"AgentContextDiagnosticsTransportError","httpStatus":null,"severity":"error","filePath":"apps/app/src/app/lib/agent-context-diagnostics-transport.ts","lineNumber":60,"sourceCode":"\nfunction cancelUnlockedBody(response: Response): void {\n  if (!response.body || response.body.locked) return;\n  void response.body.cancel().catch(() => undefined);\n}\n\nasync function readBoundedResponseText(\n  response: Response,\n  signal: AbortSignal,\n): Promise<string> {\n  const declaredLength = response.headers.get(\"content-length\")?.trim() ?? \"\";\n  if (/^\\d+$/.test(declaredLength)) {\n    const declaredBytes = Number(declaredLength);\n    if (\n      !Number.isSafeInteger(declaredBytes)\n      || declaredBytes > AGENT_CONTEXT_DIAGNOSTICS_RESPONSE_MAX_BYTES\n    ) {\n      cancelUnlockedBody(response);\n      throw responseTooLargeError();\n    }\n  }\n\n  if (!response.body) return \"\";\n\n  const reader = response.body.getReader();\n  const chunks: Uint8Array[] = [];\n  let bytesRead = 0;\n  const cancelOnAbort = () => {\n    void reader.cancel().catch(() => undefined);\n  };\n  signal.addEventListener(\"abort\", cancelOnAbort, { once: true });\n\n  try {\n    while (true) {\n      if (signal.aborted) throw timeoutError();\n      const chunk = await reader.read();\n      if (chunk.done) break;","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/app/lib/agent-context-diagnostics-transport.ts#L42-L78","documentation":"readBoundedResponseText first inspects the declared Content-Length header. If it is a valid integer exceeding AGENT_CONTEXT_DIAGNOSTICS_RESPONSE_MAX_BYTES (1 MiB), it cancels the body and throws responseTooLargeError() without reading anything. This pre-read guard avoids downloading a body known in advance to be too big.","triggerScenarios":"The diagnostics endpoint responds with a Content-Length header whose numeric value is greater than 1048576 bytes — e.g. a server that isn't the bounded diagnostics endpoint or that failed to truncate its payload.","commonSituations":"Pointing the diagnostics client at a wrong/debug endpoint that returns huge payloads; a server bug that serializes the full agent context unbounded; a proxy injecting large HTML error pages with explicit Content-Length.","solutions":["Fix the diagnostics endpoint to cap/truncate its JSON payload to under 1 MiB","Verify the client URL points at the real agent-context diagnostics endpoint, not another route","Check for proxies/middleware that inflate the response (error pages, injected content)","If the payload is legitimately larger, the endpoint must paginate or summarize rather than grow the response"],"exampleFix":"// before: endpoint serializes full context\nreturn Response.json(fullContext);\n// after: cap the payload server-side\nreturn Response.json(truncateContext(fullContext, 1_000_000));","handlingStrategy":"try-catch","validationCode":"const contentLength = Number(response.headers.get(\"content-length\") ?? \"\");\nif (Number.isSafeInteger(contentLength) && contentLength > 1024 * 1024) {\n  throw new Error(\"Diagnostics response would exceed the 1 MiB limit\");\n}","typeGuard":"null","tryCatchPattern":"try {\n  const { payload } = await requestAgentContextDiagnosticsPayload({ fetchImpl, url, init });\n} catch (e) {\n  if (e instanceof AgentContextDiagnosticsTransportError && e.code === \"agent_context_diagnostics_response_too_large\") {\n    // endpoint returned >1MiB; request a truncated/paginated payload\n  } else throw e;\n}","preventionTips":["Cap the diagnostics payload server-side below 1 MiB","Confirm you are calling the real diagnostics endpoint, not a debug route","Check status/content-type so error pages aren't mistaken for diagnostics JSON","Paginate or summarize large context data instead of one big response"],"tags":["http","limit","response-size"],"backgroundTag":"response-size-limit-exceeded","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}