can1357/oh-my-pi · error
response exceeds ${maxBytes} bytes
Error message
response exceeds ${maxBytes} bytes What it means
readResponseWithLimit enforces a hard cap on how many bytes it will buffer from a response body. As soon as accumulated bytes exceed maxBytes it cancels the stream and throws 'response exceeds N bytes' rather than consuming unbounded memory. It's a deliberate safety guard against oversized downloads.
Source
Thrown at packages/coding-agent/src/web/scrapers/utils.ts:51
if (!reader) return new Uint8Array(0);
const chunks: Buffer[] = [];
let totalBytes = 0;
try {
while (true) {
if (signal?.aborted) {
await reader.cancel();
throw new ToolAbortError();
}
const { done, value } = await reader.read();
if (done) break;
if (!value || value.byteLength === 0) continue;
totalBytes += value.byteLength;
if (totalBytes > maxBytes) {
await reader.cancel();
throw new Error(`response exceeds ${maxBytes} bytes`);
}
chunks.push(Buffer.from(value));
}
} finally {
reader.releaseLock();
}
return new Uint8Array(Buffer.concat(chunks, totalBytes));
}
/**
* Fetch binary content from a URL
*/
export async function fetchBinary(url: string, timeout: number = 20, signal?: AbortSignal): Promise<BinaryFetchResult> {
const requestSignal = ptree.combineSignals(signal, timeout * 1000);
try {
const response = await fetch(url, {View on GitHub (pinned to 9690622007)
Solutions
- Raise the maxBytes/MAX_BYTES limit if the content size is legitimate for your use case.
- Pre-check Content-Length in the response headers and reject/short-circuit before reading.
- Use a Range request to fetch only the first N bytes when you only need a preview.
- Catch the error and surface a truncated/oversized result to the caller instead of failing the whole task.
Example fix
// before
const buf = await readResponseWithLimit(response, 1024 * 1024);
// after
const size = Number(response.headers.get("content-length") ?? 0);
if (size > 10 * 1024 * 1024) return { ok: false, error: "too large" };
const buf = await readResponseWithLimit(response, 10 * 1024 * 1024); Defensive patterns
Strategy: validation
Validate before calling
const len = Number(response.headers.get("content-length") ?? NaN);
if (Number.isFinite(len) && len > MAX_BYTES) {
return { ok: false, error: `content-length ${len} exceeds ${MAX_BYTES}` };
} Type guard
null
Try / catch
try { return await readResponseWithLimit(res, MAX_BYTES, signal); }
catch (e) {
if (e instanceof Error && /response exceeds \d+ bytes/.test(e.message)) {
return { ok: false, error: "response too large", truncated: true };
}
throw e;
} Prevention
- Pre-check Content-Length before reading the body.
- Size MAX_BYTES to the largest payload your feature legitimately consumes.
- For previews, use Range headers instead of raising the cap.
- Report truncation/oversize to the caller rather than failing silently.
When it happens
Trigger: Fetching a resource (web page, PDF, image) whose body is larger than the maxBytes passed to readResponseWithLimit (e.g. MAX_BYTES in fetchBinary).
Common situations: Scraping a huge HTML page or downloading a large PDF that exceeds the scraper's byte cap; endpoints that ignore Range/limits and return full bodies.
Related errors
- Request was aborted
- No response body for V2 compaction streaming
- V2 compaction stream closed before response.completed
- V2 compaction stream parse failed: ${err instanceof Error ?
- formatCompactionV2Failure(event, type)
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/04e876d015d3d88a.
Report an issue: GitHub.