Skip to content

proto(client): ChunkData frames become sender's choice — drop the 1 KiB CHUNK_SIZE chop, bound only by the 16 MiB framing cap #1796

Closed

Description

@alpergundogdu

Refines #1791 item 1. Instead of replacing the 1 KiB frame size with another fixed number, ChunkData becomes variable-size, sender's choice, bounded above only by the framing layer.

Current state

  • CHUNK_SIZE = 1024 (crates/protocol/src/client.rs:49) is the exact payload size of every ChunkData except the final one. The sender re-chops the bao export at it (ChunkFramer, crates/node/src/handlers/client/delivery.rs:63-113); the receiver rejects anything larger at decode (ChunkData::new → MessageValidationError::ChunkTooLarge, the only constructor, gated via TryFrom<ChunkDataWire>).
  • The constant's stated rationale — "matches iroh-blobs' internal 1024-byte chunk granularity" — is vestigial since ADR 038: the payload is the bao interleaved verified stream, framing boundaries are explicitly independent of chunk-group boundaries, the codec is the sole verifier, and delivery.rs:26 notes the 16 KiB chunk group does not line up with CHUNK_SIZE. The alignment buys nothing; it forces 1,024 frames (and their per-frame validate/copy/encode/write costs) per MiB served — comically small against multi-hundred-GB transfer targets.

Decision

  • Payload bounds: 1.. at the protocol level. ChunkData::new keeps only the non-empty check (the ADR 005 §Non-empty chunk progress invariant is unchanged and load-bearing). MessageValidationError::ChunkTooLarge is deleted; the effective ceiling is the framing layer's MAX_MESSAGE_SIZE (16 MiB, crates/protocol/src/framing.rs:32), enforced where it already is.
  • Frame size is sender policy, not protocol. In practice frames stay well under the payment cadence: CHUNK_BYTES (1 MiB) is the proof interval, and delivery is paced by the credit window — a not-yet-ramped lane's window is one chunk, so a sender naturally sizes frames at or below the window remaining. The serving node picks a target coalescing size locally (the ChunkFramer threshold becomes a node-local constant rather than a wire constant); nothing is negotiated and nothing new travels the wire.
  • Receiver is size-agnostic. Payment (cumulative byte counter crossing CHUNK_BYTES boundaries), verification (bao decoder fed from the reassembled stream), and the partial-final-chunk rule all generalize: "the final chunk MAY be smaller" dissolves into "every frame carries 1.. bytes, sender's choice".
  • Known trade-off, accepted: whole-frame inactivity stall detection gets coarser as frames get larger; that detector is too crude regardless of this change and is tracked separately (see the byte-progress stall-detection issue, linked below once filed).

Work

  1. crates/protocol: relax ChunkData::new/validate to non-empty only; delete CHUNK_SIZE and ChunkTooLarge; update the struct/constructor docs and the discriminant/bounds tests.
  2. crates/node: ChunkFramer coalesces to a node-local target size and emits whole buffers (no split cap); the equivalent miss-path frame production in serve_encoder/serve_leg follows the same rule.
  3. crates/client-pull: remove the CHUNK_SIZE assumptions in comments/logic (lib.rs:2150, :2585); confirm the receive path is size-agnostic.
  4. Tests that chop wire bytes at CHUNK_SIZE switch to a local helper constant (any size is now a valid sender choice).
  5. ADR 005: rewrite the cdn/client/v1 diagram note ("1024-byte chunks"), §Partial final chunk, and the Tradeoffs line about the 1024-byte granularity; state that framing is sender's choice, independent of verification and payment boundaries, bounded by the message-size cap. ADR 038's wire-format wording is checked for consistency.

Pre-launch wire policy applies (CLAUDE.md): in-place change, both sides in the same PR, no compatibility shim — after first deployment this same change is a Tier-3 ALPN bump, which is why it lands now.

Related: #1791 (items 1–2), #1788.

Activity

  1. alpergundogdu commented on Aug 24, 2026

    @alpergundogdu
    ContributorAuthor

    Decision on the node-local sender policy (work item 2): the default coalescing target is 1 MiB — matching CHUNK_BYTES, the payment cadence — with the effective frame size naturally smaller whenever the credit-window remaining is smaller (an unramped lane's window is one chunk, so early frames are window-sized). The target is node configuration, not a wire constant; nothing is negotiated.


    Generated by Claude Code

  2. alpergundogdu commented on Aug 24, 2026

    @alpergundogdu
    ContributorAuthor

    Implementation note from a pre-work read-through: there are two frame producers to change, not one.

    • Hit path: ChunkFramer (crates/node/src/handlers/client/delivery.rs:36, cut at CHUNK_SIZE in next_frame, :88-112).
    • Miss path: CoherentFrameProducer::next_frame (crates/node/src/handlers/client/serve_encoder.rs:286-305), which re-cuts the coherent bao encode's channel output at CHUNK_SIZE the same way.

    Both should coalesce to the same node-local 1 MiB default (clamped by credit-window remaining). The receive side (crates/client-pull/src/lib.rs:2147-2169) is already size-agnostic — it only counts cumulative wire bytes against the promised total — so the client needs comment updates only, as the work list assumes.


    Generated by Claude Code

  3. self-assigned this
    on Aug 24, 2026
  4. moved this from Backlog to In progress in deCDNon Aug 24, 2026
  5. moved this from In progress to Done in deCDNon Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions