feat(write): gate a knowledge write on duplication and citation resolution - #164
Merged
Conversation
tangletools
approved these changes
Aug 21, 2026
tangletools
left a comment
Contributor
There was a problem hiding this comment.
✅ Auto-approved drewstone PR — 028acfc4
This PR was opened by the trusted drewstone account.
This approval is provisional and was applied by the local stand-in because the pr-reviewer webhook host is unreachable (2026-08-21). CI on this head is fully green. The full PR reviewer audit re-runs via the resweep when the service returns and will publish findings if it detects issues.
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.
Why
discovery-lab measured two store defects that no later report reverses (#157, capabilities 1 and 2a):
Both were patched locally in the lab, which deepens the recorded fork. The gate belongs in the store.
What
assertKnowledgeWriteIntake(candidates, { visiblePages, nearDuplicates?, citations? })insrc/write-intake.tscomposes primitives that already exist — it adds no second detector and no second resolver:detectNearDuplicatePagesovervisible ∪ candidates, keeps only pairs touching a candidate, and refuses throughKnowledgeDuplicateIntakeErrorcarrying the offending pairs;assertKnowledgeCitationsResolvedover the same corpus and raises the existingKnowledgeCitationResolutionError.A duplicate pair is cleared by one of three authoring actions, each of which converts the duplication into structure rather than blocking it: cite the matched page, name it in
contradicts, or give the candidate that page's id so the write is an update of it. Either side of a pair may declare the relation.The candidates are part of the corpus both checks see, so a batch may cite a page it writes in the same call. Candidates replace the
hereentries at the same paths; an inherited or shared page at one of those paths stays visible, so a citation into it still reports its true ambiguity instead of silently resolving.applyKnowledgeWriteBlocks(root, text, { pagesDirectory, intake })runs the gate inside the existing mutation lock, beforecommitKnowledgeFileMutations, so a refused proposal leaves nothing on disk. CLI:apply-write-blocks --intake [--intake-threshold <n>].The lab's 0.55 title+topic Jaccard is a different similarity from the detector's 0.82 title+text shingles, so
thresholdis exposed and the detector's own default stands. No untested constant is hardcoded here.Simplification
Simplification: page construction from Markdown had one inline copy inside
loadKnowledgePagesUnlocked; it is nowknowledgePageFromMarkdown(path, content, pagesDirectory)and the reader and the gate share it, so a gate judges exactly what the store loads back. The scaffold/.mdfilter is likewise one predicate,isKnowledgePagePath. No second construction path was created.Net: +477 / -38 lines, 11 files, 1 duplicated construction path avoided (2 would have existed), 0 new detectors or resolvers.
Not done here: the intake gate does not check
contradictstargets or citation cycles;auditKnowledgeCitationsand thebroken-contradictionlint own those, and moving them to the write path is its own PR.Tests: +8 (the duplicate refusal and each of the three outs, which is the whole contract of the gate; a path rewrite that replaces rather than duplicates; a batch citing itself; a dangling cite refused at the write path with the pages directory proven untouched; a duplicate refused and then accepted once it cites), -0 deleted. No shape assertions.
Proof
The 23 failing files are identical on this branch and on clean
origin/mainon this macOS host, and every failure carries one error —knowledge transaction directory escaped its root, the/var->/private/varsymlink undertmpdir(). Linux CI has no such symlink. The new test realpaths its temp root, so it is green locally as well.Refs #157