Skip to content

fix(ci): key the drifted-citation exemption on the cited line, not its number (#1447) - #1523

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/citation-drift-identity
Sep 25, 2026
Merged

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

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Rule 2 of check_doc_citations.py compares a citation this changeset did not touch against the text it named at the base revision, and exempts one the changeset re-anchored. That exemption asked whether the span was present at the base — and a span number is not stable under the edits the rule exists to police.

The identity I chose, and the one I rejected

Chosen: the cited LINE, tracked through the re-anchoring this changeset performed. reanchored_claims reads both revisions and returns every cited line text whose claim this changeset carried onto a new number. check_drift declines a span whose base text is one of them: what the base document named at that number is alive elsewhere, so the span under test is a different citation that inherited the number rather than the base one left behind.

Nothing guesses, and two counted conditions keep it that way:

  • a receiver is only a head-cited end whose number this document did not cite at the base at all. A number the base already carried explains nothing — it is as likely to be a second stale citation, which is exactly what two adjacent citations do when their file loses a line and each lands on its neighbour's old text.
  • the receivers for a text must be at least as many as the base citations that named it. A document that named one line twice and re-anchored one of the two has left the other behind — that is check_doc_citations.py keys drift on the whole span tuple, so a half-applied renumbering exempts every sibling number #1457's half-applied renumbering, and it must keep being reported.

Rejected: the enclosing symbol resolved at both revisions. It needs a Rust item parser inside a script whose whole design is dependency-free and language-agnostic (it resolves .md targets too, which have no symbols at all), it is heuristic by construction, and it still cannot separate two citations that point inside the same function — which is the case the issue itself names as having no symbol to cite. Text equality across two revisions is a fact; an enclosing-construct resolver would be a guess with a parser in front of it.

What the script now says about its own limits

The two residuals are printed, not left in the issue tracker. Verbatim, from the report:

Each is declined on EVIDENCE, not on a guess: the text that number held at the base
is cited again at a number this changeset introduced, at least as many times as the
base document named it, so the claim moved and the number was spent on something
else. Without this the correct citation is reported as drift and no edit to the
document removes the report. Two residuals stay, and both are printed rather than
silent. A base citation this changeset DELETED instead of re-anchoring leaves no
such number, so a correct citation landing on the deleted one's line is still
reported above. And a cited line carrying little text — a lone `}`, a bare `where`
— can match by coincidence, and a real drift is declined; the matched text is
quoted on each line so a reviewer can see what it was and disposition it.
A symbol has no number to reuse.

And, from the header: declining a span says the base's claim moved, never that the number the changeset wrote is a sensible place to point at. That stays --audit's question, and a symbol's. mod.rs:2152 — a number that moved between two identical lines — is out of reach of the text key for the same reason it was out of reach of the number key.

The exemption count of the 2026-09-22 addendum already exists

Checked before building anything. At 5355cec0 the unmodified script already prints the exempt count on every run that has a base. Measured here, --base 5355cec0185c07c81e2334fca73ec290749d1dae on this branch:

OK: none of the 297 cited lines compared against 5355cec0185c changed their text.
0 re-anchored spans were exempt from the comparison and never checked at all; `--show` lists them, and a compared total cannot report them.

(A zero here is the honest reading, not a missing instrument: this changeset re-anchors nothing. The same line reads 66 re-anchored spans were exempt on a branch that does — reported to me from another branch's run against the same base, not reproduced here.)

It landed in #1478 (54dcacf5, "Refs #1447"), on both report shapes — inline in the ::error:: line when something drifted, on its own line when nothing did — with --show tagging each span |re-anchored. So it is not reimplemented here. It is also genuinely tested rather than merely emitted: FIXTURE_DRIFT_EXEMPT is movable by a fixture, not only by reverting production code — adding one head-only citation to doc/keyed.md gives

FAIL self-test: 4 cited lines were exempt from the comparison as re-anchored, expected exactly 3.

What this changeset adds beside it is the second declined class, kept separate 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 rather than folded into the re-anchored count. Folding it in would have reproduced, one level down, the exact defect the addendum reported.

Before/after on a real changeset

refactor/h2-goaway-drain against its merge base 921c13673616 — a changeset that re-anchors 72 spans.

Before (origin/main's script):

::error::1 of 264 compared citations drifted since 921c13673616 (72 re-anchored spans exempt):
  lib/src/protocol/mux/LIFECYCLE.md:295: `h2.rs:5994` — lib/src/protocol/mux/h2.rs:5994 moved: was `context.unlink_stream(stream_id);`, now `// `write_streams` could run `kawa.prepare` against the converter.`

After:

OK: none of the 263 cited lines compared against 921c13673616 changed their text.
72 re-anchored spans were exempt from the comparison and never checked at all; `--show` lists them, and a compared total cannot report them.

1 cited line NOT compared because this changeset reused the number for different code (sozu-proxy/sozu#1447):
  lib/src/protocol/mux/LIFECYCLE.md:295: `h2.rs:5994` — lib/src/protocol/mux/h2.rs:5994 not compared: the base named `context.unlink_stream(stream_id);` there, and this changeset re-anchored that line to lib/src/protocol/mux/h2.rs:5955

Verified by hand, both revisions: the base document cited h2.rs:5994 for the unlink site, and context.unlink_stream(stream_id); is at 5955 at head, where this changeset cites it. The old report's was half named a claim that is alive and correct 39 lines up; the span it fired on belongs to a group the changeset rewrote wholesale (5994/6053 → 6060/5994/6012). Note what the new line does not claim: whether 5994 is a good place to point at is a separate question, and the report hands the reviewer both halves of the evidence to ask it.

It does not widen anything it should not. On 06fc2708 — the 92-span re-anchoring #1457 was measured on — the two rules report the identical six drifts and decline nothing:

::error::6 of 240 compared citations drifted since 80cd162a3334 (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 = kawa.storage.space();`

Swept over 40 merged commits and 30 local branches that touch both documents and code: one verdict changes in total. refactor/h2-stream-slots's genuine drift and pr1300's thirty are all preserved.

Red, then green

The fixture asserts the correct verdict and was seen red against the unmodified rule first.

RED A — doc/keyed.md's reused number asserted as correct, rule untouched (origin/main's script, only FIXTURE_DRIFT_EXPECTED and FIXTURE_DRIFT_COMPARED edited):

FAIL self-test: expected 4 drifted citations from the fixtures, got 5:
  doc/drift.md:11: `drift.rs:12` — drift.rs:12 moved: was `pub fn moved(&self) -> u8 {`, now `pub fn inserted(&self) -> u8 {`
  doc/drift.md:15: `drift.rs:13` — drift.rs:13 moved: was `1`, now `0`
  doc/drift.md:15: `drift.rs:8-13` — drift.rs:13 moved (end of range): was `1`, now `0`
  doc/keyed.md:16: `keyed.rs:16` — keyed.rs:16 moved: was `pub fn tail(&self) -> u8 {`, now `pub fn reused(&self) -> u8 {`
  doc/keyed.md:7: `keyed.rs:17` — keyed.rs:17 moved: was `let far = 3;`, now `2`
FAIL self-test: compared 39 cited lines against the base revision, expected exactly 38 — the scanned surface or the comparison has shrunk
EXIT=1

GREEN — the fix in place:

OK self-test: 48 fixture line citations, 38 of them compared against a base revision (3 more exempt as re-anchored, 1 declined as a reused number), 6 examined test names (4 checked), 3 pinned blocks compared …
EXIT=0

RED B — the identity reverted to the number key (moved_claims = {}):

FAIL self-test: expected 4 drifted citations from the fixtures, got 5:
  … doc/keyed.md:16: `keyed.rs:16` — keyed.rs:16 moved: was `pub fn tail(&self) -> u8 {`, now `pub fn reused(&self) -> u8 {`
FAIL self-test: compared 39 cited lines against the base revision, expected exactly 38 …
FAIL self-test: expected 1 cited line(s) declined as a reused number, got 0:
  MISSING: doc/keyed.md:16: `keyed.rs:16` — keyed.rs:16 not compared: the base named `pub fn tail(&self) -> u8 {` there, and this changeset re-anchored that line to keyed.rs:20
EXIT=1

RED C — the claim counting dropped from reanchored_claims (len(numbers) >= claimed → claimed). This is the one that matters: the exemption widens and swallows #1457's half-applied renumbering.

FAIL self-test: expected 4 drifted citations from the fixtures, got 3:
  doc/drift.md:15: `drift.rs:13` — …
  doc/drift.md:15: `drift.rs:8-13` — …
  doc/keyed.md:7: `keyed.rs:17` — …
FAIL self-test: compared 37 cited lines against the base revision, expected exactly 38 …
FAIL self-test: expected 1 cited line(s) declined as a reused number, got 2:
  doc/drift.md:11: `drift.rs:12` — drift.rs:12 not compared: the base named `pub fn moved(&self) -> u8 {` there, and this changeset re-anchored that line to drift.rs:16
  doc/keyed.md:16: `keyed.rs:16` — keyed.rs:16 not compared: the base named `pub fn tail(&self) -> u8 {` there, and this changeset re-anchored that line to keyed.rs:20
EXIT=1

doc/drift.md is that guard: its base cites drift.rs:12 twice, the head re-anchors only one of them to :16, so one claim stays unaccounted for and the span left behind is compared. Widening the exemption past its counting turns --self-test red instead of turning the rule off.

RED D — one word of the declined report's wording changed (there → here), which is why that list is pinned by exact text and not by a count:

FAIL self-test: expected 1 cited line(s) declined as a reused number, got 1:
  doc/keyed.md:16: … the base named `pub fn tail(&self) -> u8 {` here, and this changeset re-anchored …
  MISSING: doc/keyed.md:16: … the base named `pub fn tail(&self) -> u8 {` there, and this changeset re-anchored …
EXIT=1

The pre-existing shape assertions still bite, checked by perturbation rather than by assuming — the declined lines go into their own returned list precisely so REPORTED_PAIR keeps matching the drift lines. Changing the drift report's separator (, now → , and now ):

FAIL self-test: could not read the quoted pair out of the drift report 'doc/drift.md:22: `wide.md:11` — …' — its shape changed and this assertion now checks nothing
FAIL self-test: expected the drift 'doc/drift.md:11: …, now `pub fn inserted…`', got '…, and now `pub fn inserted…`'
… (4 more)

On removing an assertion

keyed.rs:16 leaves FIXTURE_DRIFT_EXPECTED, which reads like a deleted assertion and is not one: it moves into FIXTURE_DRIFT_REUSED_EXPECTED, pinned by its exact reported text, and FIXTURE_DRIFT_COMPARED drops 39 → 38 in the same direction. One pinned-defect verdict becomes one pinned-correct verdict plus a new list and a lower counter — net assertions grow, and drift.rs:12 is now the guard against widening, in this list and named in the header for it.

Verification

cargo build  --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd   -> EXIT=0  Finished `dev` profile in 31.43s
cargo +nightly fmt --all -- --check                                                            -> EXIT=0  (no output)
cargo clippy --all-targets --locked --no-default-features --features …  -- -D warnings         -> EXIT=0  Finished `dev` profile in 12.46s
cargo test -p sozu-lib  --locked --no-default-features --features …                            -> EXIT=0  ok. 5 passed; 0 failed; 5 ignored (doctests); all suites ok
cargo test -p sozu      --locked --no-default-features --features …                            -> EXIT=0  ok. 113 passed; 0 failed
cargo test -p sozu-e2e  --locked --no-default-features --features … -- --skip tests::fuzz_tests:: -> EXIT=0  ok. 447 passed; 0 failed; 4 filtered out; 375.15s
RUSTFLAGS="--cfg tokio_unstable" cargo test   -p sozu-sim --locked                             -> EXIT=0  ok. 12 + 6 + 6 + 6 passed; 0 failed
RUSTFLAGS="--cfg tokio_unstable" cargo clippy -p sozu-sim --all-targets --locked -- -D warnings-> EXIT=0  Finished `dev` profile in 0.79s
python3 .github/scripts/check_doc_citations.py --self-test                                     -> EXIT=0  OK self-test: 48 fixture line citations, 38 compared …
python3 .github/scripts/check_doc_citations.py --root .                                        -> EXIT=0  OK: all 188 citations resolve to a non-blank line
python3 .github/scripts/check_doc_citations.py --base 5355cec0185c07c81e2334fca73ec290749d1dae -> EXIT=0  OK: none of the 297 cited lines changed their text; 0 re-anchored, 0 reused
python3 .github/scripts/check_doc_citations.py --audit --root .                                -> EXIT=0
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked                         -> EXIT=0  Finished `dev` profile in 43.92s
cargo bench -p sozu-lib --bench h2_stream_table -- --test                                      -> EXIT=0  Success (every case)

cargo build is run before cargo fmt deliberately: on a fresh worktree fmt exits 1 with failed to resolve mod 'command' until the build script has generated command/src/proto/command.rs.

The first sozu-e2e run reported tests::tests::test_async and tests::tls_tests::test_wss_server_speaks_first_after_upgrade as FAILED. That was port contention, not this changeset — pgrep sozu_e2e showed a second binary holding the process-wide registry from PORT_SEARCH_START. Both passed in isolation immediately afterwards, and the full suite is the green line above, re-run with pgrep sozu_e2e | wc -l at 0 and the 1-minute load below 8. This changeset contains zero .rs files, so the test binaries are byte-identical to 5355cec0.

Scope

.github/scripts/check_doc_citations.py, .github/scripts/testdata/citations/doc/keyed.md (one sentence of fixture prose that asserted the old verdict; its citations are unchanged, and its line numbering is preserved because doc/keyed.md:16 is pinned), doc/README.md and CHANGELOG.md. No production code, no dependency change, ci.yml untouched — its own comment says that when a rule changes, the script changes and the workflow does not.

CHANGELOG.md and doc/README.md follow the precedent every previous change to this script set: #1458, #1467, #1468, #1478, #1493 and #1495 each touched CHANGELOG.md, and all but #1467 also touched doc/README.md. The entry sits below the first entry of ### 🔄 Changed rather than at the top of the section, so it does not collide with every other open PR's entry.

One thing the gate caught on its author, worth recording: the first draft of the doc/README.md paragraph quoted the measured example as h2.rs:5994, and --root . reported it as an ambiguous unresolvable citation. Rewritten without a citation-shaped literal.

Closes #1447

…s number (#1447)

`check_doc_citations.py`'s rule 2 compares a citation this changeset did not
touch against the text it named at the base revision, and exempts one the
changeset re-anchored. That exemption asked whether the SPAN was present at the
base, and a span number is not stable under the edits the rule exists to
police. 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 as drift with no edit to the document that
removes the report. #1447 found it 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 landed the
`StreamState::Link` transition on that very line.

THE IDENTITY IS THE CITED LINE. `reanchored_claims` reads both revisions and
returns every cited line TEXT whose claim this changeset carried onto a new
number; `check_drift` declines a span whose base text is one of them, because
what the base document named at that number is alive elsewhere and the span
under test is a different citation that inherited the number rather than the
base one left behind.

NOTHING GUESSES, and two counted conditions keep it that way. A RECEIVER is
only a head-cited end whose number this document did not cite at the base at
all: a number the base already carried explains nothing, being as likely to be
a second stale citation, which is exactly what two adjacent citations do when
their file loses a line and each lands on its neighbour's old text. And the
receivers for a text must be AT LEAST AS MANY as the base citations that named
it, so a document that named one line twice and re-anchored one of the two has
left the other behind and it is still reported — which is #1457's
half-applied renumbering, and the reason the widening cannot swallow it.

Measured on `refactor/h2-goaway-drain` against `921c13673616`, which re-anchors
72 spans: the number-keyed rule reported one mux `h2.rs` citation as drift
because the base had spent that number on `context.unlink_stream(stream_id);`,
while that line is cited, correctly and by the same changeset, 39 lines
earlier. Measured on `06fc2708`, the 92-span re-anchoring #1457 was measured
on, both rules report the identical six drifts and nothing is declined: the
exemption is inert where no number was reused. Across 30 branches and 40 merged
commits it changes exactly one verdict.

DECLINED, NEVER SILENT. Every declined span is printed with the text that was
matched and the number the claim moved to, and `--show` tags it
`|reused-number`. It is a comparison the rule did not perform, so it lowers the
compared total instead of hiding inside it, and it is listed apart from the
re-anchored exempt count. Two residuals are stated in the report rather than
left to the issue tracker: a base citation this changeset DELETED instead of
re-anchoring leaves no receiver, so a correct citation landing on its line is
still reported; and a cited line carrying little text, a lone `}` or a bare
`where`, can match by coincidence and decline a real drift, with the matched
text on screen so a reviewer sees it for what it is. Declining a span says the
base's claim moved, never that the number the changeset wrote is a sensible
place to point at; that stays `--audit`'s question, and a symbol's.

`doc/keyed.md`'s reused number moves out of FIXTURE_DRIFT_EXPECTED into the new
FIXTURE_DRIFT_REUSED_EXPECTED, pinned by its exact reported text rather than by
a count: an exemption a reviewer cannot read is a heuristic with no audit
trail, and a build that stopped naming the matched text would emit the same
count. FIXTURE_DRIFT_COMPARED drops 39 -> 38 in the same direction, because a
declined span is one fewer comparison. `doc/drift.md` is the guard from the
other side and keeps `drift.rs:12` in FIXTURE_DRIFT_EXPECTED: its base cites
that span twice and the head re-anchors only one of them.

Seen red four ways, each change reverted alone against `--self-test`:

    A  fixture verdict flipped, rule unmodified
       expected 4 drifted citations from the fixtures, got 5
       compared 39 cited lines against the base revision, expected exactly 38
    B  identity reverted to the number key
       expected 1 cited line(s) declined as a reused number, got 0
    C  claim counting dropped from reanchored_claims
       expected 1 cited line(s) declined as a reused number, got 2
         (drift.rs:12 swallowed — #1457's half-applied renumbering)
    D  one word of the declined report's wording changed
       MISSING: doc/keyed.md:16: `keyed.rs:16` — ... the base named ... there

The header section is retitled and rewritten, `doc/README.md`'s drift chapter
with it. No production code changes.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 7208c74 into main Sep 25, 2026
28 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the fix/citation-drift-identity branch September 25, 2026 11:17
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.

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

1 participant