Skip to content

fix(node,protocol): close the #1828 review findings on the zero-copy frame path - #1835

Merged
thiras merged 4 commits into
mainfrom
fix/1828-followup-zero-copy-frame-review
Aug 26, 2026
Merged

thiras merged 4 commits into
mainfrom
fix/1828-followup-zero-copy-frame-review

Conversation

@yigitdot

Copy link
Copy Markdown
Contributor

Continues #1828 (merged as 9595aee5), which moved the cdn/client/v1 serve hot path from "encode a ChunkData frame into one contiguous buffer" to "encode a ≤9-byte header on the stack + vectored QUIC write of reference-counted Bytes".

A multi-agent review of that PR after merge found no correctness bug — byte accounting, the credit-window bound, faulted terminality, the metering split, and cancel-safety all hold, and the perf claim is real end to end (quinn_proto::SendBuffer::write moves each Bytes into unacked_segments without copying). What it did find was docs that no longer describe the code, refusals nobody can observe, and the absence of any test for the property the change exists for. No wire change; no behaviour change on any reachable path.

docs — correct stale and misattributed docs (ba2a2626)

  • The new zero-target test was inserted between a_mid_export_fault_propagates's doc block and its fn, so the fault test read as undocumented and the zero-target test opened with a summary about a fault it does not exercise. Re-attached.
  • Four comments claimed frame_target "floors at one bao chunk group". It does not — only its room term does, and payment.frame_target_bytes may be as low as 1, which yields frame_target == 1. They now state what actually makes a zero target unreachable: it never returns zero.
  • A comment still named the removed buf field; two docstrings carried changelog voice ("no longer"); one test justified itself by a caller (encode_chunk_frame from the delivery loop) that no longer exists; "coalesces" survived in the protocol crate after being fixed in the node crate.
  • Both framers now document what the returned usize is — it is simultaneously what the header declares to the client and what the serve loop bills for — and CoherentFrameProducer::next_frame_chunks gains the # Errors section its cache-hit twin already had.

fix — surface serve-path framing faults to operators (888759d5)

Every accounting refusal on this path was correct and silent: the delivery aborts without StreamEnd, so the client neither receives a mislabelled frame nor pays the closing voucher, and the only trace was a debug! in the dispatch sink — below the project's default RUST_LOG=info. To an operator that reads as a client that hung up.

  • tracing::error! with the hash at each framing refusal.
  • CoherentFrameProducer gains the hash field its cache-hit twin already carried, so its encode fault logs the same way. Previously the miss leg's fault was strictly less observable than the hit leg's.
  • New FrameAccountingFault marker carries the cause, so both serve loops meter decdn_serve_frame_accounting_fault_total without misfiling a store fault or a peer disconnect as a node bug. Documented in adr/appendix-observability.md as a latent-bug report — alert on > 0.

fix — make impossible framing states loud rather than silent (28259046)

Each is unreachable today; each degrades the wrong way if that stops being true.

  • write_varint_u32 dropped its length prefix to zero bytes and returned Ok, after which write_frame wrote the payload anyway — a frame with no prefix, desyncing the peer's stream and the cumulative wire-byte count vouchers are paid against, silently on both sides. Of the three encode_varint_u32 callers it was the only one that degraded instead of erroring. encode_varint_u32 no longer counts a byte it did not write.
  • pump() dropped the encode future on both success and fault, so the terminal state was enforced only by its caller remembering to set faulted. It poisons itself now. A closed channel under a live encoder is a contradiction, not end-of-range.
  • Both Ok(None) doors — the ones that tell the serve loops the blob is complete — now rest on the queue rather than only on its counter, and drain_frame uses checked_sub so a desync cannot clamp that counter to zero.
  • ChunkTooLarge's field is now frame_len: it is always larger than the payload_len the caller passed, and reading it as one is exactly what confused review on perf(node,protocol): zero-copy ChunkData framing via vectored QUIC writes (#1791) #1828. write_chunk_bufs takes its buffers by value, since write_all_chunks empties them.

test — pin the zero-copy shape (f068d2c8)

Nothing asserted the property the whole change exists for. Every framer test routed through the coalescing test shims, and the drain_frame test compared total against a sum of the same lengths total was built from — a tautology. A drain_frame rewritten to concatenate passed the entire suite.

Now the chunk counts are asserted at both framers and at drain_frame, plus the boundary cases the shape can break on: a frame ending exactly on an item boundary, a target past everything queued, and an under-counting queued. Verified by falsification — a coalescing drain_frame fails five of them.

Also: the cache-hit fault test now matches its coherent twin (refusal by name, queue cleared); encode_chunk_frame's ADR 013 ceiling is pinned, since that is the door an out-of-tree caller reaches; and the miss leg's only large blob gets a position-varying fill, because a constant one compares equal under a within-frame permutation.

