nexu-io/open-design · warning · BudgetExceededError

file ${relPath} (${contentBytes} bytes) exceeds remaining bu

Error message

file ${relPath} (${contentBytes} bytes) exceeds remaining budget

What it means

Thrown as a BudgetExceededError after reading the body: the actual UTF-8 byte length of the content exceeds the remaining budget, even though the Content-Length header did not (or was absent/zero). This is the second-line guard that catches misreported or chunked/gzip-decoded sizes.

Source

Thrown at apps/daemon/src/mcp.ts:3275

  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,
  /<audio\b[^>]*\bsrc=["']([^"']+)["']/gi,
  /<iframe\b[^>]*\bsrc=["']([^"']+)["']/gi,
];

const CSS_REF_PATTERNS = [

View on GitHub (pinned to 5be4028344)

Solutions

  1. Raise the remainingBytes budget for the fetch operation.
  2. Read the file in pages via offset/limit so each chunk fits the budget.
  3. Pre-filter large files out of the bundle using the directory listing's size metadata.
  4. If the header/body disagreement is a daemon bug, file an issue with the path and sizes.

Example fix

// before: whole-file read overflows residual budget
const file = await getFile(baseUrl, project, bigTextPath, active, resolved, 0, 2000, remainingBytes);
// after: paged read
const page = await getFile(baseUrl, project, bigTextPath, active, resolved, 0, 500, remainingBytes);
Defensive patterns

Strategy: try-catch

Validate before calling

const contentBytes = Buffer.byteLength(content, 'utf8');
if (contentBytes > remainingBytes) throw new BudgetExceededError('content exceeds budget');

Try / catch

try {
  return await fetchRawFile(baseUrl, projectId, relPath, remainingBytes, headers);
} catch (e) {
  if (e instanceof BudgetExceededError) return await pagedRead(baseUrl, projectId, relPath, remainingBytes);
  throw e;
}

Prevention

When it happens

Trigger: Server omitted or under-reported Content-Length (e.g. chunked transfer-encoding); the body decoded to more bytes than advertised; a text file slightly larger than the residual budget after the header check passed.

Common situations: Compressed/streamed responses where header size disagrees with decoded size; UTF-8 multibyte content inflating beyond a byte-counted budget; budgets set just under the file size.

Related errors


AI-assisted analysis of nexu-io/open-design@5be4028344 (2026-08-12). Data as JSON: /api/errors/8b1fc402f3e00d33. Report an issue: GitHub.