{"record":{"id":"e9acc624a02f25ba","repo":"affaan-m/ECC","slug":"memory-body-is-too-large-maximum-max-body-bytes","errorCode":null,"errorMessage":"memory body is too large (maximum ${MAX_BODY_BYTES} bytes).","messagePattern":"memory body is too large \\(maximum (.+?) bytes\\)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/memory-vault-format.js","lineNumber":156,"sourceCode":"  ) {\n    throw new Error(`${label} must be an ISO-8601 timestamp.`);\n  }\n  return normalized;\n}\n\nfunction normalizeBody(value) {\n  if (typeof value !== 'string') {\n    throw new Error('memory body must be a string.');\n  }\n  if (hasUnsafeControlCharacters(value, true)) {\n    throw new Error('memory body must not contain unsafe control or bidirectional formatting characters.');\n  }\n  const normalized = value.trim();\n  if (normalized.length === 0) {\n    throw new Error('memory body must contain non-whitespace context.');\n  }\n  if (Buffer.byteLength(normalized, 'utf8') > MAX_BODY_BYTES) {\n    throw new Error(`memory body is too large (maximum ${MAX_BODY_BYTES} bytes).`);\n  }\n  return normalized;\n}\n\nfunction normalizeMemory(memory) {\n  if (!memory || typeof memory !== 'object' || Array.isArray(memory)) {\n    throw new Error('memory must be an object.');\n  }\n\n  const targetHarnesses = uniqueStrings(memory.targetHarnesses, {\n    label: 'target harnesses',\n    limit: MAX_TARGETS,\n    validator: value => validateSlug(value, 'target harness'),\n  });\n  if (targetHarnesses.length === 0) {\n    throw new Error('target harnesses must contain at least one harness or \"all\".');\n  }\n","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/memory-vault-format.js#L138-L174","documentation":"Thrown by normalizeBody() when Buffer.byteLength(normalized, 'utf8') exceeds MAX_BODY_BYTES (65536 bytes = 64 KiB). Bodies are bounded so the vault scan loop (MAX_SCAN_BYTES = 16 MiB across all files) cannot be exhausted by a single entry and recall excerpts stay readable. The limit is measured in UTF-8 bytes, not character count, so multi-byte content hits it sooner.","triggerScenarios":"saveMemory({body: hugeString}) where hugeString is a log dump, a full file content, a stack trace, or an embedded base64 blob larger than 64 KiB. Pasting the contents of a large file. Auto-saving a transcript of a long session.","commonSituations":"Agent loop that saves its entire context window each turn. Error reporter that attaches the full stack and surrounding log. Backup routine that stores serialized state in body. UTF-16/emoji-heavy text where the byte count is 2–4x the character count.","solutions":["Truncate before saving: body = body.slice(0, 60000) to leave headroom for multi-byte tails.","Split into multiple memories linked via the links field, each under the cap.","Store large payloads out-of-band (a file, an object store) and put the reference in body.","Add a pre-check: if (Buffer.byteLength(body, 'utf8') > 65536) throw new Error('too big')."],"exampleFix":"// before\nsaveMemory({ title: 'log dump', body: entireLogFile }); // 2 MB\n\n// after\nconst MAX_BODY_BYTES = 64 * 1024;\nlet body = entireLogFile;\nif (Buffer.byteLength(body, 'utf8') > MAX_BODY_BYTES) {\n  body = body.slice(0, 60000) + '\\n…[truncated]';\n}\nsaveMemory({ title: 'log dump', body });","handlingStrategy":"validation","validationCode":"const { MAX_BODY_BYTES } = require('./scripts/lib/memory-vault-format');\nif (Buffer.byteLength(input.body, 'utf8') > MAX_BODY_BYTES) {\n  throw new Error(`body exceeds ${MAX_BODY_BYTES} bytes; split or truncate.`);\n}\nsaveMemory(input);","typeGuard":"function isWithinBodyLimit(value): value is string {\n  return typeof value === 'string'\n    && Buffer.byteLength(value, 'utf8') <= 64 * 1024;\n}","tryCatchPattern":null,"preventionTips":["Bound your textareas and inputs at the UI layer to ~60 KiB of UTF-8.","For long payloads, store externally and put a reference in body.","Remember the cap is bytes not chars: emoji-heavy or CJK text counts 2–4x."],"tags":["validation","limits","memory-vault","size-limit"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}