fix(tools): anchor memory index-line match to prevent index corruption (#486) - #487
Draft
TYRMars wants to merge 1 commit into
Draft
fix(tools): anchor memory index-line match to prevent index corruption (#486)#487TYRMars wants to merge 1 commit into
TYRMars wants to merge 1 commit into
Conversation
…ted entries (#486) `mergeIndexLine` (memory.write) and `removeIndexLine` (memory.delete) located an entry's MEMORY.md line with an unanchored substring test (`line.includes("](<slug>.md)")`). Because summaries are free-form markdown one-liners, a summary that embeds another entry's `](.md)` link would match — writing one slug silently replaced, and deleting one slug silently dropped, the unrelated entry, corrupting the memory index (data loss) with no error surfaced. The `](<slug>.md)` link is always the line's terminal token, so anchor the match with `line.trimEnd().endsWith(needle)` in both functions. Adds two regression tests covering write-clobber and delete-collateral. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011HvA2WP4xHYUJmQjuejoYL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #486.
mergeIndexLine(used bymemory.write) andremoveIndexLine(used bymemory.delete) inpackages/tools/src/memory-tools.tslocated an entry'sMEMORY.mdline with an unanchored substring test —line.includes("](<slug>.md)").Index lines have the shape
- [<summary>](<slug>.md), and summaries are free-form markdown one-liners the model writes. If one entry's summary text embeds a markdown link to another entry's.md(e.g.summary: "see [the guide](guide.md) for details"), then writing or deleting theguideslug matched the unrelatedlinksline — silently replacing it (write) or dropping it (delete). The result is silent memory-index corruption / data loss with no error surfaced: the orphaned body file disappears frommemory.listand system-prompt injection.Fix
The
](<slug>.md)markdown link is always the line's terminal token, so anchor the match to the end of the line:line.trimEnd().endsWith(needle)instead ofline.includes(needle), in both functions.Tests
Added two regression tests to
memory-tools.test.ts:write does not clobber an entry whose summary embeds another slug's .md linkdelete does not remove an entry whose summary embeds the target's .md linkBoth fail against the pre-fix code and pass after the change. Full
@jarvis/toolssuite (42 memory tests) passes;typecheckandeslintclean on the changed files.🤖 Generated with Claude Code
https://claude.ai/code/session_011HvA2WP4xHYUJmQjuejoYL
Generated by Claude Code