Skip to content

The drift rule keys on span numbers, so a reused line number is a false positive with no correct fix #1447

Closed

Description

@FlorentinDUBOIS

The drifted-citation rule compares a citation only when the identical (path, spans) pair also exists in the base revision of the same document. That exemption is deliberate and documented — it is what lets a re-anchored citation through. But it keys on the span number, not on what the number refers to, so a line number that is reused for different code produces a false positive that no correct edit can avoid.

Found while reviewing the H2 sans-io extraction stack; the evidence below is from that stack but the defect is in the script.

The failure

At merge base 595920e9, lib/src/protocol/mux/LIFECYCLE.md:469 cites h2.rs:6248 for the handle_goaway_frame retry loop.

On a branch that renumbers citations after a large h2.rs edit, the StreamState::Link transition lands on h2.rs:6248 (sed -n '6248p' → stream.state = StreamState::Link;).

Renumbering the Link citation to its true new line is then reported as drift — because the base document already used that number for different code, so the (path, spans) pair is not new and the exemption does not apply. The citation is correct; the rule fires anyway.

Why this is not a one-off

Any changeset that shifts a heavily-cited file rolls these dice once per citation. doc/h2_mux_internals.md alone carries 18 pinned blocks into h2.rs, and one branch this week renumbered 75 citations in a single pass. Number reuse across a document with ~100 citations into an 8800-line file is not a rare coincidence.

The escape works, and does not cover everything

The script's own header already gives the remedy — cite a symbol wherever the prose names an item — and it is the right pattern, generalised as "cite a symbol whenever the prose names an item" rather than "cite a symbol when the drift rule complains".

It has a real gap: a citation that means a specific branch inside an item has no symbol to name. Pointing at a match arm, a particular early return, or one of several call sites inside one function cannot be expressed as a symbol, so those citations must stay numeric and remain exposed.

Related, and worth fixing together

A second exemption problem in the same rule, from the same stack: when a changeset legitimately rewrites the code a citation quotes, re-quoting the new text keeps the (path, spans) identity and therefore stays under comparison. The result is a citation that is green against the PR's base sha and red against its parent branch — and which flips to red for everyone the moment the parent merges. A gate with a fuse whose length is set by merge order.

The workaround there is to re-anchor rather than re-quote — move the span onto an enclosing construct the prose already names, creating a new identity that is legitimately exempt. That works, but it means the honest fix and the fix the rule rewards are the same only by luck.

Both cases have one root: the rule's identity for a citation is its span number, and a span number is not stable under the edits the rule exists to police.

Asked for

Decide whether the exemption can key on something better than (path, spans) — the cited text at the base revision, or the enclosing symbol resolved at both revisions, so that a number reused for unrelated code is not mistaken for the same citation. If a stable identity is not achievable, say so in the script's own output: the rule already prints an honest "this is a floor, not a proof" paragraph about rule 1, and this limitation deserves the same treatment rather than silence.

Whatever is chosen, the self-test needs a fixture for number reuse specifically: a base document citing a.rs:N, a head document citing a.rs:N for genuinely different code, and an assertion about which verdict is correct. Write the fixture so it is seen red under the current rule before the fix lands.

Do not weaken the rule to make the false positive disappear — a rule that stops comparing is worse than one that occasionally over-reports. If over-reporting is the chosen trade-off, the output must say which citations were compared on a reused number so a reviewer can disposition them.

Addendum — the exemption is unmeasurable, and that is a second defect

Added 2026-09-22 after implementing the markdown-target extension.

The exemption has an edge beyond the false positive above: a compared count reports what the rule looked at, never what it declined to look at. So this rule's coverage can silently fall to zero for a whole class of work while every counter it emits stays healthy.

Measured on a changeset that repaired six markdown citations: with .md targets enabled, 370 cited ends compared; with them disabled, 370. Zero of the six entered rule 2 — repairing a citation changes its (path, spans) pair, which is exactly what the exemption covers. The run reported OK: none of the 370 cited lines compared against <base> changed their text and was telling the truth about the 370 while saying nothing about the six.

The general shape: a rule whose exemption is keyed on change cannot measure the value of a change that qualifies for the exemption, and cannot report its own blind spot using the instrument it has.

The honest instrument is a count of exemptions taken — how many citations were skipped because their (path, spans) pair was absent at the base — emitted alongside the compared count. Nothing currently emits it. With it, a changeset that re-anchors forty citations would say so out loud instead of reporting a healthy comparison of the ones it did not touch.

That count is also the cheapest available mitigation for the false positive above, independent of whether the identity problem is solved: a reviewer who can see "38 compared, 12 exempt" knows there is something to disposition, where "38 compared" reads as complete coverage.

Activity

  1. FlorentinDUBOIS commented on Sep 25, 2026

    @FlorentinDUBOIS
    CollaboratorAuthor

    Closed by #1523, merged as 7208c74a.

    The identity problem was solved, not documented away. The exemption now keys on the cited line's text, tracked through the re-anchoring the changeset itself performed, rather than on the span number. A new helper reads both revisions and returns every cited line text whose claim moved onto a new number; the drift rule declines a span whose base text is one of them. Two counted conditions keep it evidence-based: a receiver must be a head-cited end whose number the base did not cite at all, and receivers for a text must be at least as many as the base citations that named it — the second is what keeps a half-applied renumbering reported instead of swallowed.

    Enclosing-symbol identity was considered and rejected, for a reason this issue did not anticipate: the script resolves .md targets, which have no symbols, so symbol identity would need a Rust item parser inside a deliberately dependency-free, language-agnostic script — and it still could not separate two citations inside one function, which is exactly the case this issue names as having no symbol.

    The addendum's exemption count already existed. #1478 (54dcacf5, "Refs #1447") landed it on both report shapes, after this addendum was written and without the issue being updated. It is genuinely tested rather than merely emitted: its constant is movable by a fixture, so adding one head-only citation to the fixture corpus reddens it. Nothing was rebuilt.

    The new declined class is kept separate from that count on purpose. A reuse exemption is a comparison the rule no longer performs, so it lowers the compared total and is listed line by line; folding it into the exempt count would reproduce this addendum's own defect one level down.

    The number-reuse fixture was seen red four ways, including a widening guard: with claim counting removed, a deliberately half-applied renumbering stops being reported, and the fixture catches that. Residual cases — a base citation deleted rather than re-anchored, a low-entropy line matching by coincidence — are printed with their matched text and receiving number, not silent, and the header states that declining means the base's claim moved, never that the written number is a good place to point at. That remains --audit's question.

    Precision, measured rather than asserted: sweeping 40 merged commits and 30 local branches, exactly one verdict changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions