{"record":{"id":"d5c8d532f02f3428","repo":"affaan-m/ECC","slug":"duplicate-memory-frontmatter-field-in-sourcepath","errorCode":null,"errorMessage":"Duplicate memory frontmatter field in ${sourcePath}.","messagePattern":"Duplicate memory frontmatter field in (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/memory-vault-format.js","lineNumber":233,"sourceCode":"  try {\n    return FATAL_UTF8_DECODER.decode(buffer);\n  } catch {\n    throw new Error(`${label} must contain valid UTF-8 text.`);\n  }\n}\n\nfunction parseFrontmatterLine(line, sourcePath, seen) {\n  const separator = line.indexOf(':');\n  if (separator <= 0) {\n    throw new Error(`Invalid memory frontmatter line in ${sourcePath}.`);\n  }\n  const serializedKey = line.slice(0, separator).trim();\n  const objectKey = FRONTMATTER_KEYS.get(serializedKey);\n  if (!objectKey) {\n    throw new Error(`Unknown memory frontmatter field in ${sourcePath}.`);\n  }\n  if (seen.has(objectKey)) {\n    throw new Error(`Duplicate memory frontmatter field in ${sourcePath}.`);\n  }\n  const rawValue = line.slice(separator + 1).trim();\n  try {\n    return { objectKey, value: JSON.parse(rawValue) };\n  } catch {\n    throw new Error(`Memory frontmatter field in ${sourcePath} must use a JSON value.`);\n  }\n}\n\nfunction parseMemoryDocument(source, sourcePath = '<memory>') {\n  const openingMarker = typeof source === 'string'\n    ? /^---\\r?\\n/.exec(source)\n    : null;\n  if (!openingMarker) {\n    throw new Error(`Memory document ${sourcePath} must start with --- frontmatter.`);\n  }\n  if (Buffer.byteLength(source, 'utf8') > MAX_DOCUMENT_BYTES) {\n    throw new Error(`Memory document ${sourcePath} is too large.`);","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/memory-vault-format.js#L215-L251","documentation":"Thrown by parseFrontmatterLine() via the 'seen' Set when the same serialized key (normalised to its objectKey) appears twice in one frontmatter block. Duplicate fields create ambiguity about which value wins; rather than picking last/first, the parser rejects the document. This catches copy-paste errors and merge-conflict leftovers.","triggerScenarios":"A git merge that left both versions of a field: 'title: \"a\"' and later 'title: \"b\"'. Copy-paste of a block that included the title twice. AI agent appending a 'kind:' line to a document that already had one. Editor template that pre-fills fields the user then re-added.","commonSituations":"Post-merge memory file never edited after conflict resolution. Repetitive templating workflow. Refactor that moved fields around but did not delete the originals.","solutions":["Open sourcePath and remove the duplicate line, keeping one canonical value.","After a git merge, grep each vault file for repeated keys.","Run doctorMemoryVault() to enumerate which files fail validation, then fix each.","Regenerate via serializeMemoryDocument() to guarantee one of each field."],"exampleFix":"// before\n---\ntitle: \"handoff A\"\nkind: \"handoff\"\ntitle: \"handoff B\"        // duplicate\n---\n\n// after\n---\ntitle: \"handoff A\"\nkind: \"handoff\"\n---","handlingStrategy":"validation","validationCode":"const seen = new Set();\nfor (const line of frontmatterLines) {\n  const key = line.slice(0, line.indexOf(':')).trim();\n  if (seen.has(key)) throw new Error(`duplicate frontmatter key: ${key}`);\n  seen.add(key);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After git merges on vault files, scan for repeated frontmatter keys.","Author via serializeMemoryDocument() — it emits each field exactly once.","Run doctorMemoryVault() as a post-merge check."],"tags":["parsing","frontmatter","validation","memory-vault","duplicate"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}