Skip to content

fix(dedupe): scope words must not stand in for content (#421) - #422

Merged
abogartz merged 2 commits into
mainfrom
fix/dedupe-scope-token-leak
Nov 17, 2026
Merged

abogartz merged 2 commits into
mainfrom
fix/dedupe-scope-token-leak

Conversation

@abogartz

@abogartz abogartz commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

What

contentTokens() built its vocabulary from haystack() (content + keywords + scope + type) minus the whole scope/type strings. The #417 identifier tokenizer also emits the SPLIT words of a snake_case scope, so auth_token_refresh_policy left auth/token/refresh/policy standing in for content. Two unrelated non-Latin rows in that scope shared a Jaccard-1 vocabulary supplied entirely by metadata, cleared the MIN_CONTENT=4 floor on scope tokens alone, and dedup hid the older row through the composed handler.

Fix: construct the vocabulary directly from the content and keyword fields. Metadata never enters; the floor keeps doing what it exists for.

Evidence

  • Reproduced verbatim from @WhollyMindless's post-merge follow-up on perf(recall): split identifiers in the matcher tokenizer (#409) #417, through the composed memory_recall handler: query=auth_token_refresh_policy, OPENCODE_MEMORY_DEDUP=0.8, two settled learning rows. On main: only the newer row returned. With the fix: both.
  • New test test/dedupe-scope-leak.test.ts: red on origin/main (3 fail), green with the fix. Unit tests pin the leak (scope contributes zero tokens to a non-Latin row) and the intent (content + keywords still supply the vocabulary).
  • Merge gate on push: 1,441 unit + 34 e2e, 0 fail.

Blast radius

Dedup is flag-gated (OPENCODE_MEMORY_DEDUP); flag-off path untouched. Rows are never deleted — the bug hid recall results; the fix restores them.

Closes #421. Post-merge follow-up to #417.

Disclosure (from review, 2026-11-17)

Suppression strictly weakens for every multi-token scope, not only non-Latin rows: shared metadata tokens previously raised pair Jaccard ((i+k)/(u+k)); removing them lowers every pair's score, and rows whose content+kw vocabulary is under MIN_CONTENT=4 are now never compared. The §17 threshold replay ("0.8 suppresses only near-identical copies") predates this vocabulary change. The fix is flag-gated, so no shipped-behavior change on main today; PR #426 flips the default to 0.8, and the replay should be re-run against the new vocabulary before or right after that merge.

…ly (#421)

contentTokens() tokenized haystack() (content + keywords + scope + type) and
removed only the WHOLE scope/type strings. Since #417 the identifier tokenizer
also emits the split words, so a snake_case scope like auth_token_refresh_policy
left auth/token/refresh/policy standing in for content. Two unrelated non-Latin
rows in one scope then shared a Jaccard-1 metadata vocabulary, cleared
MIN_CONTENT on scope tokens alone, and dedup hid the older row through the
composed handler. Reproduced verbatim from the post-merge report on #417; the
new test file fails on main and passes with the fix.

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retested the original #417 composed-handler reproduction unchanged on 971852d, in an isolated store on Windows/Bun 1.4.4: both unrelated CJK rows now survive with dedup enabled, and both content-token sets are empty. The focused dedup suites also pass. This verifies the reported scope-token leak is addressed in this PR (which is still open), rather than a claim about private retrieval measurements. Disclosure: the base includes earlier contributions by me; no independent approval of that code is implied.

@abogartz abogartz left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review verdict: APPROVE (posted as comment — GitHub refuses approve/request-changes on self-authored PRs; the ruleset's approving review needs a second account or an admin merge).

Reviewed the branch diff against main with the reporter's probe reconstructed: contentTokens() now reads content+kw only — type/scope/status/tags all out; the CJK regression test is faithful red-on-main; no scope creep. Findings: 0 blocking, 1 disclosure (suppression strictly weakens for all multi-token scopes; §17 replay numbers predate the vocabulary change — added to the PR body; re-run the replay before/after #426 flips the default), 2 nits (a comment line on the opposite-direction change; ambient OPENCODE_MEMORY_QUERY_GATE hygiene in the new test — verified harmless).

@abogartz
abogartz merged commit 07ac3e7 into main Nov 17, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.28.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dedup: identifier tokens from scope names leak into the content-token floor (P2, post-merge follow-up on #417)

2 participants