Skip to content

Collapse byte-identical turn hits at recall time - #4

Merged
ericwalisko merged 1 commit into
mainfrom
ericwalisko/recall-collapse-identical
Sep 3, 2026
Merged

Collapse byte-identical turn hits at recall time#4
ericwalisko merged 1 commit into
mainfrom
ericwalisko/recall-collapse-identical

Conversation

@ericwalisko

Copy link
Copy Markdown
Owner

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 --glob would 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:

  • Recall-time view only — no turn is deleted. Sessions still read back whole; distinct findings inside those automation sessions still surface on their own text.
  • Deterministic, model-free — byte-identical match, no similarity thresholds. Consistent with memware's no-model-in-the-loop design.
  • Opt out with collapse_duplicates=False.

Tests

  • New 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.
  • 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.

Full suite, ruff, ruff format, mypy all green locally.

🤖 Generated with Claude Code

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
@ericwalisko
ericwalisko merged commit 3e2a3e2 into main Sep 3, 2026
6 checks passed
@ericwalisko
ericwalisko deleted the ericwalisko/recall-collapse-identical branch September 3, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant