{"record":{"id":"7cc9df31d12512b3","repo":"affaan-m/ECC","slug":"memory-body-is-too-large-maximum-maxbytes-byte","errorCode":null,"errorMessage":"memory body is too large (maximum ${maxBytes} bytes).","messagePattern":"memory body is too large \\(maximum (.+?) bytes\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"scripts/memory.js","lineNumber":188,"sourceCode":"      bytesRead = fs.readSync(0, buffer, 0, buffer.length, null);\n    } catch (error) {\n      const retryable = ['EAGAIN', 'EWOULDBLOCK', 'EINTR'].includes(error?.code);\n      if (!retryable) throw error;\n      if (remainingRetryWaitMs < retryDelayMs) {\n        throw new Error(\n          `Standard input remained unavailable after ${maxRetryWaitMs}ms.`\n        );\n      }\n      wait(retryDelayMs);\n      remainingRetryWaitMs -= retryDelayMs;\n      continue;\n    }\n    if (bytesRead === 0) break;\n    chunks.push(buffer.subarray(0, bytesRead));\n    total += bytesRead;\n  }\n  if (total > maxBytes) {\n    throw new Error(`memory body is too large (maximum ${maxBytes} bytes).`);\n  }\n  return decodeUtf8(Buffer.concat(chunks, total), 'memory body from standard input');\n}\n\nfunction readBody(options) {\n  const sources = [Boolean(options.stdin), Boolean(options.bodyFile)]\n    .filter(Boolean).length;\n  if (sources !== 1) {\n    throw new Error('Choose exactly one memory body source: --stdin or --body-file.');\n  }\n  if (options.stdin) {\n    return readBoundedStdin(MAX_BODY_BYTES);\n  }\n\n  const bodyPath = path.resolve(options.bodyFile);\n  return readRegularTextFile(bodyPath, {\n    label: '--body-file',\n    maxBytes: MAX_BODY_BYTES,","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/memory.js#L170-L206","documentation":"After successfully reading stdin (or a body file), readBoundedStdin/readBody check that total bytes did not exceed MAX_BODY_BYTES (64 * 1024 = 65536 bytes, from memory-vault-format.js). If the body is larger, it throws. The cap exists to keep memory documents small, scannable, and safe against memory-exhaustion via oversized memories; it is also enforced upstream on document size (MAX_DOCUMENT_BYTES = 128 KiB).","triggerScenarios":"Piping or pointing --body-file at a large file: a multi-megabyte log, a full markdown book chapter, a pasted transcript. Feeding a binary/concatenated blob. A redirected file that is bigger than expected.","commonSituations":"Treating the memory vault as a document store rather than a note store. Forgetting the 64 KiB body cap. A generated report larger than the limit.","solutions":["Trim the body to the essentials (under 64 KiB) before saving.","Store the large artifact elsewhere and save a memory that links to it (use --link <memory-id> and a short summary body).","Check size first: `wc -c body.md` and ensure it is < 65536.","Split a long body into multiple smaller memories tagged consistently."],"exampleFix":"# before\nhuge_report > body.md  # e.g. 200 KiB\necc memory save --title \"report\" --body-file body.md   # throws\n\n# after — summarize and link the full report\necc memory save --title \"report summary\" --body-file summary.md   # < 64 KiB\n# keep the full report in your docs tree; reference it from the summary body","handlingStrategy":"validation","validationCode":"// Validate body size against the 64 KiB cap before reading.\nconst fs = require('fs');\nconst MAX_BODY_BYTES = 64 * 1024;\nfunction assertBodyWithinLimit(filePath) {\n  const st = fs.statSync(filePath);\n  if (st.size > MAX_BODY_BYTES) {\n    throw new Error(`memory body is too large (maximum ${MAX_BODY_BYTES} bytes); file is ${st.size}.`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try { body = readBody(options); }\ncatch (err) {\n  if (/memory body is too large/.test(err.message)) {\n    console.error(`${err.message} Trim the body or store the artifact elsewhere and link it.`);\n    process.exit(2);\n  } else throw err;\n}","preventionTips":["Check `wc -c <file>` before saving; keep bodies under 64 KiB.","Store large artifacts in docs and save a short summary memory that links to them.","Split very long content into several tagged memories."],"tags":["memory-vault","size-limit","io","validation"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}