Skip to content

docs: cite Rust code by symbol instead of by line number - #1480

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/rust-comment-citations
Sep 23, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/rust-comment-citations

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

file:line citations written inside Rust comments drift with no signal — the CI gate reads only doc/** and **/LIFECYCLE.md. #1473 framed the fix as a genuine fork: extend the gate to **/*.rs, or stop writing line numbers in Rust comments and cite the symbol instead. This measures the population and takes the second.

Comment-only: zero non-comment .rs lines changed. sozu-lib 1092, unchanged.

The measurement that decided it

90 file:line citation tokens in Rust comments, across 29 files, naming 113 line targets.

had drifted from the text they named 68 of 90
broke on the very next commit touching the target file 43 of those 68
median survival 1 commit, 0 days
wrong within a week 65 of 68
all h2.rs:NNN tokens in the tree 18 of 18 drifted
still defensible today 16 of 90

Two caveats so those numbers are not misread: 22 were unchanged since written, which is not the same as correct — three were } else {, ); and }; from birth. "Defensible" means intact and not landing on a bare delimiter, blank line, or past EOF.

The number that killed "extend the gate": the deduped day-one failure set is 70 of 90 (78%) — 68 drifted, 14 naming an ambiguous basename (four files are h2.rs, nineteen are mod.rs), 2 pointing into the kawa dependency, 1 blank target. Turning on a check that fails 78 of every 100 citations on its first run produces a gate people bypass rather than satisfy, which the script's own header already argues in another context.

A one-commit half-life is not a maintenance problem to tighten. It is a form that does not work.

Not a new convention — an existing one, extended

doc/README.md already documents this, and its first rule is exactly symbol citation. It was simply scoped to "these documents". So the change is the scope, not the rule: the convention now covers Rust comments, with the measurements recorded under #citing-code-from-a-rust-comment, the rule alone in CLAUDE.md as a pointer rather than a restated copy, and a CHANGELOG.md entry under Changed.

82 of 90 converted, across 25 files. Each was re-pointed at the symbol recovered by reading the target at the commit that wrote the citation, not at HEAD — for two-thirds of them HEAD is a different construct entirely.

The conflict resolution is the argument for this change

This branch conflicted with #1477 in e2e/src/tests/h2_priority_rearm_tests.rs. #1477's side was pure line arithmetic (mod.rs:1402-1423 → :1403-1424), derived from the cited line's text — the technique this repository rightly prefers.

Both of its renumbered citations are wrong by about 880 lines. mod.rs:1403-1424 sits in ready_inner (starts 1349); the real timeout path is Mux::timeout_inner (1997), with the timeout_backend trace at 2154 and the should_write drain loop at 2282-2283.

This is not #1477's error. The citation had already drifted into ready_inner by 19fd5d8c, and self.context.now = Instant::now(); is a duplicated idiom present in both ready_inner's and timeout_inner's loops — so tracking the text faithfully landed on the wrong copy. That is doc/README.md's own #1437 lesson reproduced: a re-anchor preserves the pointer, not the claim.

My own symbol was imperfect too: SessionState::timeout was correct at the commit that wrote the citation, but the body has since split into a wrapper at 1079 and Mux::timeout_inner at 1997. Resolved to Mux::timeout_inner for all three — strictly better than either side, and verified to hold both claims at 04fade63.

doc/testing.md auto-merged, which is where a convergence trap would hide, so it was read rather than trusted: #1477's h2.rs:5403 → :5401 on line 676 and two symbol conversions on 680-682, different lines in the same paragraph. Correct.

Two semantic corrections, not re-pointing

Worth a reviewer's eye, because these change what the comment says:

  • h2_log_context_tests.rs named log_context_lite! for a line inside log_module_context!. Only the latter renders the bare MUX-H2 tag with no session block, which is what the comment claims.
  • e2e/src/tests/mod.rs named two tests by a line holding their #[serial_test::serial] attribute rather than the test.

What is deliberately left