Verification

  • cargo clippy --workspace --all-targets -- -D warnings clean
  • cargo nextest run --workspace — 3046 passed, 0 failed
  • cargo test -p decdn-node --test client_loopback 110 pass; --test node_to_node_pull_through 4 pass
  • cargo fmt -- --check, cargo doc --no-deps --workspace, markdownlint clean
  • Public-API snapshot diff is exactly the len → frame_len rename, nothing else

Out of scope

Two issues filed rather than bundled here:

🤖 Generated with Claude Code

yigitdot and others added 4 commits August 26, 2026 10:20
…-copy frame path

The mid-export-fault test's doc block sat above the zero-target test inserted
in front of it, so the fault test read as undocumented and the zero-target test
opened with a summary about a fault it does not exercise. Re-attach it.

`frame_target` does not floor at one bao chunk group — only its room term does,
and `payment.frame_target_bytes` may be as low as 1. State what actually makes a
zero target unreachable: `frame_target` never returns zero.

Name the queue where a comment still named the removed `buf`, cut the two
changelog-voice phrasings, drop the claim that the delivery loop calls
`encode_chunk_frame`, and say what the returned byte count is on both framers.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Every accounting refusal on the serve path was correct and silent. The delivery
aborts without `StreamEnd`, the client neither receives a mislabelled frame nor
pays the closing voucher — and the only trace is a `debug!` in the dispatch sink,
below the default `RUST_LOG=info`. To an operator that reads as a client that
hung up.

Give the four framing refusals a `tracing::error!` with the hash, give
`CoherentFrameProducer` the `hash` field its cache-hit twin already carries so its
encode fault logs the same way, and carry the cause as `FrameAccountingFault` so
both serve loops can meter `decdn_serve_frame_accounting_fault_total` without
misfiling a store fault or a peer disconnect as a node bug.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ilent

Each of these is unreachable today. Each also degrades the wrong way if that ever
stops being true, and the failures they guard are the ones nobody would find.

`write_varint_u32` dropped its length prefix to zero bytes and returned `Ok`, after
which `write_frame` wrote the payload anyway — a frame with no prefix, desyncing
the peer's stream and the cumulative wire-byte count vouchers are paid against,
silently on both sides. `encode_varint_u32` now stops rather than counting a byte
it did not write, and the prefix write refuses a short buffer.

`pump` dropped the encode future on both success and fault, so the terminal state
was enforced only by its caller remembering to set `faulted`; it poisons itself
now. A closed channel under a live encoder is a contradiction, not end-of-range.

Both `Ok(None)` doors — the one that tells the serve loop the blob is complete —
now rest on the queue, not only on its counter, and `drain_frame` uses
`checked_sub` so a desync cannot clamp that counter to zero.

Also: `ChunkTooLarge`'s field is `frame_len`, since it is always larger than the
`payload_len` the caller passed and reading it as one is what confused review; and
`write_chunk_bufs` takes its buffers by value, since `write_all_chunks` empties
them and nothing has a use for what is left.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…, and the encode ceiling

Nothing asserted the property the whole change exists for. Every framer test
routed through the coalescing test shims, and the `drain_frame` test compared
`total` against a sum of the same lengths `total` was built from — a tautology. A
`drain_frame` rewritten to concatenate passed the entire suite.

Assert the chunk counts instead, at both framers and at `drain_frame`, and cover
the boundary cases the shape can break on: a frame ending exactly on an item
boundary, a target past everything queued, and an under-counting `queued` that
must not be clamped to zero. Verified by falsification — a coalescing
`drain_frame` now fails five of them.

Also bring the cache-hit fault test up to its coherent twin, which already
asserted the refusal is the poison guard's and that the queue was cleared; pin
`encode_chunk_frame`'s ADR 013 ceiling, which is the door an out-of-tree caller
reaches; and give the miss leg's only large blob a position-varying fill, since a
constant one compares equal under a within-frame permutation.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 82.00% (was 82.01%, ▼ 0.02%) — 68305/83299 lines

File Coverage Lines Δ
crates/node/src/handlers/client/delivery.rs 93.65% 339/362 ▼ 2.37%
crates/node/src/handlers/client/serve_encoder.rs 88.84% 398/448 ▼ 0.93%
crates/node/src/handlers/client/serve_leg.rs 83.98% 152/181 ▼ 0.59%
crates/node/src/handlers/client/wire.rs 95.72% 358/374 ▼ 1.33%
crates/node/src/metrics.rs 94.51% 860/910 ● 0.00%
crates/protocol/src/client.rs 97.56% 1079/1106 ▼ 1.14%
crates/protocol/src/framing.rs 97.49% 388/398 ▼ 1.25%
crates/protocol/src/message.rs 99.64% 275/276 ● 0.00%
History
Commit Total Δ vs base
f068d2c (HEAD) 82.00% ▼ 0.02%

@thiras
thiras merged commit 99a2e64 into main Aug 26, 2026
71 of 75 checks passed
@thiras
thiras deleted the fix/1828-followup-zero-copy-frame-review branch August 26, 2026 08:13
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.

2 participants