Repository navigation
fix(ci): key citation drift per span and count the re-anchored exemptions - #1478
Merged
Merged
Conversation
…pans it skips `check_doc_citations.py`'s rule 2 exempts a citation the base revision of its own document did not carry, because an author who RE-ANCHORS a citation is not drifting it. That exemption was keyed on the whole parsed span tuple, and the key was the defect in two different directions. #1447 asked for them to be fixed together; they are one identity computation and share one fixture document. A FALSE NEGATIVE (#1457). Correcting one number in a group written `file.rs:NNN/MMM/PPP/QQQ` produced a tuple absent from the base, so the whole citation was classified "re-anchored by this changeset, which is not drift" and every sibling was skipped however stale it was. That is precisely the half-applied renumbering this file's own header names as a thing it means to catch, and the whole-tuple key handed it an exemption: the author who fixed one number bought silence for the rest, and the more careful the partial fix looked, the more numbers it hid. It is worse than leaving the group alone — an all-stale group reads as uniformly suspect, while a group whose first element is freshly correct reads as maintained, and a reader following the second element lands on unrelated code with no signal that anything is wrong. `06fc2708` is the worked case: it moved element 1 of three groups in `lib/src/protocol/mux/LIFECYCLE.md` by the correct shift, left seven sibling numbers on unrelated code, and the job was green. Measured, both directions: $ python3 .github/scripts/check_doc_citations.py --root <06fc2708> \ --base 06fc270^ # before: OK: none of the 233 cited lines compared against 80cd162 # changed their text. # after: ::error::6 of 240 compared citations drifted since 80cd162 # (92 re-anchored spans exempt): # …LIFECYCLE.md:308: `h2.rs:5860` was `where` # …LIFECYCLE.md:308: `h2.rs:5885` was `return false;` # …LIFECYCLE.md:308: `h2.rs:5903` was a comment # …LIFECYCLE.md:328: `mod.rs:2068` was `} else {` # …LIFECYCLE.md:328: `mod.rs:2163` was `log_module_context!()` # …LIFECYCLE.md:329: `h2.rs:5756` was `let buf = …space();` Key per SPAN. `3/6` and `3, 6` remain the same citation, which is what the parsed-span key was chosen for; only a moved element stops covering for the ones beside it. The seventh stale number, `mod.rs:2152`, escapes the per-span key too, because the text at that line equals the text at the line it used to name — a comparison of text cannot see a number that moved between two identical lines. Both ends of a range deliberately stay ONE span: they describe one construct and move together, and keying per end would compare a fresh single `file.rs:MMM` against an older `file.rs:NNN-MMM`'s end, a new false positive for no coverage. A FALSE POSITIVE (#1447), NOT FIXED, AND DOCUMENTED INSTEAD OF GUESSED AT. The exemption keys on a number, and a number is not stable under the edits the rule polices: renumbering a citation onto a line whose number the base revision spent on something else leaves the span not-new, so the exemption does not apply and a CORRECT citation is reported. At `595920e9` the mux `LIFECYCLE.md` cited an `h2.rs` line for the `handle_goaway_frame` retry loop, and a branch that renumbered after a large `h2.rs` edit put the `StreamState::Link` transition on that very line; repointing Link at its true new line was reported as drift, with no edit that would silence it. Nothing here guesses. The rule has a path, a number and two revisions of a line; it does not have the claim the number was attached to, and an honest re-anchor is indistinguishable from a reused number on that evidence — "the head text existed elsewhere at the base" fires on every insertion, genuine drift included. A rule that stopped comparing would be worse than one that occasionally over-reports, and a heuristic that guessed wrong QUIETLY would be worse than both. So the rule over-reports, says so in its own output, and the fixture pins the over-report as an expected verdict, so widening the exemption to make it disappear turns `--self-test` red instead of turning the rule off. AND THE EXEMPTION IS NOW COUNTED. A compared total reports what the rule looked at and never what it declined to look at, so coverage can fall to zero for a whole changeset with every counter it emits still healthy. #1447 measured that: on a changeset repairing six markdown citations, 370 cited ends compared with `.md` targets enabled and 370 with them disabled — zero of the six entered the rule, because repairing a citation changes its span, which is exactly what the exemption covers. Every run now prints the exempt count beside the compared one and `--show` lists each exempt span as `|re-anchored`. The two counts partition every cited end that resolved and was in range AT HEAD, which is what decides the order of the two range tests. An exempt span reads no base text, so only the HEAD range can bind it and rule 1 already owns HEAD out-of-range; testing `min(base, head)` before the exemption instead would drop every citation renumbered into the GROWN TAIL of a file, which is not a corner case but the dominant re-anchoring shape — an insertion of any size pushes later citations past the old end by construction. The base range is still tested, after the exemption, because a compared span does need a line at the base to compare against. `testdata/citations/doc/keyed.md` is the fixture and carries both shapes: a two-span group with one span moved and one left behind, and a single span whose number named different code at the base revision. `FIXTURE_TOTAL` 41 -> 44, `FIXTURE_DRIFT_COMPARED` 32 -> 34, and `FIXTURE_DRIFT_EXEMPT` is new at 3 — the third being the existing fixture's `drift.rs:16`, which sits past the base revision's 15 lines and is exactly the grown-tail case. Seen red, each production change reverted alone with the fixture kept. With the per-span key reverted to the span tuple, `--self-test` exits 1 with "expected 5 drifted citations, got 4" — the missing one being the stale sibling — plus "compared 33 ... expected exactly 34" and "4 cited lines were exempt ... expected exactly 3". With the counter reverted instead, it exits 1 with "0 cited lines were exempt from the comparison as re-anchored, expected exactly 3". With the two range tests swapped back to the old order, with "2 cited lines were exempt ... expected exactly 3", the missing one being the grown-tail case. `doc/README.md` carries the convention, including the reuse limitation; its worked examples are written in the `NNN` placeholder form, because that file is itself inside the guarded surface and a literal `file.rs:NNN` written there is a real citation — the resolver reported five of them when this changeset first spelt them out. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 23, 2026 20:40
This was referenced Sep 23, 2026
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.
Two defects in the citation gate's drift rule, both reproduced against
19fd5d8cbefore being touched. One gets a real fix; the other gets a documented limitation and an instrument, because a heuristic there would guess wrong silently.#1457 — the drift key exempted exactly the citations most likely to be wrong
untouchedkeyed on(path, tuple(spans)), so the identity of a citation was the whole span tuple. Any citation the changeset re-anchored was therefore exempt by construction, and a second staleness inside the same changeset was invisible to both invocations.Reproduced on a constructed minimal repository — one span of
g.rs:1/3moved to2, leaving the sibling3stale:Reproduced again on the real tree, at the commit #1457 names, with
--base 06fc2708^:OK: none of the 233 cited lines compared against 80cd162a3334 changed their text.::error::6 of 240 compared citations drifted since 80cd162a3334 (92 re-anchored spans exempt):The six are a byte-for-byte match with the six #1457 predicted, and
mod.rs:2152is correctly absent — its text is identical at both lines.The fix: key
untouchedon(path, span)element-wise, and move the exemption inside the span loop. This strictly widens what gets compared and adds no new exemption —3/6and3, 6remain the same citation.#1447 — a documented limitation, deliberately not a heuristic
The rule has a path, a number, and two revisions of a line. It does not have the claim the number was attached to. From that evidence an honest re-anchor and a reused line number are indistinguishable: the obvious test — "did this head text exist elsewhere at base?" — fires on every insertion, genuine drift included.
So the rule keeps over-reporting, says so in its own output, and the fixture pins the false positive as an expected verdict so a future attempt to silence it goes red rather than quietly passing.
What is added instead is the instrument the issue's addendum asked for: an exemption count printed on every run, with
--showlisting each exempt span as|re-anchored. A reviewer can now see how much of a changeset the rule declined to check, which is the number that was previously invisible.An ordering bug caught in review, worth recording
My first cut tested
min(base, head)before the exemption, which silently dropped every citation renumbered into a file's grown tail — the dominant re-anchoring shape, and precisely the population this change exists to start checking. Reordered so rule 1 owns the HEAD range first, then the exemption, then the base range for compared spans only.Red-then-green
Each production change reverted alone, against the script's existing
--self-testmode:New fixture
doc/keyed.md+keyed.rs, both with.baserevisions, carrying both shapes.FIXTURE_TOTAL41→44,FIXTURE_DRIFT_COMPARED32→34,FIXTURE_DRIFT_EXEMPTnew at 3. The production diff contains no fixture literal — the fix is not test-shaped.Verified
ci.ymlis untouched — its own comment says that if a rule changes, change the script and leave the workflow alone.Two stale claims in the script's header, reported not fixed
Its "A THIRD GAP … a prose-to-prose citation is matched by no rule" was superseded by #1458, which taught the resolver to read
.mdtargets. Its count of "exactly three such citations (:79,:157,:230)" is also stale — the tree now has two, atdoc/configure_admin_ops.md:158and:348. Left alone to keep this diff to the drift rule.Closes #1457
Refs #1447