Collapse byte-identical turn hits at recall time - #4
Merged
Conversation
A user's own scheduled-automation prompts (a nightly cron's system prompt, say) are real turns captured identically on many days. The schema-v2 skip-prefix sweep only catches harness-injected boilerplate, so these verbatim repeats slip in and crowd recall — e.g. 3 of 8 result slots going to copies of one string. Widen the existing "collapse to one per turn" rule to "collapse turns whose quoted text is byte-identical", keeping the highest-ranked copy. It runs in both the single-query and multi-query (post-RRF) paths, is deterministic and model-free, and is a recall-time view only: every turn stays in the store, a session still reads back whole, and distinct findings inside those sessions still surface. Opt out with collapse_duplicates=False. Two existing tests seeded byte-identical text across sessions purely as a convenience (recency ordering; session separation); made their seeds distinct so they test what they intend without tripping the new collapse. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NnaQwZUSDRbVUNh8fsdksD
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.
Problem
The work laptop found a second duplicate source the schema-v2 skip-prefix sweep can't catch. That sweep only removes harness-injected boilerplate (
Base directory for this skill:, the local-commands caveat). But a user's own scheduled-automation prompts — a nightly cron's system prompt captured identically every day — are real turns, so no static prefix list will ever match them. Observed: 3 of 8 MCP recall slots going to byte-identical copies of one string; one preamble repeated 11× across the store.prune --globwould delete those sessions' real findings along with the preambles, so it's the wrong tool.Fix
Widen the existing "collapse to one hit per turn" to "collapse turns whose quoted text is byte-identical", keeping the highest-ranked copy. Applied in both the single-query path (
search_turns) and the multi-query path (after RRF fusion, since RRF keys on(kind, id)and wouldn't dedup distinct turn ids).Properties:
collapse_duplicates=False.Tests
test_recall_collapses_byte_identical_turns_but_keeps_distinct_findings: three identical cron prompts collapse to one slot, a distinct finding sharing vocabulary still surfaces, opt-out returns the copies, and the store still holds all four turns.Full suite, ruff, ruff format, mypy all green locally.
🤖 Generated with Claude Code