Repository navigation
fix(tools): prevent customId collisions in claude memory tool (#1547) - #1676
Adityakk9031 wants to merge 3 commits into
Conversation
|
One migration edge looks worth covering before merge: the legacy read fallback is path-safe, but the write paths can strand both identities for the same logical file.
So after an upgrade, starting with one legacy document for
That means the first successful edit of a legacy file can make the file unusable on the next operation—the exact migration path the fallback is intended to preserve. A useful regression would seed one legacy-ID document, perform each mutating write path, then assert there is still exactly one resolvable logical file with the requested new content. The implementation could migrate/update the old identity or delete it after the new write succeeds; the important invariants are one logical file → one resolvable document, and failure ordering that does not delete the only good copy before the replacement write is durable. |
|
I checked this PR and #1586, which both address #1547. The new encoding looks injective. I tested it by brute force over every path of up to 6 characters from The risk is in existing data. The encoding changes the A possible fix: when the document that was read has the legacy id, write back to that id, or delete it after the new write. |
…event path ambiguity
Resolves #1547
Problem
In
packages/tools/src/claude-memory.ts,normalizePathToCustomIdflattened both/and.directly into_:This mapping was not injective and caused document collisions:
/memories/notes.txt,/memories/notes_txt, and/memories/notes/txtall mapped tomemories_notes_txt./memories/project/a.mdcollided with/memories/project_a.md.Because
customIdis the unique document identity when saving withclient.add(), creating or editing one path silently overwrote or destroyed documents at colliding paths.Solution
_->__/->_s_.->_d_customIds (e.g.memories_s_notes_d_txtvsmemories_s_notes__txtvsmemories_s_notes_s_txt).getFileDocumentcandidate resolution for documents previously created under legacy normalization (memories_notes_txt).claude-memory.test.tsasserting uniqueness across previously-colliding paths and verifying legacy document resolution.