Skip to content

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

Closed

Description

@FlorentinDUBOIS

What happens

The drift rule treats a citation's identity as the whole span tuple, so moving one number in a multi-span citation exempts every sibling in that citation from the drift comparison.

.github/scripts/check_doc_citations.py:532-535 builds the base set:

untouched = {
    (m.group("path"), tuple(parse_spans(m.group("spans"))))
    for m in CITATION.finditer(base_body)
}

and :546-547 skips anything not found in it:

if (cited, tuple(spans)) not in untouched:
    continue  # re-anchored by this changeset, which is not drift

For a citation like h2.rs:5676/5860/5885/5903, correcting only the first number yields the tuple (5701, 5860, 5885, 5903). That tuple is absent from untouched, so the whole citation is classified "re-anchored, not drift" and continues — and 5860, 5885 and 5903 are never compared, however stale they are.

Why it matters

This is precisely the half-applied renumbering signature, which the script's own header already names as a thing it means to catch. Today it is caught only via the duplicate-number heuristic, which misses this shape entirely: the author who fixes one number in a group silently buys an exemption for the rest, and the more careful the partial fix looks, the more numbers it hides.

The failure is worse than leaving the group untouched. An all-stale group still reads as uniformly suspect; a group where element 1 is freshly correct reads as maintained, and a reader following element 2 lands on unrelated code with no signal that anything is wrong.

Observed instance

Commit 06fc2708 ("refactor(mux): hand the Endpoint trait an RTT value, not a peer socket") moved element 1 of three groups in lib/src/protocol/mux/LIFECYCLE.md by the correct shift and left seven sibling numbers pointing at unrelated code. The checker passed.

Relaxing the drift identity from the whole tuple to a single span surfaces them:

LIFECYCLE.md:308  h2.rs:5860  was `where`                          now `{`
LIFECYCLE.md:308  h2.rs:5885  was `return false;`                  now `trace!(`
LIFECYCLE.md:308  h2.rs:5903  was a comment                        now a different comment
LIFECYCLE.md:328  mod.rs:2068 was `} else {`                       now `set_default_answer(...)`
LIFECYCLE.md:328  mod.rs:2163 was `log_module_context!()`          now `);`
LIFECYCLE.md:329  h2.rs:5756  was `let buf = kawa.storage.space();` now `buf[..frame.len()].copy_from_slice(&frame);`

mod.rs:2152 is a seventh stale number that escapes even that relaxed check, because the text at that line happens to be identical to the text at the line it used to name.

Suggested direction

Key the drift identity per span, not per tuple: a span that is byte-identical between base and head is still subject to rule 2 even when a sibling in the same citation moved. Element-wise, (path, span) rather than (path, tuple(spans)).

Note the existing comment at :530-532 gives a genuine reason for parsing spans rather than comparing their text — it makes 3/6 and 3, 6 the same citation, which they are. A per-span key preserves that property; it only stops one moved element from covering for the others.

Relationship to #1447

Distinct. #1447 is about a span number being reused across bullets, producing a false positive with no correct fix. This is the opposite failure: a false negative, where a partial correction suppresses true drift. A fix for one does not address the other, though both live in the same identity computation.

