Skip to content

docs(mux,udp): re-anchor citations that drifted off their code - #1399

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/stale-doc-citations
Sep 21, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/stale-doc-citations

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Repairs every file.rs:NNN citation in lib/src/protocol/mux/LIFECYCLE.md and lib/src/protocol/udp/LIFECYCLE.md that no longer names the code it claims, and corrects one section whose prose is false rather than merely misnumbered.

How this surfaced

PR #1372 is a Dependabot actions bump that touches no documentation at all. That is exactly what made it able to see this: its merge base is b51d9f9a (2026-09-20), and check_drift only compares a citation whose (path, spans) pair is unchanged since the base (.github/scripts/check_doc_citations.py:456-470). A pull request that edits these files re-anchors their citations, which removes them from comparison. #1372 edits nothing, so nothing was excluded, and it reported 9 drifted citations on a changeset that contains none of the code involved.

The drift rule itself only landed today in 07ad3037, and the doc-citations job one day earlier in 21296c0b, so these citations went stale before any run could compare them.

Two kinds of defect

Stale line numbers (the large majority, ~70 citations). Each named a real construct but the number had drifted as later commits shifted the target. Renumbered against origin/main at 610eaa04. Representative:

citation was now
MAX_LOOP_ITERATIONS backstop mod.rs:1216 mod.rs:1762
counter declaration above both ready_inner loops mod.rs:793 mod.rs:1335
once-per-outer-pass clock sample mod.rs:841 mod.rs:1383
top-of-Mux::timeout clock sample mod.rs:1430 mod.rs:1965
top-of-Mux::shutting_down clock sample mod.rs:1929 mod.rs:2338
Context.now field declaration mod.rs:465 mod.rs:523
armed_deadline clear-before-reschedule manager.rs:534 manager.rs:535

Note mod.rs:465 and mod.rs:1430 were not among the 9 CI reported: both were added after b51d9f9a, so the rule treated them as deliberately re-anchored and skipped them. They were wrong anyway. manager.rs:534 was an off-by-one that predates the recent churn entirely.

The symbol form was not substituted here. In each case the prose already names the symbol separately and the line number pins one specific statement among several uses of it — four distinct self.context.now writes, two distinct MAX_LOOP_ITERATIONS comparisons — which is the case doc/README.md reserves line citations for.

A false claim, not a stale number. Sections 4.1 and 5.4 asserted that handle_continuation_header_state, cancel_timed_out_streams, handle_rst_stream_frame, handle_goaway_frame and end_stream perform self.streams.remove(...) inline instead of routing through ConnectionH2::remove_dead_stream, and instructed reviewers to apply its two invalidation checks by hand at each. That is no longer true:

