{"record":{"id":"fdb1eaee6faccc1c","repo":"different-ai/openwork","slug":"response-too-large","errorCode":"response_too_large","errorMessage":"response_too_large","messagePattern":"response_too_large","errorType":"error_code","errorClass":"SafeProbeFailure","httpStatus":null,"severity":"warning","filePath":"apps/server/src/agent-context-cloud-probe.ts","lineNumber":446,"sourceCode":"\nasync function cancelBody(response: Response, deadline?: ProbeDeadline): Promise<void> {\n  try {\n    const cancellation = response.body?.cancel();\n    if (cancellation) await (deadline ? deadline.race(cancellation) : cancellation);\n  } catch {\n    // Cancellation is best effort and its error is never reported.\n  }\n}\n\nasync function readBoundedBody(\n  response: Response,\n  deadline: ProbeDeadline,\n  budget: ProbeResponseBudget,\n): Promise<string> {\n  const declared = Number(response.headers.get(\"content-length\"));\n  if (Number.isFinite(declared) && declared > budget.remaining) {\n    await cancelBody(response, deadline);\n    throw new SafeProbeFailure(\"response_too_large\");\n  }\n  const reader = response.body?.getReader();\n  if (!reader) return \"\";\n  const chunks: Uint8Array[] = [];\n  let size = 0;\n  try {\n    while (true) {\n      const next = await deadline.race(reader.read());\n      if (next.done) break;\n      size += next.value.byteLength;\n      if (next.value.byteLength > budget.remaining) {\n        await deadline.race(reader.cancel());\n        throw new SafeProbeFailure(\"response_too_large\");\n      }\n      budget.remaining -= next.value.byteLength;\n      chunks.push(next.value);\n    }\n  } catch (error) {","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/server/src/agent-context-cloud-probe.ts#L428-L464","documentation":"readBoundedBody in the cloud probe enforces a response-size budget. Before reading the stream, it checks the declared content-length header; if it exceeds budget.remaining, the body is cancelled and a SafeProbeFailure('response_too_large') is thrown. SafeProbeFailure is a controlled probe failure, not a crash — the probe reports it safely.","triggerScenarios":"Probing a cloud agent-context endpoint whose response declares a content-length larger than the remaining response budget (ProbeResponseBudget.remaining).","commonSituations":"Endpoint returns a very large JSON/HTML document (e.g., an error page with huge payload or an unexpectedly verbose API response); misconfigured probe URL pointing at a bulk/download endpoint.","solutions":["Point the probe at the correct (small) health/context endpoint.","Raise the probe's response budget if larger responses are legitimately expected.","Server-side: cap the endpoint's response size."],"exampleFix":"// before\nif (Number.isFinite(declared) && declared > budget.remaining) {\n  await cancelBody(response, deadline);\n  throw new SafeProbeFailure(\"response_too_large\");\n}\n// after — log declared size for diagnosis\nif (Number.isFinite(declared) && declared > budget.remaining) {\n  recordInspectorEvent(\"probe.response_too_large\", { declared });\n  throw new SafeProbeFailure(\"response_too_large\");\n}","handlingStrategy":"fallback","validationCode":"const len = Number(response.headers.get(\"content-length\"));\nif (Number.isFinite(len) && len > MAX_BYTES) {\n  console.warn(\"Skipping probe: response too large\", len);\n  return null;\n}","typeGuard":"function hasAcceptableLength(response: Response, max: number): boolean {\n  const declared = Number(response.headers.get(\"content-length\"));\n  return !(Number.isFinite(declared) && declared > max);\n}","tryCatchPattern":"try {\n  const body = await readBoundedBody(response, deadline, budget);\n} catch (error) {\n  if (error instanceof SafeProbeFailure && error.code === \"response_too_large\") {\n    return null; // probe result: too large, non-fatal\n  }\n  throw error;\n}","preventionTips":["Probe small, bounded health/context endpoints only.","Check content-length before reading when present.","Set explicit response budgets per probe target.","Treat size failures as probe findings, not app errors."],"tags":["http","limits","probe"],"backgroundTag":"response-body-too-large","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}