JuliusBrussee/caveman · error

oversized_response

Error message

oversized_response

What it means

readRuntimePolicyResponseText enforces a 1 MiB cap on runtime policy responses. If the Content-Length header is present, numeric, and exceeds RUNTIME_POLICY_MAX_RESPONSE_BYTES (1024*1024), the body is cancelled and this error is thrown before any bytes are read.

Solutions

  1. Verify the runtimePolicy URL points to the intended small policy endpoint, not a bundle or dump
  2. Check server-side that the policy document is under 1 MiB and trim it
  3. Serve the policy with compression so the wire Content-Length stays under the cap
  4. Inspect any proxy/gateway that may inflate the response size

Example fix

// before
const policyUrl = "https://example.com/policies/all.json"; // 4 MB bundle
// after
const policyUrl = "https://example.com/policy/active.json"; // small active policy
Defensive patterns

Strategy: validation

Validate before calling

const head = await fetch(policyUrl, { method: "HEAD" });
const len = Number(head.headers.get("content-length") ?? "0");
if (len > 1024 * 1024) throw new Error(`policy response too large: ${len} bytes`);

Type guard

function hasBoundedBody(res: Response): boolean {
  const len = res.headers?.get?.("content-length");
  return !(typeof len === "string" && /^\d+$/.test(len) && Number(len) > 1024 * 1024);
}

Try / catch

try {
  const text = await readRuntimePolicyResponseText(response);
} catch (e) {
  if (e.message === "oversized_response") fallbackToCachedPolicy();
  else throw e;
}

Prevention

When it happens

Trigger: Calling the runtime policy fetch path when the policy endpoint returns a Content-Length header greater than 1,048,576 bytes.

Common situations: Pointing runtimePolicy at a bulk/policy-bundle URL instead of the intended small policy JSON; a proxy appending large payloads; misconfigured endpoint serving an entire dataset.

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


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/c6049491838b9047. Report an issue: GitHub.

Appendix: source

Thrown at packages/sdk/typescript/src/index.ts:879

      }
      return response;
    }
  };
}

// ─── Runtime policy client ────────────────────────────────────────────────────

/** Schema version this client accepts; anything else is rejected (fail closed). */
const RUNTIME_POLICY_SCHEMA_VERSION = "caveman.runtime-policy.v1";

/** Runtime-policy envelopes are KB-sized; stop a hostile body after 1 MiB. */
const RUNTIME_POLICY_MAX_RESPONSE_BYTES = 1024 * 1024;

async function readRuntimePolicyResponseText(response: Response): Promise<string> {
  const contentLength = response.headers?.get?.("content-length");
  if (typeof contentLength === "string" && /^[0-9]+$/.test(contentLength) && Number(contentLength) > RUNTIME_POLICY_MAX_RESPONSE_BYTES) {
    await Promise.resolve(response.body?.cancel?.()).catch(() => undefined);
    throw new Error("oversized_response");
  }

  const reader = response.body?.getReader?.();
  if (!reader) throw new Error("bounded_response_unavailable");
  const chunks: Uint8Array[] = [];
  let total = 0;
  try {
    while (true) {
      const { done, value } = await reader.read();
      if (done) break;
      if (!(value instanceof Uint8Array)) throw new Error("runtime policy response stream returned invalid bytes");
      total += value.byteLength;
      if (total > RUNTIME_POLICY_MAX_RESPONSE_BYTES) {
        await Promise.resolve(reader.cancel()).catch(() => undefined);
        throw new Error("oversized_response");
      }
      chunks.push(value);
    }

View on GitHub (pinned to 3ee70a1026)