$ grep -n "streams\.remove(" lib/src/protocol/mux/h2.rs
3695:        if self.streams.remove(&stream_id).is_none() {

One occurrence, inside remove_dead_stream itself (fn remove_dead_stream at h2.rs:3694). All five named sites now call the helper, several carrying a comment that cites this LIFECYCLE section by name as the reason. Renumbering them would have re-anchored a false statement onto correct-looking targets — which is how it survived: PR #1397 shifted these citations mechanically by +42 to track its own insertion, carrying the wrong claim forward intact.

Both sections are rewritten. The "inline, unsafe" list is gone because nothing is left to list, the five sites moved into the "routes through the helper" list with fresh citations, and the close backend-teardown exception is kept and renumbered because that half is still true — it never removed at all.

One further miss, caught by a second check

Section 8 cited mod.rs:1473 for "Mux::timeout inspects each stream's state". That line is a push_event(EventKind::BackendUp) inside ready_inner. The inspection the sentence describes is match self.context.streams[stream_id].state at mod.rs:2018, whose arms are exactly the 408/503/504, forcefully-terminate and keep-draining outcomes the prose lists. Corrected.

It escaped both the --base comparison and a symbol sweep because the doc line names Mux::timeout while the citation must point inside timeout_inner — so a plain "is the cited line inside the named function" test cannot separate a correct delegation citation from a wrong one. Mux::ready, Mux::timeout and Mux::shutting_down all delegate to an _inner function, and five other citations legitimately rely on that.

Verification

$ python3 .github/scripts/check_doc_citations.py --self-test
OK self-test: 19 fixture line citations, 17 of them compared against a base revision, ...
exit=0

$ python3 .github/scripts/check_doc_citations.py
OK: all 219 `file.rs:NNN` citations in doc/ and **/LIFECYCLE.md resolve to a non-blank line.
OK: all 304 cited test names (from 3673 candidate identifiers) name a `fn` in the tree.
exit=0

$ python3 .github/scripts/check_doc_citations.py --base b51d9f9a10f5956f17237497900caa49e63f9a4a
OK: none of the 47 cited lines compared against b51d9f9a10f5 changed their text.
exit=0

Seen red before the fix, on the same command that CI runs:

$ git checkout origin/main -- lib/src/protocol/mux/LIFECYCLE.md lib/src/protocol/udp/LIFECYCLE.md
$ python3 .github/scripts/check_doc_citations.py --base b51d9f9a10f5956f17237497900caa49e63f9a4a
::error::7 of 54 compared citations drifted since b51d9f9a10f5:
exit=1

(7 rather than the 9 CI reported: PR #1397 had already renumbered the two h2.rs:4571 citations, dropping them out of the comparison.)

Documentation only — no code, no dependency, no test change. check_doc_citations.py is untouched and no citation was deleted to silence a failure.

Unblocks the Doc citations job on #1372.

check_doc_citations.py --base b51d9f9 (PR #1372's
merge base, a Dependabot actions bump that touches no doc file) reported 9 of 56
compared citations drifted. Sweeping every remaining `file.rs:NNN` citation in
both files against origin/main at 610eaa0 found roughly 60 more that the base
comparison structurally cannot see, because the checker only compares a citation
whose (path, line) pair is unchanged since the base -- and a prior PR (#1397,
merged after this fix started) mechanically renumbered many h2.rs citations to
track a 200+-line insertion without checking whether they pointed at the right
place first. A renumbered-but-still-wrong citation drops out of every future
--base comparison forever.

STALE LINE NUMBERS (the large majority): each of these named a real construct
correctly but the number had drifted, usually because later commits shifted the
target file. Renumbered to the current line. Symbol form was not substituted
because in every case the prose already names the symbol separately (e.g.
"MAX_LOOP_ITERATIONS (mod.rs)") and the line number pins a *specific statement*
among several uses of that same symbol (e.g. two separate MAX_LOOP_ITERATIONS
comparisons, four separate self.context.now writes, many remove_dead_stream
call sites) -- exactly the case doc/README.md's citation-form rule reserves for
line citations, since no symbol names "this one occurrence" more precisely than
a line does. Representative fixes: the MAX_LOOP_ITERATIONS backstop check
(mod.rs:1216 -> 1762), the `counter` declaration above both ready_inner loops
(mod.rs:793 -> 1335), the once-per-outer-pass and top-of-Mux::timeout clock
samples (mod.rs:841 -> 1383, mod.rs:1430 -> 1965), the top-of-shutting_down
sample (mod.rs:1929 -> 2338), frontend-HUP detection and the two
MuxResult::CloseSession sites (mod.rs:795/860/1183 -> 1337/1402/1729), every
StreamState::Link/Unlinked/Recycle transition site in h1.rs/h2.rs/answers.rs,
the backend attach/detach citations (Router::connect, Context::link_stream,
Context::unlink_stream), the Recycle-slot pool-clear/metrics-reset/search
citations in Context::create_stream, the ConnectionH2.now mirror-assignment
sites in readable/writable/cancel_timed_out_streams/start_stream, the
outbound-byte and fc-stall-arm liveness refreshes in write_streams, the
SETTINGS-ACK-timeout checks in readable and flush_pending_control_frames, the
graceful-GOAWAY call chain (Mux::shutting_down -> graceful_goaway -> goaway),
the backend-timeout action arm in Mux::timeout, and the flood-window /
back-pressure-window fail-closed citations. udp/LIFECYCLE.md needed exactly the
one CI-reported fix: armed_deadline's clear-before-reschedule statement
(manager.rs:534 -> 535); the file was otherwise untouched by any PR since the
merge base and every other citation in it still resolves correctly.

A GENUINE PROSE ERROR, not a stale line number: section 4.1 and section 5.4 of
mux/LIFECYCLE.md asserted that `handle_continuation_header_state`,
`cancel_timed_out_streams`, `handle_rst_stream_frame`, `handle_goaway_frame`
and `end_stream` perform `self.streams.remove(...)` inline instead of routing
through the canonical `ConnectionH2::remove_dead_stream` helper, and told
reviewers to apply its two invalidation checks (`expect_write`, `expect_read`)
by hand at each one. That claim is now false: `self.streams.remove(` occurs
exactly once in the whole of h2.rs, inside `remove_dead_stream` itself, and
all five sites this section named as unsafe now call the helper -- several
with a comment explicitly citing this LIFECYCLE.md section by name as the
reason. Renumbering any of the five citations would have re-anchored them onto
correct-looking but misleading targets, since the code they used to point at
no longer exists as a distinct inline removal. Rewrote both sections instead:
the "inline" call-site list is gone (there is nothing left to list), the five
sites moved into the "goes through remove_dead_stream" list with fresh
citations, and the prose now states plainly that the helper is the only
removal path and performs both invalidation checks internally. The `close`
backend-stream-teardown exception (which never removed at all) is kept and
renumbered, since that half of the claim is still true.

One citation the sweep missed, found by a separate check: section 8's frontend
timeout handling cited `mod.rs:1473` for "`Mux::timeout` inspects each stream's
state". That line is a `push_event(EventKind::BackendUp)` inside `ready_inner`,
unrelated to timeouts. The state inspection the sentence describes is the
`match self.context.streams[stream_id].state` at mod.rs:2018, whose arms are
exactly the 408/503/504, forcefully-terminate and keep-draining outcomes the
prose lists. Corrected to mod.rs:2018. It escaped both the --base comparison
and the symbol sweep because the doc line names `Mux::timeout` while the
citation must point inside `timeout_inner`, so a naive "is the cited line
inside the named function" test cannot distinguish a correct delegation
citation from a wrong one.

Verified locally against origin/main at 610eaa0 (this task's second base;
PR #1397 landed mid-task and required a full rebase and re-verification of
every previously-computed line number):
  python3 .github/scripts/check_doc_citations.py --self-test          # exit 0
  python3 .github/scripts/check_doc_citations.py                      # exit 0
  python3 .github/scripts/check_doc_citations.py --base b51d9f9
    # red before this commit (matching the 9 CI-reported citations, minus the
    # 2 that PR #1397's mechanical renumbering had already dropped out of
    # comparison -- 7/54 reported at 610eaa0), green after (0/47 drifted)

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 2032383 into main Sep 21, 2026
24 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the fix/stale-doc-citations branch September 21, 2026 12:07
pull Bot pushed a commit to jrcribb/sozu that referenced this pull request Sep 21, 2026
The ignore rule's comment claimed a Rust version that existed would have
silently raised the MSRV. Verified against the actual job log for
`cargo audit` (run 35588449699): `dtolnay/rust-toolchain` runs
`rustup default <ref>` and exports no `RUSTUP_TOOLCHAIN`, so the
`rust-toolchain` directory override still pins cargo to 1.93.1 for any
work inside this checkout. The real exposure is narrower and worth
naming precisely: the steps that build outside the checkout — the
lagging_server and bench_logger clones and `cargo install cargo-audit`
— take the default toolchain, and the release build's own comment
promises it matches the pinned MSRV.

The reason to ignore the dependency is unchanged; only the description
of the damage was wrong, and a wrong claim left in a comment is the
failure mode sozu-proxy#1399 just finished repairing elsewhere in this tree.

Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS added a commit that referenced this pull request Sep 22, 2026
Move the wire StreamId -> GlobalStreamId map, highest_peer_stream_id,
expect_read/expect_write, rst_sent, and the per-stream
activity/flow-control-stall caches into lib/src/protocol/mux/h2_stream_table.rs,
behind the same closed-API shape hpack_state.rs and h2_flow_control.rs
established in the two prior extraction steps. ConnectionH2 keeps a single
private stream_table: H2StreamTable field.

create_stream, start_stream, remove_dead_stream and refuse_stream_and_discard
stay on ConnectionH2 (they orchestrate Context, logging, metrics, the RFC 9218
prioriser and readiness, none of which the new module has), but their
stream-table bookkeeping now delegates to H2StreamTable's narrow API.
H2StreamTable::remove is the sole removal chokepoint, including the
expect_read/expect_write gid invalidation LIFECYCLE.md SS5.4 documents;
streams is now a private field of h2_stream_table.rs, so
self.streams.remove(...) cannot be written from h2.rs any more, which was
verified by temporarily reintroducing an inline removal and observing
E0609 (reverted). This makes SS5.4's "no call site removes inline anymore"
claim compiler-enforced instead of prose that can silently go stale, which
already happened to it once (#1399). On this branch the claim
was independently verified true before the move too: self.streams.remove
occurred at exactly one call site, inside remove_dead_stream itself, so no
parallel removal site needed eliminating here.

Determinism fix: H2StreamTable::collect_timed_out (the reap-candidate union
cancel_timed_out_streams drives) used to read stream_last_activity_at and
stream_fc_stalled_since as plain HashMaps with `for (&k, &v) in map` loops,
so which of several simultaneously-timed-out streams got RST_STREAM'd first
was non-deterministic across process restarts -- the same class of leak
issue #1338 decided to close, and the same fix step 2 already applied to
pending_window_updates. That order flows onto the wire: collect_timed_out's
returned order is the order cancel_timed_out_streams calls enqueue_rst in,
which pushes onto pending_rst_streams, drained in push order. Both maps are
now BTreeMap (stream_fc_stalled_progress converts alongside
stream_fc_stalled_since since the two are documented as kept in lockstep),
so collect_timed_out walks each guard group in ascending StreamId order.
Every other iteration over the wire map itself was enumerated by reading
(not only grepping for .iter()/.keys()/.values()/.drain(), which misses a
`for (&k, &v) in &map` site) and found not to leak: the priority scheduler's
HashMap-order keys() feed is immediately sorted by (urgency, *id), a total
order; the GOAWAY retry loop and close()'s backend-teardown loop only affect
scheduling order, not the bytes of a fixed frame set; and GOAWAY's own
last_stream_id is the incrementally-updated highest_peer_stream_id scalar.

H2StreamTable carries debug_assert! pre/post-conditions on every mutating
method plus a check_invariants() sweep, matching h2_flow_control::H2FlowControl
and protocol::udp::manager::UdpManager. router.rs reaches the wire-map length
through a new ConnectionH2::stream_count() accessor, the sole external reader
now that the field is private.

LIFECYCLE.md citations are re-anchored by content throughout; doc/h2_mux_internals.md,
doc/lifetime_of_a_session.md and doc/testing.md follow.

Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS added a commit that referenced this pull request Sep 22, 2026
Move the wire StreamId -> GlobalStreamId map, highest_peer_stream_id,
expect_read/expect_write, rst_sent, and the per-stream
activity/flow-control-stall caches into lib/src/protocol/mux/h2_stream_table.rs,
behind the same closed-API shape hpack_state.rs and h2_flow_control.rs
established in the two prior extraction steps. ConnectionH2 keeps a single
private stream_table: H2StreamTable field.

create_stream, start_stream, remove_dead_stream and refuse_stream_and_discard
stay on ConnectionH2 (they orchestrate Context, logging, metrics, the RFC 9218
prioriser and readiness, none of which the new module has), but their
stream-table bookkeeping now delegates to H2StreamTable's narrow API.
H2StreamTable::remove is the sole removal chokepoint, including the
expect_read/expect_write gid invalidation LIFECYCLE.md SS5.4 documents;
streams is now a private field of h2_stream_table.rs, so
self.streams.remove(...) cannot be written from h2.rs any more, which was
verified by temporarily reintroducing an inline removal and observing
E0609 (reverted). This makes SS5.4's "no call site removes inline anymore"
claim compiler-enforced instead of prose that can silently go stale, which
already happened to it once (#1399). On this branch the claim
was independently verified true before the move too: self.streams.remove
occurred at exactly one call site, inside remove_dead_stream itself, so no
parallel removal site needed eliminating here.

Determinism fix: H2StreamTable::collect_timed_out (the reap-candidate union
cancel_timed_out_streams drives) used to read stream_last_activity_at and
stream_fc_stalled_since as plain HashMaps with `for (&k, &v) in map` loops,
so which of several simultaneously-timed-out streams got RST_STREAM'd first
was non-deterministic across process restarts -- the same class of leak
issue #1338 decided to close, and the same fix step 2 already applied to
pending_window_updates. That order flows onto the wire: collect_timed_out's
returned order is the order cancel_timed_out_streams calls enqueue_rst in,
which pushes onto pending_rst_streams, drained in push order. Both maps are
now BTreeMap (stream_fc_stalled_progress converts alongside
stream_fc_stalled_since since the two are documented as kept in lockstep),
so collect_timed_out walks each guard group in ascending StreamId order.
Every other iteration over the wire map itself was enumerated by reading
(not only grepping for .iter()/.keys()/.values()/.drain(), which misses a
`for (&k, &v) in &map` site) and found not to leak: the priority scheduler's
HashMap-order keys() feed is immediately sorted by (urgency, *id), a total
order; the GOAWAY retry loop and close()'s backend-teardown loop only affect
scheduling order, not the bytes of a fixed frame set; and GOAWAY's own
last_stream_id is the incrementally-updated highest_peer_stream_id scalar.

H2StreamTable carries debug_assert! pre/post-conditions on every mutating
method plus a check_invariants() sweep, matching h2_flow_control::H2FlowControl
and protocol::udp::manager::UdpManager. router.rs reaches the wire-map length
through a new ConnectionH2::stream_count() accessor, the sole external reader
now that the field is private.

LIFECYCLE.md citations are re-anchored by content throughout; doc/h2_mux_internals.md,
doc/lifetime_of_a_session.md and doc/testing.md follow.

Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS added a commit that referenced this pull request Sep 22, 2026
Move the wire StreamId -> GlobalStreamId map, highest_peer_stream_id,
expect_read/expect_write, rst_sent, and the per-stream
activity/flow-control-stall caches into lib/src/protocol/mux/h2_stream_table.rs,
behind the same closed-API shape hpack_state.rs and h2_flow_control.rs
established in the two prior extraction steps. ConnectionH2 keeps a single
private stream_table: H2StreamTable field.

create_stream, start_stream, remove_dead_stream and refuse_stream_and_discard
stay on ConnectionH2 (they orchestrate Context, logging, metrics, the RFC 9218
prioriser and readiness, none of which the new module has), but their
stream-table bookkeeping now delegates to H2StreamTable's narrow API.
H2StreamTable::remove is the sole removal chokepoint, including the
expect_read/expect_write gid invalidation LIFECYCLE.md SS5.4 documents;
streams is now a private field of h2_stream_table.rs, so
self.streams.remove(...) cannot be written from h2.rs any more, which was
verified by temporarily reintroducing an inline removal and observing
E0609 (reverted). This makes SS5.4's "no call site removes inline anymore"
claim compiler-enforced instead of prose that can silently go stale, which
already happened to it once (#1399). On this branch the claim
was independently verified true before the move too: self.streams.remove
occurred at exactly one call site, inside remove_dead_stream itself, so no
parallel removal site needed eliminating here.

Determinism fix: H2StreamTable::collect_timed_out (the reap-candidate union
cancel_timed_out_streams drives) used to read stream_last_activity_at and
stream_fc_stalled_since as plain HashMaps with `for (&k, &v) in map` loops,
so which of several simultaneously-timed-out streams got RST_STREAM'd first
was non-deterministic across process restarts -- the same class of leak
issue #1338 decided to close, and the same fix step 2 already applied to
pending_window_updates. That order flows onto the wire: collect_timed_out's
returned order is the order cancel_timed_out_streams calls enqueue_rst in,
which pushes onto pending_rst_streams, drained in push order. Both maps are
now BTreeMap (stream_fc_stalled_progress converts alongside
stream_fc_stalled_since since the two are documented as kept in lockstep),
so collect_timed_out walks each guard group in ascending StreamId order.
Every other iteration over the wire map itself was enumerated by reading
(not only grepping for .iter()/.keys()/.values()/.drain(), which misses a
`for (&k, &v) in &map` site) and found not to leak: the priority scheduler's
HashMap-order keys() feed is immediately sorted by (urgency, *id), a total
order; the GOAWAY retry loop and close()'s backend-teardown loop only affect
scheduling order, not the bytes of a fixed frame set; and GOAWAY's own
last_stream_id is the incrementally-updated highest_peer_stream_id scalar.

H2StreamTable carries debug_assert! pre/post-conditions on every mutating
method plus a check_invariants() sweep, matching h2_flow_control::H2FlowControl
and protocol::udp::manager::UdpManager. router.rs reaches the wire-map length
through a new ConnectionH2::stream_count() accessor, the sole external reader
now that the field is private.

LIFECYCLE.md citations are re-anchored by content throughout; doc/h2_mux_internals.md,
doc/lifetime_of_a_session.md and doc/testing.md follow.

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