Skip to content

fix(note): the near-duplicate guard was wired shut for every lesson - #174

Merged
navbytes merged 2 commits into
mainfrom
claude/fix-dedup-tag-gate
Jul 28, 2026
Merged

navbytes merged 2 commits into
mainfrom
claude/fix-dedup-tag-gate

Conversation

@navbytes

Copy link
Copy Markdown
Owner

nt's near-duplicate detection could essentially never fire for the most common kind of note. nt distill and the write-time duplicate check were both silently inert.

The bug

FindSimilar pairs two notes if slugs match exactly, or they share a tag and title Jaccard ≥ 0.5. But structuralTag strips lesson/rule/memory-core before the shared-tag test, and --project never wrote a tag at all — it writes a separate project: frontmatter field.

So a --kind lesson --project foo note carried tags ["lesson"], its tag set was empty after filtering, sharedTag was always false, and the Jaccard branch was never evaluated. Only exact-slug collisions could ever be caught.

Demonstrated: a title with 0.82 Jaccard against an existing note was accepted with no warning; only a byte-identical slug was refused.

The code already believed project was a tag — the comments describing parallelSiblings protecting per-project variants describe behaviour that was also inert. This is implementation drift from documented intent.

The fix

Fold the project into the in-memory tag set used for sharedTag (and correspondingly in parallelSiblings, so genuine per-project variants stay protected). No on-disk format change — project is never written as a literal tag, so no store is rewritten.

Project is trimmed and lowercased at the fold point. Without that, --project WTC vs wtc, or " wtc " vs wtc, put the guard straight back to sleep with no signal — and the write path already trimmed while the dedup path did not, so the two disagreed about the same flag value.

Before/after, verified on the real binary: on main two same-project lessons with high title overlap were both created silently; with this fix the second is refused with a remedy (--append / --supersede / --force).

What this does NOT do — read before judging it

On a 29-note store written by five concurrent agents, this surfaces zero new pairs, and that is the correct, expected outcome. Max title Jaccard across all 406 pairs there is 0.375, under the 0.5 gate. This repairs a gate that was wired shut; it is not a paraphrase detector.

Description-level similarity was investigated as the alternative and rejected on evidence: max description Jaccard is 0.265 (the strongest true duplicate cluster scores 0.100), so a 0.5 threshold finds nothing, and dropping to 0.25 starts merging unrelated Go and Swift lessons. Lexical similarity is the wrong instrument for paraphrase — the prompt-level sweep in /distill remains the semantic layer, and it demonstrably works.

Verified

Reviewed context-isolated (verdict: ship). New regression tests confirmed FAILING pre-fix, including the one that matters most — same project, different topics → still no pair, i.e. folding project in did not bypass the Jaccard gate and turn every lesson into a duplicate. go build ./..., go test ./..., go vet ./..., golangci-lint run clean, run bare.

Known, deliberately out of scope

An identical title under two different projects is still refused (the exact-slug branch returns before any project logic). That is pre-existing and unchanged. On review we judged it correct to keep: two notes both titled "release checklist" self-identify as nothing, claimPath would file the second as -2.md, and nt mv / [[links]] / handle resolution all degrade on duplicate titles.

navbytes added 2 commits July 29, 2026 00:24
--project stores its value as a separate `project:` frontmatter field,
not a tag. A note whose only tag is a class marker (lesson/rule/
memory-core, stripped by structuralTag) therefore had an EMPTY tag set
in FindSimilar, so the Jaccard near-duplicate branch could never fire
for the most common kind of note — only exact-slug matches worked.
`nt distill` and the write-time dedup guard were silently inert for
these notes.

FindSimilar/parallelSiblings now fold project into the in-memory tag
set they compare on (via a new similarityTags/tagsWithProject helper),
without writing project as a literal tag to disk. Threaded the project
value through FindSimilar's three real call sites (cli note create,
mcp note create, distill's NearDupPairs); import has no project
concept so it passes "".
Project was folded into FindSimilar's in-memory tag set verbatim, so
--project wtc vs WTC (or " wtc ") silently missed each other — the
write path (commands.go:697) trims before storing the frontmatter but
FindSimilar's call site (commands.go:675) doesn't, so the two paths
disagreed about the same flag value. Trim+lowercase in
similarityTags/tagsWithProject covers all call sites in one change,
matching recall.go's projectTokens normalization. TAG case is
pre-existing and untouched.

Also adds the missing same-project/different-topic regression (the
main nuisance-pair risk of folding project into the tag set) and a
test pinning the case/whitespace fix.
@navbytes
navbytes merged commit 09d84b9 into main Jul 28, 2026
9 checks passed
@navbytes
navbytes deleted the claude/fix-dedup-tag-gate branch July 28, 2026 17:33
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