8 sites under lib/src/protocol/mux/, because that directory is being rewritten by the write-path inversion (#1479) and converting them now would conflict. Ready-to-paste replacements are recorded for the follow-up.

Two of those are the one principled exception in the whole population: stream.rs's citations into a pinned kawa version. A line number into a pinned dependency cannot drift, and both are correct today.

A gate rule rejecting PATH:[0-9]+ in *.rs comments belongs in check_doc_citations.py, which #1478 is currently changing. It would start green outside mux/ at this HEAD. Sequenced after both land rather than written here as a parallel script.

Verified

cargo +nightly fmt --all -- --check                     -> exit 0
cargo build --locked --no-default-features ...          -> exit 0
cargo test -p sozu-lib ...                              -> 1092 passed; 0 failed
check_doc_citations.py --root .                         -> exit 0, 211 citations, 500 test names
check_doc_citations.py --base 04fade63                  -> exit 0, none of 326 cited lines changed
non-comment +/- lines in the committed .rs diff         -> 0

The gate caught one of my own mistakes mid-work: rewrapping shifted lines in h2_correctness_tests.rs, and --base flagged two doc/testing.md citations pointing into it — the guarded half of exactly the pair #1465 was about. Fixed by naming the two tests.

One item stays unverified and is stated rather than glossed: fuzz/fuzz_targets/fuzz_command_channel.rs is comment-edited, but fuzz is a separate workspace, so neither the battery nor cargo fmt --all reaches it. rustfmt --check exits 1 on that file byte-identically on the pre-change baseline (an import-ordering artifact in a use block untouched here), which proves it still parses; with zero non-comment lines changed, a comment-only edit that parses cannot alter compilation. To close it fully: cd fuzz && cargo +nightly fuzz build fuzz_command_channel.

Refs #1473

`check_doc_citations.py` resolves `doc/**` and `**/LIFECYCLE.md`, so a
`path.rs:NNN` inside a `//`, `///` or `//!` comment was read by no rule at
all — not the existence floor, not the drift comparison, not once. The two
`SAFETY:` comments justifying `from_utf8_unchecked` in `lib/src/http.rs`
and `lib/src/https.rs` are how it surfaced (#1473): both cited a `Method`
match arm for `hostname_and_port`, and drifted there with CI green
throughout, until #1474 re-pointed them at the function.

The population was measured before the form was chosen, at main `19fd5d8c`:
90 citation tokens across 29 files, holding 113 line targets. Sixty-eight
of the 90 had drifted from the text they named at the commit that last
wrote or re-anchored them, and only 16 still land on a line that is neither
a bare delimiter, a blank, nor past end-of-file. The half-life decided it:
43 of those 68 broke on the very NEXT commit that touched the file they
point into, the median citation survived ONE such commit and zero days, and
65 of 68 were wrong inside a week. All 18 `h2.rs:NNN` tokens had drifted.

Extending the resolver over `**/*.rs` was the alternative, and it was
measured rather than argued: switched on at that revision it would have had
to reject those 68, plus 14 naming a basename that is ambiguous here — four
files are called `h2.rs`, nineteen `mod.rs` — plus two pointing into the
`kawa` dependency, which is not in this repository. A gate that fails on
most of the population it guards gets bypassed rather than satisfied, which
is the argument the script's own header makes about `--all-features`.

So `doc/README.md`'s three forms now govern Rust comments too, with one
narrowing: the symbol form only, and a comment that means one branch names
that branch in words. All 82 citations outside `lib/src/protocol/mux/` are
converted, across 25 files, each re-pointed at the symbol recovered by
reading the cited file AT THE COMMIT THAT WROTE THE CITATION rather than at
HEAD. The rule is also in `CLAUDE.md`'s code-style list.

Rewrapping the comments shifted lines in `e2e/src/tests/h2_correctness_tests.rs`,
and the drift rule caught two `doc/testing.md` citations pointing into it —
the guarded half of exactly the pair #1465 was about. They now name
`try_h2_large_gzipped_chunked_drains_fully` and
`try_h2_large_chunked_7mb_drains_fully`.

Two corrections fell out of recovering intent rather than trusting HEAD:
`h2_log_context_tests.rs` named `log_context_lite!` for a line that is
inside `log_module_context!` — only the latter renders the bare `MUX-H2`
tag the comment claims — and `e2e/src/tests/mod.rs` named two tests by a
line holding their `#[serial_test::serial]` attribute.

Comments and documentation only; no code, literal, attribute, assertion or
test name changed. The eight sites under `lib/src/protocol/mux/` are left
for a separate pass to keep this off a module under concurrent change; two
of them, into pinned `kawa` 0.7.1, are the one class here where a line
number genuinely cannot rot.

Refs #1473

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.

1 participant