Skip to content

fix(tools): anchor memory index-line match to prevent index corruption (#486) - #487

Draft
TYRMars wants to merge 1 commit into
mainfrom
claude/vibrant-dijkstra-c9ytya
Draft

fix(tools): anchor memory index-line match to prevent index corruption (#486)#487
TYRMars wants to merge 1 commit into
mainfrom
claude/vibrant-dijkstra-c9ytya

Conversation

@TYRMars

@TYRMars TYRMars commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #486.

mergeIndexLine (used by memory.write) and removeIndexLine (used by memory.delete) in packages/tools/src/memory-tools.ts located an entry's MEMORY.md line 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 the guide slug matched the unrelated links line — 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 from memory.list and 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 of line.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 link
  • delete does not remove an entry whose summary embeds the target's .md link

Both fail against the pre-fix code and pass after the change. Full @jarvis/tools suite (42 memory tests) passes; typecheck and eslint clean on the changed files.

🤖 Generated with Claude Code

https://claude.ai/code/session_011HvA2WP4xHYUJmQjuejoYL


Generated by Claude Code

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants