different-ai/openwork · warning · SafeProbeFailure

response_too_large

response_too_large

Error message

response_too_large

What it means

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.

Source

Thrown at apps/server/src/agent-context-cloud-probe.ts:446

async function cancelBody(response: Response, deadline?: ProbeDeadline): Promise<void> {
  try {
    const cancellation = response.body?.cancel();
    if (cancellation) await (deadline ? deadline.race(cancellation) : cancellation);
  } catch {
    // Cancellation is best effort and its error is never reported.
  }
}

async function readBoundedBody(
  response: Response,
  deadline: ProbeDeadline,
  budget: ProbeResponseBudget,
): Promise<string> {
  const declared = Number(response.headers.get("content-length"));
  if (Number.isFinite(declared) && declared > budget.remaining) {
    await cancelBody(response, deadline);
    throw new SafeProbeFailure("response_too_large");
  }
  const reader = response.body?.getReader();
  if (!reader) return "";
  const chunks: Uint8Array[] = [];
  let size = 0;
  try {
    while (true) {
      const next = await deadline.race(reader.read());
      if (next.done) break;
      size += next.value.byteLength;
      if (next.value.byteLength > budget.remaining) {
        await deadline.race(reader.cancel());
        throw new SafeProbeFailure("response_too_large");
      }
      budget.remaining -= next.value.byteLength;
      chunks.push(next.value);
    }
  } catch (error) {

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Point the probe at the correct (small) health/context endpoint.
  2. Raise the probe's response budget if larger responses are legitimately expected.
  3. Server-side: cap the endpoint's response size.

Example fix

// before
if (Number.isFinite(declared) && declared > budget.remaining) {
  await cancelBody(response, deadline);
  throw new SafeProbeFailure("response_too_large");
}
// after — log declared size for diagnosis
if (Number.isFinite(declared) && declared > budget.remaining) {
  recordInspectorEvent("probe.response_too_large", { declared });
  throw new SafeProbeFailure("response_too_large");
}
Defensive patterns

Strategy: fallback

Validate before calling

const len = Number(response.headers.get("content-length"));
if (Number.isFinite(len) && len > MAX_BYTES) {
  console.warn("Skipping probe: response too large", len);
  return null;
}

Type guard

function hasAcceptableLength(response: Response, max: number): boolean {
  const declared = Number(response.headers.get("content-length"));
  return !(Number.isFinite(declared) && declared > max);
}

Try / catch

try {
  const body = await readBoundedBody(response, deadline, budget);
} catch (error) {
  if (error instanceof SafeProbeFailure && error.code === "response_too_large") {
    return null; // probe result: too large, non-fatal
  }
  throw error;
}

Prevention

When it happens

Trigger: Probing a cloud agent-context endpoint whose response declares a content-length larger than the remaining response budget (ProbeResponseBudget.remaining).

Common situations: 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.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/fdb1eaee6faccc1c. Report an issue: GitHub.