Repository navigation
refactor(node): extract FrameQueue/FrameChunks so the serve framers stop hand-maintaining the byte-count invariant (#1834) - #1888
Merged
Conversation
…top hand-maintaining the byte-count invariant (#1834) Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR refactors the node’s serve-path framing logic by extracting the shared “queued Bytes + running byte count” bookkeeping into FrameQueue/FrameChunks in handlers/client/wire.rs, so the frame byte-count invariant is enforced structurally rather than by duplicated runtime checks in both serve framers (cache-hit ChunkFramer and cache-miss CoherentFrameProducer).
Changes:
- Introduces
FrameQueue(owningVecDeque<Bytes>plusqueued) andFrameChunks(payload slices plus computedtotal) and moves frame-cutting logic onto the type. - Updates both serve framers and their call sites to pass around
FrameChunksinstead of(Vec<Bytes>, usize)and removes now-redundant invariant guards. - Adjusts
chunk_frame_bufsand related tests to rely on the new construction invariants.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/node/src/handlers/client/wire.rs | Adds FrameQueue/FrameChunks, refactors frame cutting and buffer assembly to rely on construction invariants, updates unit tests accordingly. |
| crates/node/src/handlers/client/serve_leg.rs | Switches serve loop framing from (Vec<Bytes>, usize) to FrameChunks and uses FrameChunks::total() for billing/accounting. |
| crates/node/src/handlers/client/serve_encoder.rs | Replaces manual VecDeque + queued bookkeeping with FrameQueue, updates framing APIs/tests to use FrameChunks. |
| crates/node/src/handlers/client/delivery.rs | Replaces manual VecDeque + queued bookkeeping with FrameQueue, updates framing APIs/call sites/tests to use FrameChunks. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 82.40% (was 82.40%, ● 0.00%) — 69557/84415 lines
History
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1834.
Both serve framers —
ChunkFramer(cache-hit leg,delivery.rs) andCoherentFrameProducer(cache-miss leg,serve_encoder.rs) — held identical byte-queue state (queue: VecDeque<Bytes>+queued: usize) and maintained its invariants by hand, with the free functionwire::drain_frameholding the seam open via two&mutout-params that had to move in lockstep. These are money-carrying invariants: a desync yieldsOk(None), which the serve loop reads asdone_delivering→StreamEndover a truncated blob, with the client paying the closing voucher.This extracts the shared state into two types in
wire.rs, so the byte-count invariant is held by construction rather than by prose + runtime checks. Per #1834 this is the "refactor second" half of harden-first-refactor-second; it deletes the very guards #1828's follow-up added, which is why the two could not land together.New types
FrameQueue { queue, queued }—new/push/len/clear/cut(is_emptyis test-only).pushdrops emptyBytes, soqueued == 0iff the queue is empty by construction — the desync the framers guarded by hand is unrepresentable.cutisdrain_frame's body moved onto the type, returningOption<FrameChunks>;Noneonly on an empty queue.FrameChunks { chunks, total }— private constructor; onlycutbuilds it, computingtotalfrom the same items it moves intochunks. A frame whose header would misdeclare its own bytes cannot be built.What it deletes (each now unrepresentable)
if len > 0filters (now insideFrameQueue::push).drain_frame'sfront_len == 0branch.chunk_frame_bufs— the empty-payload guard and theactual != total_lensum check.checked_subandqueue.is_empty()guards from the perf(node,protocol): zero-copy ChunkData framing via vectored QUIC writes (#1791) #1828 follow-up.Out of scope (per issue)
faulted/hashstay duplicated in each producer (the two faults are semantically different; terminal-poison is a producer property, not a byte-queue one).frame_target→NonZeroUsize(its own commit) — thetarget == 0guards stay in bothnext_frame_chunks.Verification
cargo fmt -- --check— cleancargo build/cargo clippy --all-targets— no warningscargo nextest run -p decdn-node— 1058 passed, 0 failedNet: 4 files, +329 / −358.
🤖 Generated with Claude Code