Repository navigation
fix(tools): make claude memory customId injective to stop silent file overwrites - #1586
Sravanjangam wants to merge 1 commit into
Conversation
…writes normalizePathToCustomId flattened / and . to _ non-injectively, so /memories/notes.txt, /memories/notes_txt and /memories/notes/txt all mapped to memories_notes_txt — create/delete/view on one path silently hit another file's document (supermemoryai#1547). pathToCustomId now keeps the exact legacy id only for the canonical /dir/file.ext shape (no underscore, one dot, one slash) so existing documents keep resolving, and appends an 8-hex sha256 digest of the original path for every other shape, making distinct paths map to distinct ids. Round-trip collision tests included.
|
I checked this PR and #1676, which both address #1547. Merged onto Keeping the legacy id for A possible fix: when the lookup under the new id finds nothing, retry with the plain flattened id and accept the result only if |
|
🤖 AI-assisted triage, reviewed by @MaheshtheDev. Thanks! #1676 fixes #1547 with legacy cleanup, so we're going with that one. Closing. |
Fixes #1547.
Hi supermemory team 👋 Thanks for building such a great product! While running a security & quality audit of the repo we hit this issue and put together a small, tested fix — details below.
Problem
ClaudeMemoryTool.normalizePathToCustomIdflattened/and.to_non-injectively:/memories/notes.txt,/memories/notes_txt, and/memories/notes/txtall mapped tomemories_notes_txt. Creating, viewing, or deleting one path therefore silently operated on a different file's document — silent data loss with no error surfaced.Solution
Exported pure
pathToCustomId()keeps the exact legacy id for the canonical single-segment shape (no underscore, exactly one dot, exactly one slash — e.g./dir/file.ext) so already-stored documents keep resolving with zero migration, and appends an 8-hex sha256 digest of the original path for every other shape, making distinct paths map to distinct IDs again.Changes
packages/tools/src/claude-memory.ts→ private method now delegates to the new exportedpathToCustomId()(all six call sites covered)packages/tools/src/claude-memory.test.ts→ +4 tests: three-way collision from the issue, legacy-id stability, determinism, distinct digests for distinct underscore pathsVerification
Fresh from the committed branch:
bunx vitest run src/claude-memory.test.ts→ 14/14 pass.packages/tools/test/**carries pre-existing type errors unrelated to this change (tracked in #1545) — this diff adds none.Happy to iterate on any of this — feedback and reworks very welcome! 🙏
Environment
fix/claude-memory-customid-collision— all gates re-run fresh at commit049a50ee0ac6