{"record":{"id":"bd5663712216302d","repo":"affaan-m/ECC","slug":"label-is-too-large-maximum-maxbytes-bytes","errorCode":null,"errorMessage":"${label} is too large (maximum ${maxBytes} bytes).","messagePattern":"(.+?) is too large \\(maximum (.+?) bytes\\)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/memory-vault.js","lineNumber":183,"sourceCode":"    }\n    if (options.trustedRoot) {\n      assertWithinTrustedRoot(filePath, options.trustedRoot, `read ${label}`);\n    }\n    if (opened.size > BigInt(maxBytes)) {\n      throw new Error(`${label} is too large (${opened.size} bytes).`);\n    }\n\n    const chunks = [];\n    let total = 0;\n    while (total <= maxBytes) {\n      const buffer = Buffer.alloc(Math.min(64 * 1024, maxBytes + 1 - total));\n      const bytesRead = fs.readSync(descriptor, buffer, 0, buffer.length, null);\n      if (bytesRead === 0) break;\n      chunks.push(buffer.subarray(0, bytesRead));\n      total += bytesRead;\n    }\n    if (total > maxBytes) {\n      throw new Error(`${label} is too large (maximum ${maxBytes} bytes).`);\n    }\n    return decodeUtf8(Buffer.concat(chunks, total), label);\n  } finally {\n    fs.closeSync(descriptor);\n  }\n}\n\nfunction writeCreateOnlyTextFile(filePath, content, trustedRoot) {\n  assertWithinTrustedRoot(filePath, trustedRoot, 'write memory');\n  const temporaryPath = path.join(\n    path.dirname(filePath),\n    `.ecc-memory-${process.pid}-${crypto.randomUUID()}.tmp`\n  );\n  const flags = fs.constants.O_WRONLY\n    | fs.constants.O_CREAT\n    | fs.constants.O_EXCL\n    | (fs.constants.O_NOFOLLOW || 0);\n  let descriptor;","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/memory-vault.js#L165-L201","documentation":"readRegularTextFile reads a file within the memory vault in bounded chunks and enforces a hard size cap (maxBytes). When the accumulated byte count exceeds maxBytes it throws this error instead of loading an oversized file into memory. This protects the vault from unbounded reads of corrupted or user-swapped files.","triggerScenarios":"Calling any vault API that reads a text document (e.g. saveMemory's .gitignore check, or document loading paths via readBody/existing) when the target file's size exceeds maxBytes (MAX_DOCUMENT_BYTES for project memory documents).","commonSituations":"A .gitignore or memory .md file was replaced with a much larger file outside the library; a user pasted a huge document into the vault manually; syncing tools (Dropbox, git LFS checkout issues) expanded files unexpectedly.","solutions":["Reduce the file's size below maxBytes (trim or split the document).","Remove or replace the oversized file (e.g. the project memory .gitignore) and let the library recreate it.","If legitimately needed, re-invoke with a higher maxBytes option where the API exposes it."],"exampleFix":"// before\nconst content = readRegularTextFile(bigDoc, { label: 'doc', maxBytes: 1024 });\n// after\nconst content = readRegularTextFile(bigDoc, { label: 'doc', maxBytes: 64 * 1024 }); // raise cap or trim file first","handlingStrategy":"validation","validationCode":"const stat = fs.statSync(filePath);\nif (stat.size > maxBytes) throw new Error(`Refusing to read ${filePath}: ${stat.size} bytes exceeds ${maxBytes}.`);","typeGuard":"const isWithinSizeLimit = (filePath, maxBytes) => { try { return fs.statSync(filePath).size <= maxBytes; } catch { return false; } };","tryCatchPattern":"try {\n  const content = readRegularTextFile(filePath, { label, maxBytes, trustedRoot });\n} catch (err) {\n  if (err.message.includes('is too large')) {\n    // handle oversize: truncate, split, or raise the cap deliberately\n  } else throw err;\n}","preventionTips":["Stat files before reading them into the vault.","Keep vault documents small and split large notes into multiple memories.","Monitor vault directory sizes in sync/backup tooling.","Set maxBytes explicitly rather than relying on defaults when you expect larger documents."],"tags":["file-size","io","memory-vault"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}