fix: dedup relevant-memories injection to prevent duplicate bullets - #4
Open
foxsky wants to merge 1 commit into
Open
fix: dedup relevant-memories injection to prevent duplicate bullets#4foxsky wants to merge 1 commit into
foxsky wants to merge 1 commit into
Conversation
The memory server can store the same text content across different sessions (e.g., repeated workspace-update instructions or identical heartbeat prompts). When `searchLongTermMemory` returns the top N results by similarity, these duplicates occupy multiple result slots, causing the `<relevant-memories>` block to contain 2-3 identical bullets and waste ~67% of the injection token budget. This was observed on a 7-agent OpenClaw board where every `<relevant-memories>` block contained the same instruction 3 times: ``` <relevant-memories query-specific="true"> - On April 5, 2026, User received a workspace update notification... - On April 5, 2026, User received a workspace update notification... - On April 5, 2026, User received a workspace update notification... </relevant-memories> ``` Fix: add a content-hash dedup filter (Set<string> on trimmed text) between the search results and the injection. Unique results are preserved in their original similarity-ranked order. The logger now reports `unique/total` counts so operators can see the dedup ratio. This is a read-side fix only. A complementary write-side fix (dedup on insert into the memory server) would prevent duplicates from accumulating in the first place, but that requires changes to the agent-memory-server, not this plugin.
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
searchLongTermMemoryresults and<relevant-memories>injectionunique/totalcounts for observabilityProblem
On a 7-agent OpenClaw board, every
<relevant-memories>block contained the same instruction 3 times:Fix
Read-side dedup using a
Set<string>on trimmed text in the auto-recallbefore_prompt_buildhandler. Unique results preserved in similarity-ranked order.Test plan
<relevant-memories>blocks contain unique bulletsinjecting 1/3 query-specific memories (deduped)pattern🤖 Generated with Claude Code