nexu-io/open-design · warning · BudgetExceededError
file ${relPath} (${size} bytes) exceeds remaining budget
Error message
file ${relPath} (${size} bytes) exceeds remaining budget What it means
Thrown as a BudgetExceededError by the raw-file fetcher: the server's Content-Length header already exceeds the caller's remaining byte budget, so the body is never read. This optimization prevents a large allocation when the advertised size alone would overflow the MCP context bundle budget.
Source
Thrown at apps/daemon/src/mcp.ts:3270
.split('/')
.filter((s) => s.length > 0)
.map(encodeURIComponent);
const url = `${baseUrl}/api/projects/${encodeURIComponent(projectId)}/raw/${segments.join('/')}`;
const resp = await fetch(url, headers ? { headers } : undefined);
if (!resp.ok) {
const body = await safeText(resp);
throw new Error(`daemon ${resp.status} on ${url}: ${body || resp.statusText}`);
}
const mime = ((resp.headers.get('content-type') || 'application/octet-stream').split(';')[0] ?? 'application/octet-stream').trim();
const headerSize = Number(resp.headers.get('content-length'));
const size = Number.isFinite(headerSize) && headerSize >= 0 ? headerSize : null;
if (!isTextualMime(mime)) {
return { name: relPath, mime, size, content: null, binary: true };
}
// If the server advertises a size that already exceeds our remaining
// budget, skip reading the body to avoid a large allocation.
if (size !== null && size > remainingBytes) {
throw new BudgetExceededError(`file ${relPath} (${size} bytes) exceeds remaining budget`);
}
const content = await resp.text();
const contentBytes = Buffer.byteLength(content, 'utf8');
if (contentBytes > remainingBytes) {
throw new BudgetExceededError(
`file ${relPath} (${contentBytes} bytes) exceeds remaining budget`,
);
}
return { name: relPath, mime, size: size ?? contentBytes, content, binary: false };
}
// Patterns common to HTML and CSS (also fine to run on plain markdown).
const HTML_REF_PATTERNS = [
/<script\b[^>]*\bsrc=["']([^"']+)["']/gi,
/<link\b[^>]*\bhref=["']([^"']+)["']/gi,
/<img\b[^>]*\bsrc=["']([^"']+)["']/gi,
/<source\b[^>]*\bsrc=["']([^"']+)["']/gi,
/<video\b[^>]*\bsrc=["']([^"']+)["']/gi,View on GitHub (pinned to 5be4028344)
Solutions
- Skip or truncate large files before fetching (filter by size/name in your listing step).
- Increase the maxBytes/remainingBytes budget passed to the fetcher if the caller controls it.
- Read the file in offset/limit chunks using the ranged file API instead of whole-file fetch.
- Exclude known large paths (dist/, node_modules/, lockfiles, minified bundles) from the bundle.
Example fix
// before const bundle = await getFile(baseUrl, project, "dist/build.js", active, resolved, 0, 2000, remainingBytes); // after: skip oversized generated files if (entry.size > remainingBytes) continue;
Defensive patterns
Strategy: validation
Validate before calling
if (typeof size === 'number' && size > remainingBytes) {
throw new BudgetExceededError(`${relPath} too large; skip or raise budget`);
} Try / catch
try {
return await fetchRawFile(baseUrl, projectId, relPath, remainingBytes, headers);
} catch (e) {
if (e instanceof BudgetExceededError) return null; // skip oversized file
throw e;
} Prevention
- Pre-filter listing entries by size against the remaining budget.
- Read large files in offset/limit pages.
- Exclude dist/, lockfiles, and minified bundles from bundles.
When it happens
Trigger: Bundling project files into an MCP response with a tight maxBytes; fetching a very large source/log/data file when remainingBytes is nearly exhausted; a binary file mislabeled with a textual MIME and a huge Content-Length.
Common situations: Agent reads many files in sequence and the cumulative budget runs out; a generated/lockfile/minified file is huge; budget set too low for the repo's largest files.
Related errors
- file ${relPath} (${contentBytes} bytes) exceeds remaining bu
- codex mcp add failed: ${failureDetail(result)}
- codex mcp remove failed: ${failureDetail(result)}
- existing config at ${where} is not valid JSON: ${err instanc
- existing config at ${where} is not a JSON object
AI-assisted analysis of nexu-io/open-design@5be4028344 (2026-08-12).
Data as JSON: /api/errors/6bf93a9af9171e3f.
Report an issue: GitHub.