affaan-m/ECC · error · Error

memory body is too large (maximum ${MAX_BODY_BYTES} bytes).

Error message

memory body is too large (maximum ${MAX_BODY_BYTES} bytes).

What it means

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.

Source

Thrown at scripts/lib/memory-vault-format.js:156

  ) {
    throw new Error(`${label} must be an ISO-8601 timestamp.`);
  }
  return normalized;
}

function normalizeBody(value) {
  if (typeof value !== 'string') {
    throw new Error('memory body must be a string.');
  }
  if (hasUnsafeControlCharacters(value, true)) {
    throw new Error('memory body must not contain unsafe control or bidirectional formatting characters.');
  }
  const normalized = value.trim();
  if (normalized.length === 0) {
    throw new Error('memory body must contain non-whitespace context.');
  }
  if (Buffer.byteLength(normalized, 'utf8') > MAX_BODY_BYTES) {
    throw new Error(`memory body is too large (maximum ${MAX_BODY_BYTES} bytes).`);
  }
  return normalized;
}

function normalizeMemory(memory) {
  if (!memory || typeof memory !== 'object' || Array.isArray(memory)) {
    throw new Error('memory must be an object.');
  }

  const targetHarnesses = uniqueStrings(memory.targetHarnesses, {
    label: 'target harnesses',
    limit: MAX_TARGETS,
    validator: value => validateSlug(value, 'target harness'),
  });
  if (targetHarnesses.length === 0) {
    throw new Error('target harnesses must contain at least one harness or "all".');
  }

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Truncate before saving: body = body.slice(0, 60000) to leave headroom for multi-byte tails.
  2. Split into multiple memories linked via the links field, each under the cap.
  3. Store large payloads out-of-band (a file, an object store) and put the reference in body.
  4. Add a pre-check: if (Buffer.byteLength(body, 'utf8') > 65536) throw new Error('too big').

Example fix

// before
saveMemory({ title: 'log dump', body: entireLogFile }); // 2 MB

// after
const MAX_BODY_BYTES = 64 * 1024;
let body = entireLogFile;
if (Buffer.byteLength(body, 'utf8') > MAX_BODY_BYTES) {
  body = body.slice(0, 60000) + '\n…[truncated]';
}
saveMemory({ title: 'log dump', body });
Defensive patterns

Strategy: validation

Validate before calling

const { MAX_BODY_BYTES } = require('./scripts/lib/memory-vault-format');
if (Buffer.byteLength(input.body, 'utf8') > MAX_BODY_BYTES) {
  throw new Error(`body exceeds ${MAX_BODY_BYTES} bytes; split or truncate.`);
}
saveMemory(input);

Type guard

function isWithinBodyLimit(value): value is string {
  return typeof value === 'string'
    && Buffer.byteLength(value, 'utf8') <= 64 * 1024;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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