affaan-m/ECC · error · Error

${label} is too large (${opened.size} bytes).

Error message

${label} is too large (${opened.size} bytes).

What it means

readRegularTextFile enforces a hard size cap on any document it opens: after fstat, if opened.size exceeds maxBytes (default MAX_DOCUMENT_BYTES), it refuses to read at all. This bounds memory consumption and prevents a single oversized document from stalling a vault scan. The check uses the size at open time, before any bytes are streamed.

Source

Thrown at scripts/lib/memory-vault.js:170

  const descriptor = fs.openSync(filePath, flags);
  try {
    const opened = fs.fstatSync(descriptor, { bigint: true });
    if (!opened.isFile()) {
      throw new Error(`${label} must be a regular, non-symlink file.`);
    }
    const after = fs.lstatSync(filePath, { bigint: true });
    if (
      after.isSymbolicLink()
      || !after.isFile()
      || !sameFileIdentity(after, opened)
    ) {
      throw new Error(`${label} must remain a regular, non-symlink file while it is opened.`);
    }
    if (options.trustedRoot) {
      assertWithinTrustedRoot(filePath, options.trustedRoot, `read ${label}`);
    }
    if (opened.size > BigInt(maxBytes)) {
      throw new Error(`${label} is too large (${opened.size} bytes).`);
    }

    const chunks = [];
    let total = 0;
    while (total <= maxBytes) {
      const buffer = Buffer.alloc(Math.min(64 * 1024, maxBytes + 1 - total));
      const bytesRead = fs.readSync(descriptor, buffer, 0, buffer.length, null);
      if (bytesRead === 0) break;
      chunks.push(buffer.subarray(0, bytesRead));
      total += bytesRead;
    }
    if (total > maxBytes) {
      throw new Error(`${label} is too large (maximum ${maxBytes} bytes).`);
    }
    return decodeUtf8(Buffer.concat(chunks, total), label);
  } finally {
    fs.closeSync(descriptor);
  }

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Trim the offending document's body to under MAX_DOCUMENT_BYTES (split large content into multiple linked memories).
  2. Move oversized reference material out of the vault into an attachment and link to it, keeping only a summary in the memory body.
  3. Locate the offending file with the diagnostics from searchMemories/doctorMemoryVault (invalidFiles list) and rewrite it via saveMemory with a fresh id.
  4. If you genuinely need a higher cap for a trusted internal call, pass options.maxBytes explicitly — but the default is a deliberate ceiling, not a typo.

Example fix

// before: memory body contains a 5MB base64 blob, read fails
// split: save a summary memory and store the blob elsewhere
saveMemory({ title: 'crash log', body: log.slice(0, 4000), tags: ['summary'] });
fs.writeFileSync('/data/attachments/full.log', fullLog);
// after: body is well under the cap
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const { MAX_DOCUMENT_BYTES } = require('./scripts/lib/memory-vault');
function assertWithinSize(p, max = MAX_DOCUMENT_BYTES) {
  const size = fs.statSync(p).size;
  if (size > max) throw new Error(`${p} is too large (${size} bytes).`);
  return size;
}

Try / catch

try { readRegularTextFile(filePath, { trustedRoot: root, maxBytes: MAX_DOCUMENT_BYTES }); }
catch (error) {
  if (/is too large/.test(error.message)) {
    console.error('Document exceeds the vault size cap; split or trim it:', error.message);
    return;
  }
  throw error;
}

Prevention

When it happens

Trigger: A memory document (or the project .gitignore when read back by ensureProjectScopeIgnored) is larger than maxBytes. Triggered by readMemoryFiles scanning a vault containing an oversized .md file, or by an explicit readRegularTextFile call where options.maxBytes was lowered.

Common situations: Pasting a huge log, stack trace, or base64 blob into a memory body; a memory document that accumulated many edits over time; embedding a large image as data URI; lowering maxBytes for a specific call below the on-disk file size; a corrupted/merged document that concatenated duplicates.

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/9c3ec5697f7b9402. Report an issue: GitHub.