affaan-m/ECC · error · Error

Duplicate memory frontmatter field in

Error message

Duplicate memory frontmatter field in ${sourcePath}.

What it means

parseFrontmatterLine() tracks which object keys have already been seen (via the `seen` set) across the frontmatter block. Because each frontmatter field maps to exactly one memory property, a second occurrence of the same key is ambiguous and is rejected instead of last-value-wins.

Solutions

  1. Delete the duplicate line, keeping the one with the correct value.
  2. Search the frontmatter block for the field name and keep a single occurrence.
  3. Resolve any git conflict markers and ensure the merged document has each field exactly once.
  4. Regenerate the document via the library's save path to guarantee canonical single-occurrence frontmatter.

Example fix

// before
---
id: "notes"
id: "notes-v2"
title: "Deploy notes"
---

// after
---
id: "notes-v2"
title: "Deploy notes"
---
Defensive patterns

Strategy: validation

Validate before calling

const keys = frontmatterLines.map(l => l.slice(0, l.indexOf(':')).trim());
const dupes = keys.filter((k, i) => keys.indexOf(k) !== i);
if (dupes.length) throw new Error(`Duplicate frontmatter keys: ${dupes.join(', ')}`);

Type guard

const hasNoDuplicateKeys = (lines) => new Set(lines.map(l => l.split(':')[0].trim())).size === lines.length;

Try / catch

try {
  parseMemoryDocument(source, path);
} catch (err) {
  if (err.message.includes('Duplicate memory frontmatter field')) {
    console.error('A field appears twice in %s frontmatter; keep exactly one occurrence.', path);
  } else throw err;
}

Prevention

When it happens

Trigger: A memory document whose frontmatter block contains the same field twice, e.g. two `title:` lines or two `id:` lines (possibly with different serialized spellings mapping to the same object key); concatenating two documents' frontmatter.

Common situations: Merge-conflict resolution in git that duplicated a line; appending an updated field instead of editing the existing one; copy-paste of a field while hand-editing the markdown vault.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/d5c8d532f02f3428. Report an issue: GitHub.

Appendix: source

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

  try {
    return FATAL_UTF8_DECODER.decode(buffer);
  } catch {
    throw new Error(`${label} must contain valid UTF-8 text.`);
  }
}

function parseFrontmatterLine(line, sourcePath, seen) {
  const separator = line.indexOf(':');
  if (separator <= 0) {
    throw new Error(`Invalid memory frontmatter line in ${sourcePath}.`);
  }
  const serializedKey = line.slice(0, separator).trim();
  const objectKey = FRONTMATTER_KEYS.get(serializedKey);
  if (!objectKey) {
    throw new Error(`Unknown memory frontmatter field in ${sourcePath}.`);
  }
  if (seen.has(objectKey)) {
    throw new Error(`Duplicate memory frontmatter field in ${sourcePath}.`);
  }
  const rawValue = line.slice(separator + 1).trim();
  try {
    return { objectKey, value: JSON.parse(rawValue) };
  } catch {
    throw new Error(`Memory frontmatter field in ${sourcePath} must use a JSON value.`);
  }
}

function parseMemoryDocument(source, sourcePath = '<memory>') {
  const openingMarker = typeof source === 'string'
    ? /^---\r?\n/.exec(source)
    : null;
  if (!openingMarker) {
    throw new Error(`Memory document ${sourcePath} must start with --- frontmatter.`);
  }
  if (Buffer.byteLength(source, 'utf8') > MAX_DOCUMENT_BYTES) {
    throw new Error(`Memory document ${sourcePath} is too large.`);

View on GitHub (pinned to 8321021c54)