Skip to content

fix(gateway,client): size a verified raw blob, and adopt the size open's pull - #2646

Merged
thiras merged 2 commits into
mainfrom
fix/gateway-raw-blob-size
Oct 27, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/gateway-raw-blob-size

Conversation

@thiras

@thiras thiras commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What

Two gateway follow-ups from #2593.

Part of #2616
Closes #2633

#2616 (part): a raw blob the gateway verified answers with its length, HEAD and Range

  • A raw blob (GET /<hash> on the bare host, /_decdn/<hash> on a site) gets Content-Length and Accept-Ranges once a whole pull on the gateway has verified its size. The size comes from the fetch host's SizeHints, read through a new worker request, Request::Size / PullWorker::size, which takes no pull slot.
  • With that size the blob takes one Range (206, or 416 past the end), is refused with 402 before its pull when it does not fit the allowance, and its pull is capped at that size, as a sized entry's is.
  • The empty root answers empty with no pull.
  • HEAD on a raw blob answers from the verified size with no pull. HEAD /_decdn/<hash> on a site used to be read as an entry of the site's own bundle and answered 404. It now answers as the bare host does, and HEAD of a bundle or an entry under /_decdn/ redirects to its site.
  • What gateway: raw-blob Content-Length, HEAD and Range from the first node's size claim #2616 asked for and this does not do. The issue asked for the length to come from the first node's size claim. Review showed that is unsafe:
    • The server stops reading a body at its Content-Length. A claim below the real size would cap the pull there, and the verified prefix would end as a whole 200 or 206. The client keeps a cut file and sees no error.
    • A claim above the real size wrongly gives a 402 or 416.
    • The first request for a raw blob therefore still streams with no length. gateway: prove a raw blob's size before its first byte, so its first request has a length #2645 tracks proving the size before the first byte, from the final chunk (ADR 039).

#2633: a download adopts the pull it opened for the size

  • LaneSources lanes are wrapped in PrimedSource. With no size hint (the peer-store fast path, or a pinned node whose probe gave no size), the whole-blob open that reads the signed size primes its pull on the lane instead of dropping it after the node has written up to a credit window.
  • A download's first leg on that lane is the same align_range(0, 0, total), so the drive adopts the pull and the holder writes the blob's wire bytes once.
  • The pull is primed for the lane's next open alone (PrimedSource::prime_next). Any other first leg (a streamed window, a resumed gap) closes it before opening its own pull, so the node never holds the floor it reserved for the pull beside the replacement leg (review: Copilot). The node's prime keeps its semantics.
  • Streamed fetches (WindowPacer) do not adopt it yet: client: a streamed fetch with no size hint still drops the pull it opened for the size #2644.

Docs: adr/appendix-gateway.md (§ Payment and allowance, § Ranges), ADR 039 (first size claim), the gateway, worker, allowance, fetch.rs and lane_sources.rs docs, and the CHANGELOG.

Reviewer notes

  • Read Gateway::blob / blob_size / head_blob in crates/cli/src/commands/gateway.rs, then open_for_header in crates/client/src/lane_sources.rs.
  • A first cut took the size from a probe (an unsigned hint) through a ProbeOpts::sized flag. A multi-agent review found the truncation hole above, and an unbounded probe round per anonymous HEAD, so that cut was dropped. crates/client/src/targets.rs is unchanged.
  • The primed pull's adoption depends on the answering lane being alone in the download's first planned batch. It connects with no network work, so it is. If another lane lands in that batch, the range is split, the pull is not adopted, and the cost is what it was before this PR.
  • The TypeScript SDK's fake gateway still gives a raw blob no length. No contract test observes it, and the SDK refuses a range on a blob client-side. The fake gateway update goes in a follow-up sdk-typescript PR.

Verification

  • pre-commit run --all-files: passed. The cargo-deny advisories it prints come from the existing lockfile and only warn.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo fmt -- --check, CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items, and make -C adr check-refs: all exit 0.
  • cargo nextest run --workspace: 5939 passed.
  • Anvil e2e: gateway_public, gateway_pointer, gateway_concurrent_pulls and peer_store_probeless passed.
    • gateway_public now checks that a raw blob's first response has no length, then a HEAD with the length and a Range window of the verified blob, and adds that window's wire bytes to the node's served-bytes check.
    • peer_store_probeless now checks that its fast-path download probes nothing and that the three holders write the blob's wire bytes once, within 16 KiB.
  • SDK contract (gateway_sdk) at the pinned .github/sdk-typescript.sha: passed on both the public and the loopback gateway.
  • driver::tests::a_pull_primed_for_the_next_open_closes_before_another_range_opens: a primed pull is closed before a leg of another range opens.
  • Mutation checks, one at a time:
    • With the size lookup returning nothing, 4 of the new gateway tests fail.
    • With the primed pull dropped instead, peer_store_probeless fails: "the holders wrote 397220 bytes for a 198610-byte pull".
    • With the prime_next close removed, the driver test above fails.

