Skip to content

docs(mux): complete the module layout and stop stating line counts (#1520) - #1522

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
docs/mux-module-layout
Sep 25, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
docs/mux-module-layout

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1520.

Which option, and why

Option 1 — keep the module list and the descriptions, delete every parenthesised
count and the total, and let the wc -l sentence the block already carried be the whole
answer.

What moved me was not that the numbers were wrong — that is repairable — but what they
turned out to be measuring. h2.rs is stated at 7562 and is 15360; its #[cfg(test)] mod tests opens at line 7784, so 7577 of those 15360 lines — just under half the file — are
its own test module. The
number a reader takes as "how much implementation is in here" was, for the largest module
in the directory, mostly a test suite. A count that has to be explained before it can be
read is not carrying information the list needs, and the list is not the place to explain
it. Meanwhile the column the block exists for — what each file is for — is the one thing
wc -l cannot print, and it is also the one that had rotted furthest: thirteen modules had
no row at all, and four of the six clauses describing h2.rs named code that now lives in
sibling files.

The argument against option 2, stated fairly. Line counts are a crude "where is the
complexity" signal, and a newcomer does want one; deleting them removes it. That is real,
and it is why the wc -l sentence stays rather than going with them — the signal is
available live, one command, already printed in the document.

What tips it is the cost of the gate. The only gate that reads these documents is
.github/scripts/check_doc_citations.py, so a count check is a new gate whose sole job
is to guard an ornament. It would fire on nearly every changeset that touches
lib/src/protocol/mux/, and that is measurable: git log -40 --format='%H' 5355cec0 -- lib/src/protocol/mux/ | wc -l returns 40 of the last 40 commits on main. Its fix is
always the same mechanical "re-run wc -l and paste", which is drift maintenance dressed up
as a check. And it would not have caught what
actually went wrong here: a module with no row at all passes a count check trivially,
because a row that does not exist has no number to compare.

What neither option fixes, said out loud. Whoever adds a module still has to remember
to add its row. That is the obligation that actually rotted — thirteen times — and no gate
enforces it in either design. It is now written into the block itself rather than left
implicit. The check that would pay is a membership comparison between the rows and
lib/src/protocol/mux/*.rs: it fires only on an add, a remove or a rename, and its fix is
exactly the thing a reader needs written. I have deliberately not built it here — it is a
CI change, #1447 is open on that script, and it deserves its own review rather than riding
in on a documentation fix.

Before / after

Measured on this branch's base 5355cec0 with wc -l lib/src/protocol/mux/*.rs, so a
reviewer can re-run it rather than take my word.

The thirteen rows that existed

module block stated tree holds delta description
mod.rs 1818 3986 +2168 corrected — claimed Stream and Router, which are stream.rs and router.rs
h1.rs 823 1212 +389 sharpened — names ConnectionH1's single active stream
h2.rs 7562 15360 +7798 corrected — see below
parser.rs 2246 2481 +235 unchanged, verified
serializer.rs 557 615 +58 corrected — it also emits PING and WINDOW_UPDATE, and the frame header
converter.rs 1410 1798 +388 extended — the HEADERS/CONTINUATION split (RFC 9113 §6.10)
pkawa.rs 2229 2917 +688 unchanged, verified
connection.rs 578 732 +154 corrected — "connection types and bookkeeping" is the Connection enum and the two Endpoint adaptors
router.rs 678 2192 +1514 sharpened
stream.rs 290 1274 +984 extended — StreamState, StreamParts, the bounded replay capture
answers.rs 302 443 +141 sharpened — it materialises an answer into the stream's kawa buffers
shared.rs 93 646 +553 corrected — "Cross-connection shared state" holds no state; it is four helpers and an enum shared by the two write paths
debug.rs 80 80 same corrected — "Diagnostic helpers" is a bounded event ring that is a no-op without debug_assertions
stated total 18 666 across 13 43 092 across 26 +24 426

debug.rs is right by coincidence, and the coincidence is checkable: the file was created
at 11fa65c3 (2026-04-15) and 7ff6b8b2 (2026-04-26) wrote the number, so
git log 7ff6b8b2..5355cec0 -- lib/src/protocol/mux/debug.rs returns nothing — it has not
been touched since.

h2.rs's description read "state machine, flow control, flood detection, RFC 9218
priorities, shutdown handling". The issue named two of those as stale; four are, for
the same reason — flow control is h2_flow_control.rs, flood detection is
h2_flood_detector.rs, the RFC 9218 priorities are h2_scheduler.rs, and shutdown
handling is h2_close.rs/h2_drain.rs. ConnectionH2 still holds those states, but as
named fields of those types, and the row now says what is left in the file itself: frame
dispatch, settings and connection state, and the edge-trigger discipline the module doc
calls itself the canonical home of.

The thirteen rows that were missing

Each description is read off the module — its //! header where that header is still
accurate, and its item inventory where it is not.

module tree holds description written
auth.rs 383 HTTP Basic auth: header extraction, SHA-256 canonicalisation, constant-time comparison
buffer_source.rs 164 BufferSource trait and PoolBufferSource: where the core takes its buffers, and that a source may refuse
h2_close.rs 951 Whether a connection may close or must keep draining under TLS backpressure
h2_control_tx.rs 871 Proxy-emitted RST_STREAM queue and its lifetime cap
h2_drain.rs 534 RFC 9113 §6.8 double-GOAWAY drain state and transitions
h2_flood_detector.rs 1768 Flood thresholds and counters: Rapid Reset, CONTINUATION flood, MadeYouReset, PING/SETTINGS/empty-DATA rates
h2_flow_control.rs 668 Connection-level (stream 0) send window, receive accounting, queued WINDOW_UPDATEs
h2_header_reassembly.rs 280 Owned accumulator for an in-progress HEADERS + CONTINUATION field block
h2_scheduler.rs 1914 RFC 9218 priorities: which stream writes next, and whether it may interleave
h2_stream_table.rs 766 Wire StreamId → GlobalStreamId map, RST dedupe, per-stream liveness and stall caches
h2_transmit.rs 554 Vectored gather/confirm of one stream's pending output
h2_write_pass.rs 346 Owned state and phase of one write_streams pass
hpack_state.rs 157 Connection HPACK codec pair (RFC 7541) and its reusable scratch buffers

No description is a guess. Where a module resisted one line I took the narrowest true
statement rather than padding it: h2_control_tx.rs says "its lifetime cap" instead of
naming the CVE, because the row is not the place to argue which of three mitigations that
cap belongs to, and the module doc does that at length.

The rows are verified against the tree as a set — 26 rows, 26 files, no extras, no
duplicates — rather than by eye.

doc/ sweep

grep -rnE '\([0-9]{2,5} lines\)' doc/ returns 13 hits, all in the block above. That was
the starting point; I also swept [0-9]+ lines in any form, [0-9]+ (modules|files|tests| crates|…), tree glyphs (├──/└──) across every file under doc/, and bullet lists of
*.rs filenames.

hit disposition
doc/architecture.md:301-315 — thirteen (N lines) updated — deleted
doc/architecture.md:318 — "Total: 18 666 lines of Rust across 13 modules" updated — deleted, and deliberately not replaced with "26 modules", which is the same class of unre-derived number
doc/architecture.md:85 — backends: HashMap<Token, Connection<TcpStream>> updated — the field is BTreeMap<Token, Connection<SessionTcpStream>>. It became a BTreeMap in #1500 precisely so that which backend serves a request stops depending on per-HashMap RandomState seeding, so "HashMap" there contradicted the guarantee that change exists to provide
doc/architecture.md:80-95 — rest of the Mux session diagram unaffected — checked field by field: frontend: Connection<FrontRustls>, streams: Vec<Stream>, buffers: Box<dyn BufferSource>, listener: Rc<RefCell<L>> all match mod.rs's Context declaration
doc/README.md:97 — "a range that drifts 46 lines" unaffected — a measurement of #1335's audit, pinned to that PR; historical, nothing re-derives it because nothing should
doc/README.md:112 — "90 citation tokens across 25 files, 113 line targets, 68 drifted" unaffected — the sentence says "Measured at main 19fd5d8c"; pinned
doc/README.md:171 — "48 code spans here begin with a colon and 45 are…", "lists that run 15, 16 and 101 lines" unaffected but flagged — this is the same class (a live measurement of the tree with no SHA pin). It is rule-design rationale for check_doc_citations.py, which #1447 has open and this branch must not touch. Left for whoever lands that
doc/README.md:263 — "grew editor.rs by 21 lines… moved 24 citations, reported 2" unaffected — pinned to #1389
doc/README.md:542 — "195 citations across 190 files and 50 pre-existing failures" unaffected — the sentence says "measured on 265d895d"; pinned
doc/benchmark.md:64 — "8 lines of javascript" unaffected — describes an external tutorial's sample, not this tree
doc/h2_mux_internals.md:1111 — "once that queue holds 200 entries" unaffected — verified: MAX_PENDING_RST_STREAMS: usize = 200 in h2_control_tx.rs, and the prose names that constant in the same sentence, so the number has a named source a reader can follow
doc/h2_mux_internals.md:1298 — "LIFECYCLE.md invariant 25" unaffected — an invariant's identity, not a count
doc/testing.md:97 — the e2e module list unaffected — self-declaredly partial: it delegates to e2e/src/tests/mod.rs "for the full module list" and ends in an ellipsis
doc/testing.md:537,541 — udp_simulation.rs / tcp_preread_sim.rs unaffected — prose about two named simulators inside a recipe, not an inventory claiming completeness
doc/health_checks.md:145-148 — box-drawing glyphs unaffected — a rendered CLI table sample

Found outside doc/, deliberately not fixed here

  • lib/src/protocol/mux/LIFECYCLE.md §1.1 "Module layout" carries the same defect in
    its other half: its table names 11 of the 26 modules across 9 rows and omits 15,
    including every extracted h2_* except h2_scheduler.rs. It states no counts, so
    doc/architecture.md hardcodes mux line counts that nothing checks: 12 of 13 wrong, 13 modules missing, total off by 24k lines #1520's specific defect is absent, and it is outside the swept tree. It is also a
    guarded document carrying 108 resolved citations of its own, so completing it means
    moving those spans — a citation-remap changeset rather than a table edit. Worth its own
    issue.
  • h2.rs's and mod.rs's own //! headers have rotted the same way the block had.
    h2.rs:3-6 still says it owns "HPACK encoder/decoder, peer settings, flow window" —
    it holds those as hpack_state/h2_flow_control fields now — and mod.rs:8-11 lists
    Connection and Stream among its key types, which are connection.rs and
    stream.rs. Not fixed: 43 resolved citations target mux/h2.rs, so editing it moves
    spans, and a documentation-only PR is the wrong place to take that risk.
  • lib/src/protocol/kawa_h1/LIFECYCLE.md §1.2 — checked, complete (4 rows, 4 .rs
    files). Unaffected.

CHANGELOG

Entry added under ### 🐛 Fixed, following #1461 (docs(mux-h2): repoint H2DrainState field narration at h2_drain.rs), which is the nearest precedent: a documentation-only
change that corrected wrong statements and carried a CHANGELOG entry under Fixed. #1510
and #1452 are documentation-led changes that did the same. The one recent doc change that
carried no entry, #1480, was a mechanical citation-form sweep across 29 source files, which
is a different kind of thing. The entry is placed further down the section rather than at
its head, to avoid colliding with the other branches in flight.

Citation-remap evidence

doc/architecture.md contains no file.rs:NNN citation and nothing cites into it —
verified before editing and again after:

$ grep -nE '[A-Za-z0-9_/.-]+\.(rs|md|toml|py|yml):[0-9]+' doc/architecture.md   → no matches
$ python3 .github/scripts/check_doc_citations.py --show --root . | grep -c architecture.md   → 0

So the remap ledger is: 0 spans drifted, 0 remapped, 0 went exempt. That is not an
assumption — --base reports it explicitly:

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

Two-key EXEMPT audit: vacuous, because the set is empty. Audited via the script's
--show output rather than grep -c EXEMPT (the script writes "exempt" in lowercase
prose, so a naive count returns a false zero and skips the audit):
--show emits 0 lines containing the token EXEMPT, and --base independently
reports 0 re-anchored spans. Both agree, so there is no span to audit on either key
(byte-identical line text, identically-named enclosing fn). The totals are unchanged
from the pre-edit baseline on every rule: 186 citations resolved, 297 cited lines compared,
578 test names, 16 pinned blocks. The candidate-identifier count moved 5598 → 5614 (words
this PR's CHANGELOG entry adds); the checked count did not, i.e. the entry introduces no
test-name citation.

CHANGELOG.md is read only by the test-name rule, which is position-independent
(doc/README.md:542), so inserting into it moves no citation.

Verification battery

Every command below was run against the tree at 470ba2f4, exit code read directly rather
than through a pipe.

command exit result
cargo build --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd 0 Finished dev profile [unoptimized + debuginfo] target(s) in 16.56s
cargo +nightly fmt --all -- --check 0 no output (run after cargo build, and after cargo +nightly fmt --all applied — which changed nothing, no Rust was touched)
cargo clippy --all-targets --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd -- -D warnings 0 Finished dev profile … in 13.22s
cargo test -p sozu-lib --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd 0 1120 passed; 0 failed; 0 ignored (+ 1, 1, and 5 passed; 5 ignored suites)
cargo test -p sozu --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd 0 113 passed; 0 failed; 0 ignored (×2)
cargo test -p sozu-e2e --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd -- --skip tests::fuzz_tests:: 0 447 passed; 0 failed; 0 ignored; 4 filtered out; finished in 379.13s
RUSTFLAGS="--cfg tokio_unstable" cargo test -p sozu-sim --locked 0 12, 6, 6, 6 passed; 0 failed
RUSTFLAGS="--cfg tokio_unstable" cargo clippy -p sozu-sim --all-targets --locked -- -D warnings 0 Finished dev profile … in 8.56s
python3 .github/scripts/check_doc_citations.py --self-test 0 OK self-test: 48 fixture line citations, 39 … compared …
python3 .github/scripts/check_doc_citations.py --root . 0 OK: all 186 … citations … resolve to a non-blank line.
python3 .github/scripts/check_doc_citations.py --base 5355cec0185c07c81e2334fca73ec290749d1dae 0 OK: none of the 297 cited lines … changed their text. / 0 re-anchored spans were exempt
python3 .github/scripts/check_doc_citations.py --audit --root . 0 7 of 90 examined citations do not plainly match the prose citing them — advisory, pre-existing, none in a file this changeset touches (grep -c architecture.md over the audit output → 0)
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked 0 Generated target/doc/sozu/index.html and 4 other files
cargo bench -p sozu-lib --bench h2_stream_table -- --test 0 Success on every benchmark

No check was weakened, skipped, newly ignored, or given a lint escape to reach green.

Scope

Documentation only: doc/architecture.md (+73/−18) and CHANGELOG.md (+36). No
production code, test, dependency or Cargo.lock change. Does not touch
.github/scripts/check_doc_citations.py, lib/src/protocol/mux/router.rs,
lib/src/udp.rs, sim/, or the ### 🔄 Changed section head.

…1520)

doc/architecture.md's "Module layout" block is the only place under doc/
that says what each file in lib/src/protocol/mux/ is for. It listed 13 of
the directory's 26 modules and hardcoded a size beside each one.
Re-measured at 5355cec with `wc -l`, twelve of the thirteen were wrong:
h2.rs stated 7562 against 15360, router.rs 678 against 2192, stream.rs 290
against 1274, shared.rs 93 against 646. debug.rs at 80 was right only
because that file has not changed. The closing "18 666 lines of Rust across
13 modules" reads 43 092 across 26 — a total off by 24 426 lines.

Take the first of the issue's two options: keep the module list and the
descriptions, which a reader cannot cheaply re-derive, and delete every
parenthesised count and the total. The block already told the reader to run
`wc -l lib/src/protocol/mux/*.rs`; that sentence now is the whole answer
rather than a footnote to a snapshot of it.

Making the counts checkable was the alternative. The only gate that reads
these documents is .github/scripts/check_doc_citations.py, so a count check
is a new gate whose sole job is to guard an ornament; it would fire on
nearly every changeset that touches this directory, with the fix always
"re-run wc -l and paste"; and it would not have caught what actually went
wrong, which is thirteen modules with no row at all. A membership check
would catch that and would fire only on an add, a remove or a rename — it
is worth its own changeset, and is deliberately not bundled here because it
is a CI change and #1447 is open on that script. Until then the obligation
is written into the block: adding a module means adding its row, and no
gate enforces that either.

All 26 modules are now listed, in the order the file had, with the
extracted h2_* siblings and hpack_state.rs grouped under h2.rs. Every
description is read off the module it names. The two stale ones the issue
called out are corrected — mod.rs no longer claims Router and Stream, which
live in router.rs and stream.rs, and h2.rs no longer claims flood detection
or shutdown handling, which are h2_flood_detector.rs and
h2_close.rs/h2_drain.rs. Two more clauses in that same h2.rs row were stale
for the same reason and go with them: flow control is h2_flow_control.rs
and the RFC 9218 priorities are h2_scheduler.rs. Four further rows were
re-earned rather than re-typed: shared.rs held no state at all (it is four
helper functions and an enum shared by the two write paths), serializer.rs
also emits PING and WINDOW_UPDATE, connection.rs names the Connection enum
and the two Endpoint adaptors, and debug.rs is a bounded event ring that
compiles to a no-op without debug_assertions.

One further correction, found sweeping doc/ for the same defect and checked
against router.rs's own declaration: the Mux session diagram above the block
declared `backends: HashMap<Token, Connection<TcpStream>>`. The field is a
BTreeMap over SessionTcpStream. It became a BTreeMap in #1500 precisely so
that which backend serves a request stops depending on per-HashMap
RandomState seeding, so naming a HashMap there contradicted the guarantee
that change exists to provide.

Documentation only; no production code, test, dependency or Cargo.lock
change.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 36a6244 into main Sep 25, 2026
28 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the docs/mux-module-layout branch September 25, 2026 11:04
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.

doc/architecture.md hardcodes mux line counts that nothing checks: 12 of 13 wrong, 13 modules missing, total off by 24k lines

1 participant