{"record":{"id":"27dfbc57dd30f8b6","repo":"affaan-m/ECC","slug":"memory-memoryid-is-duplicated-in-matches-leng","errorCode":null,"errorMessage":"Memory ${memoryId} is duplicated in ${matches.length} files.","messagePattern":"Memory (.+?) is duplicated in (.+?) files\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/memory-vault.js","lineNumber":688,"sourceCode":"  const targetHarness = options.targetHarness\n    ? validateSlug(options.targetHarness, 'target harness')\n    : null;\n  const loaded = readMemoryFiles(options);\n  if (loaded.truncated || loaded.invalidFileCount > 0) {\n    throw incompleteMemoryLookupError();\n  }\n  const matches = loaded.entries\n    .filter(entry => entry.memory.id === memoryId)\n    .filter(entry => (\n      !targetHarness\n      || entry.memory.targetHarnesses.includes('all')\n      || entry.memory.targetHarnesses.includes(targetHarness)\n    ));\n  if (matches.length === 0) {\n    throw new Error(`Memory ${memoryId} was not found.`);\n  }\n  if (matches.length > 1) {\n    throw new Error(`Memory ${memoryId} is duplicated in ${matches.length} files.`);\n  }\n  const allBacklinks = loaded.entries\n    .filter(entry => entry.memory.links.includes(memoryId))\n    .filter(entry => entry.memory.status === 'active')\n    .map(entry => entry.memory)\n    .filter(memory => (\n      !targetHarness\n      || memory.targetHarnesses.includes('all')\n      || memory.targetHarnesses.includes(targetHarness)\n    ))\n    .sort((left, right) => left.id.localeCompare(right.id));\n  const backlinks = allBacklinks\n    .slice(0, MAX_RESULTS)\n    .map(summarizeMemory);\n  return {\n    ...matches[0],\n    backlinks,\n    backlinksTruncated: allBacklinks.length > backlinks.length,","sourceCodeStart":670,"sourceCodeEnd":706,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/memory-vault.js#L670-L706","documentation":"The vault expects each memory id to resolve to exactly one file. During id lookup, if more than one loaded entry matches the same memory id (after harness filtering), the library throws this error instead of guessing which duplicate is authoritative. Duplicates typically arise from files written outside the library's create-only safeguards.","triggerScenarios":"Two files in the vault (possibly in different kind directories or roots) both parse to memories with the same id, and a lookup by that id matches both.","commonSituations":"Manually copying memory .md files in the vault; merging vault directories from two machines; a sync tool duplicating files; editing an id inside a file to match an existing one.","solutions":["Locate the duplicate files (search the vault for the id in frontmatter) and delete or rename one.","Give one copy a new unique id and re-save it properly via saveMemory.","Reconcile merged/synced vault directories so each id exists once.","Avoid manual edits/copies inside the vault; use library APIs."],"exampleFix":"// before\n# vault contains notes/abc.md and references/abc.md with the same id: abc\n// after\n# rename the second file's memory id to abc-ref and save via the API, or delete the stale copy\nrm vault/references/abc.md","handlingStrategy":"try-catch","validationCode":"const dupes = loadedEntries.filter(e => e.memory.id === memoryId);\nif (dupes.length > 1) console.warn(`Memory ${memoryId} duplicated across ${dupes.map(d => d.path).join(', ')}`);","typeGuard":null,"tryCatchPattern":"try {\n  const memory = lookupMemory(memoryId);\n} catch (err) {\n  if (err.message.includes('is duplicated')) {\n    // locate and remove the duplicate file, then retry the lookup\n  } else throw err;\n}","preventionTips":["Never copy or manually create .md files inside the vault.","Deduplicate vault directories before merging vaults from multiple machines.","Periodically scan the vault for duplicate ids.","Treat memory ids as globally unique across all kind directories."],"tags":["duplicate","invariant-violation","memory-vault"],"backgroundTag":"internal-invariant-violation","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"}