{"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/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/memory-vault-format.js#L138-L174","documentation":"normalizeBody measures the trimmed body in UTF-8 bytes and throws when it exceeds MAX_BODY_BYTES (64 KiB). This keeps each memory document within the overall 128 KiB document budget and prevents single memories from ballooning the vault.","triggerScenarios":"Calling normalizeMemory with a body whose UTF-8 encoding exceeds 65536 bytes — e.g. a large pasted log, an embedded base64 blob, or content heavy in multi-byte characters where 30k characters can exceed 64 KiB.","commonSituations":"Dumping an entire build log or stack trace into one memory; embedding base64 images/data URIs in the body; CJK/emoji-heavy text where byte length greatly exceeds character count; concatenating several documents into one memory instead of splitting them.","solutions":["Trim the body to the most relevant excerpt before saving (head/tail of logs with an elision marker).","Split the content into multiple memory documents and link them with the links field.","Strip binary/base64 blobs and store a reference/path instead of inlining them.","Check size with Buffer.byteLength(body, 'utf8') > 64 * 1024 before calling, remembering multi-byte characters count more."],"exampleFix":"// before\nnormalizeMemory({ body: fullBuildLog, ... })\n// after\nconst MAX = 64 * 1024;\nconst body = Buffer.byteLength(fullBuildLog, 'utf8') > MAX\n  ? fullBuildLog.slice(0, 20000) + '\\n...[truncated]...'\n  : fullBuildLog;\nnormalizeMemory({ body, ... })","handlingStrategy":"validation","validationCode":"const MAX_BODY_BYTES = 64 * 1024;\nif (Buffer.byteLength(body, 'utf8') > MAX_BODY_BYTES) body = truncateUtf8Safe(body, MAX_BODY_BYTES);","typeGuard":"const bodyWithinLimit = (v) => typeof v === 'string' && Buffer.byteLength(v, 'utf8') <= 64 * 1024;","tryCatchPattern":"try { normalizeMemory(mem); } catch (e) { if (e.message.includes('too large (maximum')) { mem.body = truncate(mem.body); } else throw e; }","preventionTips":["Measure size with Buffer.byteLength, not string length (multi-byte chars)","Split large content into multiple linked memories","Never inline base64/binary blobs in a memory body","Truncate logs to relevant excerpts with an elision marker before saving"],"tags":["validation","size-limit","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"}