Skip to content

fix(ci): key citation drift per span and count the re-anchored exemptions - #1478

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/citation-drift-keying
Sep 23, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/citation-drift-keying

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Two defects in the citation gate's drift rule, both reproduced against 19fd5d8c before 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

untouched keyed 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/3 moved to 2, leaving the sibling 3 stale:

compared = 0   drifted = 0
  (no drift reported)     <- false negative: the sibling was never compared

Reproduced again on the real tree, at the commit #1457 names, with --base 06fc2708^:

result
before OK: none of the 233 cited lines compared against 80cd162a3334 changed their text.
after ::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:2152 is correctly absent — its text is identical at both lines.

The fix: key untouched on (path, span) element-wise, and move the exemption inside the span loop. This strictly widens what gets compared and adds no new exemption — 3/6 and 3, 6 remain 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 --show listing 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-test mode:

RED A — per-span key reverted to the span tuple
  FAIL self-test: expected 5 drifted citations from the fixtures, got 4
  FAIL self-test: compared 33 cited lines against the base revision, expected exactly 34
  FAIL self-test: 4 cited lines were exempt from the comparison as re-anchored, expected exactly 3
  EXIT=1

RED B — exemption counter reverted
  FAIL self-test: 0 cited lines were exempt from the comparison as re-anchored, expected exactly 3
  EXIT=1

RED C — the two range tests in the old order
  FAIL self-test: 2 cited lines were exempt from the comparison as re-anchored, expected exactly 3
  EXIT=1

GREEN — restored
  OK self-test: 44 fixture line citations, 34 of them compared against a base revision
  (3 more exempt as re-anchored), 6 examined test names (4 checked), and 3 pinned blocks
  EXIT=0

New fixture doc/keyed.md + keyed.rs, both with .base revisions, carrying both shapes. FIXTURE_TOTAL 41→44, FIXTURE_DRIFT_COMPARED 32→34, FIXTURE_DRIFT_EXEMPT new at 3. The production diff contains no fixture literal — the fix is not test-shaped.

Verified

--self-test                                  -> EXIT=0
--root .                                     -> EXIT=0
--base 19fd5d8c                              -> EXIT=0
--root .github/scripts/testdata/citations    -> EXIT=1   (CI's own gate, exit checked directly)

ci.yml is 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 .md targets. Its count of "exactly three such citations (:79, :157, :230)" is also stale — the tree now has two, at doc/configure_admin_ops.md:158 and :348. Left alone to keep this diff to the drift rule.

Closes #1457
Refs #1447

…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]>
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.

check_doc_citations.py keys drift on the whole span tuple, so a half-applied renumbering exempts every sibling number

1 participant