{"record":{"id":"c1b7604c0f206d90","repo":"JuliusBrussee/caveman","slug":"bounded-response-unavailable","errorCode":null,"errorMessage":"bounded_response_unavailable","messagePattern":"bounded_response_unavailable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/sdk/typescript/src/index.ts","lineNumber":883,"sourceCode":"}\n\n// ─── Runtime policy client ────────────────────────────────────────────────────\n\n/** Schema version this client accepts; anything else is rejected (fail closed). */\nconst RUNTIME_POLICY_SCHEMA_VERSION = \"caveman.runtime-policy.v1\";\n\n/** Runtime-policy envelopes are KB-sized; stop a hostile body after 1 MiB. */\nconst RUNTIME_POLICY_MAX_RESPONSE_BYTES = 1024 * 1024;\n\nasync function readRuntimePolicyResponseText(response: Response): Promise<string> {\n  const contentLength = response.headers?.get?.(\"content-length\");\n  if (typeof contentLength === \"string\" && /^[0-9]+$/.test(contentLength) && Number(contentLength) > RUNTIME_POLICY_MAX_RESPONSE_BYTES) {\n    await Promise.resolve(response.body?.cancel?.()).catch(() => undefined);\n    throw new Error(\"oversized_response\");\n  }\n\n  const reader = response.body?.getReader?.();\n  if (!reader) throw new Error(\"bounded_response_unavailable\");\n  const chunks: Uint8Array[] = [];\n  let total = 0;\n  try {\n    while (true) {\n      const { done, value } = await reader.read();\n      if (done) break;\n      if (!(value instanceof Uint8Array)) throw new Error(\"runtime policy response stream returned invalid bytes\");\n      total += value.byteLength;\n      if (total > RUNTIME_POLICY_MAX_RESPONSE_BYTES) {\n        await Promise.resolve(reader.cancel()).catch(() => undefined);\n        throw new Error(\"oversized_response\");\n      }\n      chunks.push(value);\n    }\n  } finally {\n    try {\n      reader.releaseLock();\n    } catch {","sourceCodeStart":865,"sourceCodeEnd":901,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/sdk/typescript/src/index.ts#L865-L901","documentation":"After the size check, readRuntimePolicyResponseText needs to stream the response body via response.body.getReader(). If the body stream or getReader is unavailable (null body), it throws this error because a bounded read is impossible.","triggerScenarios":"Fetch Response whose body is null or lacks getReader() — e.g. in runtimes without streaming response support, opaque no-cors responses, or mocked Response objects without a body.","commonSituations":"Running in an older runtime/polyfilled environment where fetch responses have no readable body; unit tests passing a fake Response with body: null; opaque cross-origin responses (type: 'opaque').","solutions":["Ensure the runtime supports streaming fetch response bodies (modern Node 18+/browsers)","Fix the request so the response is not opaque (avoid mode:'no-cors' for the policy endpoint)","In tests, provide a Response with a real ReadableStream body","Upgrade the fetch polyfill/undici to one supporting body streams"],"exampleFix":"// before\nconst res = await fetch(policyUrl, { mode: \"no-cors\" }); // opaque, body null\n// after\nconst res = await fetch(policyUrl, { mode: \"cors\" });","handlingStrategy":"validation","validationCode":"if (typeof Response !== \"undefined\") {\n  const probe = new Response(\"x\");\n  if (!probe.body || typeof probe.body.getReader !== \"function\") {\n    console.warn(\"runtime lacks streaming response bodies; runtime policy fetch will fail\");\n  }\n}","typeGuard":"function hasReadableBody(res: Response): res is Response & { body: ReadableStream<Uint8Array> } {\n  return !!res.body && typeof res.body.getReader === \"function\";\n}","tryCatchPattern":"try {\n  const text = await readRuntimePolicyResponseText(response);\n} catch (e) {\n  if (e.message === \"bounded_response_unavailable\") useNonStreamingFetchFallback();\n  else throw e;\n}","preventionTips":["Run on runtimes with streaming fetch support (Node 18+, modern browsers)","Avoid mode:'no-cors'/opaque responses for the policy endpoint","Use real ReadableStream bodies in test doubles"],"tags":["network","fetch","streaming","environment"],"backgroundTag":"unsupported-operation","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}