Repository navigation
fix(note): the near-duplicate guard was wired shut for every lesson - #174
Merged
Merged
Conversation
--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.
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.
nt's near-duplicate detection could essentially never fire for the most common kind of note.nt distilland the write-time duplicate check were both silently inert.The bug
FindSimilarpairs two notes if slugs match exactly, or they share a tag and title Jaccard ≥ 0.5. ButstructuralTagstripslesson/rule/memory-corebefore the shared-tag test, and--projectnever wrote a tag at all — it writes a separateproject:frontmatter field.So a
--kind lesson --project foonote carried tags["lesson"], its tag set was empty after filtering,sharedTagwas 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
parallelSiblingsprotecting 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 inparallelSiblings, 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 WTCvswtc, or" wtc "vswtc, 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
maintwo 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
/distillremains 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 runclean, 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,
claimPathwould file the second as-2.md, andnt mv/[[links]]/ handle resolution all degrade on duplicate titles.