🤖 Generated with Claude Code

…n's pull

- #2616 (part): a raw blob that a whole pull on the gateway verified
  answers with Content-Length, Accept-Ranges, HEAD and one Range (206/416),
  and is refused with 402 before its pull when it does not fit the
  allowance; its pull is capped at that size. The size comes from the
  fetch host's SizeHints through a new worker request (Request::Size, no
  pull slot); the empty root is empty with no pull. A node's size claim
  never gives a length: the server stops reading a body at its
  Content-Length, so an understated claim would end a short pull as a
  whole response. The first request still streams unsized (#2645).
- HEAD /_decdn/<hash> on a site answers as the bare host does instead of
  404, and HEAD of a bundle or entry under /_decdn/ redirects to its site.
- #2633: LaneSources lanes are PrimedSource-wrapped, and the whole-blob
  open that learns the first size claim primes its pull on the lane, so a
  download's first leg adopts it instead of the holder writing the bytes
  twice. Streamed fetches still drop it (#2644).
- Tests: gateway raw-blob length/range/402/HEAD/empty-root tests, a worker
  size-lookup test, a downloader adoption test, gateway_public checks an
  unsized first response then HEAD and a range of the verified blob, and
  peer_store_probeless checks a fast-path download probes nothing and the
  holders write its wire bytes once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras thiras self-assigned this Oct 27, 2026
Copilot AI balanced review requested due to automatic review settings October 27, 2026 19:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An incompatible primed pull retains unpaid credit reservations that can block an otherwise affordable replacement leg.

1 open issue
What changed in this PR

This PR adds size-aware raw-blob responses to the gateway after a whole pull verifies the blob’s size, and reuses the client’s size-discovery pull for matching downloads.

Changes:

  • Adds verified-size lookup, raw-blob length and range support, and corrected site HEAD routing.
  • Primes whole-blob pulls for adoption by a download’s first matching leg.
  • Adds regression coverage and documents the remaining first-request and streamed-fetch limitations.
File Description
crates/​e2e/​tests/​peer_store_probeless.rs Checks probe-free downloads and avoids duplicate served bytes.
crates/​e2e/​tests/​gateway_public.rs Tests verified raw-blob length and range responses.
crates/​client/​src/​lane_sources.rs Primes size-discovery pulls for download reuse.
crates/​client/​src/​downloader/​tests.rs Tests adoption of a primed whole-blob pull.
crates/​client/​src/​bundle/​engine.rs Clarifies size-discovery comments.
crates/​cli/​src/​commands/​gateway/​worker/​tests.rs Tests size lookup without a pull slot.
crates/​cli/​src/​commands/​gateway/​worker.rs Exposes verified sizes through worker requests.
crates/​cli/​src/​commands/​gateway/​tests.rs Covers sized blobs, allowance rejection, site HEAD, and empty blobs.
crates/​cli/​src/​commands/​gateway/​allowance.rs Documents admission using verified blob sizes.
crates/​cli/​src/​commands/​gateway.rs Adds size-aware blob handling and site HEAD routing.
crates/​cli/​src/​commands/​fetch.rs Exposes verified sizes and clarifies size-discovery docs.
CHANGELOG.md Records gateway and client fixes and limitations.
adr/​appendix-gateway.md Documents verified-size responses and range behavior.
adr/​039-multi-source-parallel-fetch.md Documents size-pull retention and adoption.

Review effort: Balanced

Comment thread crates/client/src/lane_sources.rs Resolved
@github-code-quality

github-code-quality Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main bce8e64 fix/gateway-raw-blob... d09cc3f +/-
77% 77% 0%
View coverage of the 6 most impacted files.
File main bce8e64 fix/gateway-raw-blob... d09cc3f +/-
crates/cli/src/...teway/worker.rs 84% 83% -1%
crates/client/s...lane_sources.rs 40% 39% -1%
crates/cli/src/...ands/gateway.rs 79% 79% 0%
crates/client/src/scheduler.rs 94% 94% 0%
crates/cli/src/...mmands/fetch.rs 49% 49% 0%
crates/client/src/source.rs 93% 94% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 27, 2026 19:45 UTC

…ange

The pull LaneSources keeps from the whole-blob size open held its floor
reservation on the node while a first leg of another range (a streamed
window, a resumed gap) opened beside it, so a pool or signer with room for
one floor could refuse that leg. PrimedSource::prime_next parks a pull for
the next open alone: an open of exactly its range adopts it, any other
open closes it before the wrapped source opens. The node's prime is
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 59bbb52 into main Oct 27, 2026
37 checks passed
@thiras
thiras deleted the fix/gateway-raw-blob-size branch October 27, 2026 19:46
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.

client: the peer-store fast path still takes its first size claim from a stream it drops unread

2 participants