Activity

  1. FlorentinDUBOIS commented on Sep 23, 2026

    @FlorentinDUBOIS
    CollaboratorAuthor

    Measured case: a clean merge producing 14 silently wrong citations

    Rebasing #1460 onto main produced a concrete instance of this gap, worth recording because the
    citations involved carried no conflict marker — so nothing prompted a human to look at them.

    Both sides had independently inserted a line into lib/src/protocol/mux/mod.rs:

    • main inserted mod h2_scheduler; at line 146, shifting every citation below it by +1.
    • the branch inserted at line 668, shifting every citation below that by +1.

    A citation below both anchors — mod.rs:1341 at the merge base — was therefore rewritten to
    mod.rs:1342 on both sides. Git saw identical text and merged it cleanly. The correct value in the
    merged tree is mod.rs:1343: both shifts apply.

    14 citations landed wrong this way — 13 in lib/src/protocol/mux/LIFECYCLE.md, 1 in
    doc/testing.md, every one off by exactly 1. They were found only by manually re-aligning 123
    citations across 5 docs against their merge-base counterparts.

    Why the gate passed

    • Rule 1 passes: mod.rs:1342 resolves to a real, non-blank line. It is simply the wrong one.

    • Rule 2 never runs on it. The drift identity is the whole (path, spans) tuple:

      untouched = {(m.group("path"), tuple(parse_spans(m.group("spans"))))
                   for m in CITATION.finditer(base_body)}
      ...
      if (cited, tuple(spans)) not in untouched:
          continue  # re-anchored by this changeset, which is not drift

      Because the changeset did change 1341 → 1342, the tuple differs from the base tuple and the
      citation is exempted as "re-anchored". The gate never asks whether 1342 is correct.

    The general shape: a change detector cannot detect a wrong value that was changed. A clean merge
    is the worst case for it, because the clean merge is caused by both sides making the same partial
    correction.

    Verified after repair, at 4d87d9c8

    • mod.rs:1343 is if self.frontend.readiness().event.is_hup(), and LIFECYCLE.md:270 now cites
      mod.rs:1343.
    • mod.rs:673 is stream.metrics.reset();, and LIFECYCLE.md:350 now cites mod.rs:673.

    check_doc_citations.py --root . and --base 3e9c271c both exit 0 on the merged tree (222
    citations, 16/16 pins verbatim) — before and after the repair, which is the point.

    Note for whoever fixes this

    A uniform-offset repair is not available: on this rebase, difflib.SequenceMatcher(autojunk=False)
    line alignment between base and merged tree gave h2.rs 35 blocks / 20 distinct shifts, mod.rs
    7/6, h1.rs 10/8, router.rs 5/4, stream.rs 10/9, shared.rs 4/3. There is no single +N.

  2. FlorentinDUBOIS commented on Sep 23, 2026

    @FlorentinDUBOIS
    CollaboratorAuthor

    Correction to the example in my previous comment — the mechanism stands, but I picked the one
    citation in the set that rule 1 does catch.

    At 4d87d9c8, lib/src/protocol/mux/mod.rs:1342 is an empty line:

    $ git show 4d87d9c8:lib/src/protocol/mux/mod.rs | sed -n '1341,1343p' | cat -An
       1  ········let·mut·counter·=·0;␊
       2  ␊
       3  ········if·self.frontend.readiness().event.is_hup()␊
    

    So for that citation rule 1 fires on the blank line, and in fact that is how the class was noticed
    at all
    . My claim that rule 1 passed on it was wrong.

    The correct example for "every rule passes" is a sibling from the same batch, one line group earlier:

    $ git show 4d87d9c8:lib/src/protocol/mux/mod.rs | sed -n '671,673p'
                stream.front.storage.clear();
                stream.forget_upstream_replay();
                stream.metrics.reset();
    

    Base cited 671, both sides shifted it to 672, the truth is 673. mod.rs:672 is
    stream.forget_upstream_replay(); — real, non-blank, and wrong. Rule 1 passes. Rule 2 exempts it
    because the changeset changed the (path, spans) tuple. Nothing reports it.

    It is a sharper example than the one I gave, because forget_upstream_replay is a method the branch
    itself introduced
    — 0 occurrences in mod.rs at main@3e9c271c, 3 at 4d87d9c8 — so the wrong line
    is code that did not exist on either side of the comparison the gate performs.

    The counts and the rest of the analysis are unchanged: 14 citations landed wrong, and the blank-line
    coincidence is the only reason any of them surfaced. A repair for this issue should not assume rule 1
    provides a backstop — it caught roughly one in fourteen here, by luck of alignment.

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