Repository navigation
feat(cache,protocol): range origin pull-through — ADR decision + bao verify helper (#823) - #961
Conversation
…verify helper (#823) Origin-tier range pull-through so a node serves a byte range from an opaque origin (S3/R2/B2/HTTP/fs) without whole-blob egress, verifying the range against the BLAKE3 root H via a separately-published {H}.obao4 outboard. This is the origin->node complement to the node<->node bao range work in #915/ADR 038, which leaves the origin hop whole-blob. ADR amendments (the missing-decision deliverable): - ADR 037: Origin-tier pull-through subsection (ranged fetch + external outboard, self-validating against H, always-correct whole-blob fallback, origin_range_pull_enabled toggle; seed-leech caps compose unchanged). - ADR 005: StreamRequest.byte_len bounded-range field + Bounded byte ranges. - ADR 012: chunking sanctioned as the coarse answer; origin range pull is the fallback for non-chunked / sub-256-MiB precision. Code: - protocol: StreamRequest.byte_len base field (pre-testnet in-place edit) + requested_len() accessor; threaded through all construction sites. - cache::range_pull: align_range + encode_verified_range turn a raw origin range plus an untrusted outboard into a bao-encoded stream verified against H, ready for iroh-blobs import_bao_bytes. Proven end-to-end (import -> export_ranges). Remaining (next PR): Origin trait range+outboard adapters, engine pull_through wiring, voucher metering, serve path (composes with #915). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request implements bounded byte ranges and origin-tier pull-through as specified in ADR 005 and ADR 037. It introduces a new range_pull module in the cache crate to align requested ranges to chunk group boundaries and verify fetched ranges against the root hash using an untrusted outboard. The StreamRequest protocol message is updated to include byte_len. The review feedback recommends optimization improvements in encode_verified_range: passing the outboard parameter as bytes::Bytes to avoid unnecessary allocations, and pre-allocating the encoded vector capacity while safely handling potential u64 to usize conversion overflows.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
This PR introduces protocol and cache-layer primitives to support bounded byte-range requests and origin range pull-through verification using bao outboards, and records the associated architectural decision in ADRs. It lays the groundwork for fetching/verifying only the requested origin range (plus {H}.obao4) on cache miss, while keeping full integration into the origin adapters/engine as a follow-up.
Changes:
- Extend
cdn/client/v1StreamRequestwithbyte_len(0 = whole tail) plus arequested_len()helper and round-trip test. - Add
decdn_cache::range_pullwithalign_rangeandencode_verified_rangeto verify ranged origin bytes against a bao outboard and produceimport_bao_bytes-ready encoding, with end-to-end tests. - Update ADR 005/012/037 to document the bounded-range field and origin-tier ranged pull decision; plumb
byte_len: 0through existing callers/tests.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/protocol/src/client.rs | Adds StreamRequest.byte_len and a requested_len() helper + test updates. |
| crates/node/tests/node_to_node_pull_through.rs | Updates test fixtures to set byte_len: 0. |
| crates/node/tests/node_origin_pull.rs | Updates test fixtures to set byte_len: 0. |
| crates/node/tests/client_loopback.rs | Updates test fixtures to set byte_len: 0. |
| crates/client-pull/src/lib.rs | Sets byte_len: 0 for node-to-node pulls (whole-tail semantics). |
| crates/cache/src/range_pull.rs | New helper module for aligning/verifying origin ranges with bao outboards and encoding for iroh-blobs import. |
| crates/cache/src/lib.rs | Exposes the new range_pull module. |
| crates/cache/tests/range_pull.rs | New unit + end-to-end tests for align_range / encode_verified_range and partial-blob import/export. |
| crates/cache/Cargo.toml | Adds bao-tree and positioned-io deps for the verification codec. |
| Cargo.toml | Pins bao-tree / positioned-io in workspace deps. |
| Cargo.lock | Locks new dependency resolution. |
| adr/037-regional-proxy-warming.md | Records origin-tier ranged pull decision + config toggle. |
| adr/012-client.md | Documents chunking as the coarse ranged-access answer; points to origin range pull as fallback. |
| adr/005-protocol.md | Documents StreamRequest.byte_len and bounded-range semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 83.82% (was 83.79%, ▲ +0.02%) — 39482/47106 lines
History
|
… outboard, link/derive nits (#823) Code-review responses (gemini-code-assist + Copilot): - ADR 005 §Bounded byte ranges: correct the total_bytes claim. total_bytes stays the full blob size (the buyer derives remaining = total_bytes - byte_offset and the node needs it to frame bao verification); the metered byte count for a bounded request is min(byte_len, total_bytes - byte_offset). The prior "range length" wording contradicted client-pull and range_pull's own blob_size input. - ADR 037: scope the "no wire-format change" note to the #856 window-pull handler and point at the origin-tier path's optional StreamRequest.byte_len. - range_pull module doc: fix ADR link depth (../../../adr, not ../../adr) for a file under crates/cache/src. - encode_verified_range: take outboard as Bytes (avoids copying a multi-MB outboard the origin fetch already yields as Bytes) and pre-size the encoded buffer to header + fetch_len, degrading gracefully if it doesn't fit usize (no new error variant needed — fetch_len fits whenever range_data does). - tests: derive GROUP from IROH_BLOCK_SIZE instead of hard-coding 16 KiB, matching the production re-export; pass outboards as Bytes. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
… + requested_len (#823) The public-API snapshot job guards decdn-protocol's exported surface (#304). This PR intentionally adds the StreamRequest.byte_len base field and the requested_len() accessor; accept the baseline. Diff is exactly those two items (each listed twice via the decdn_protocol:: re-export) — no other surface change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…962) (#985) * feat(cache): wire range_pull helper into origin adapters and engine (#962) Wire the range-scoped origin pull-through landed as a helper in #961 (ADR 037 §Origin-tier pull-through, #823) through the Origin adapters and cache engine, so a node serving a byte range on a cache miss fetches only the requested span plus the small sibling {H}.obao4 outboard instead of the whole blob. - Origin trait: add `fetch_range(hash, OriginRangeRequest, outboard_max)` returning `OriginRangeFetch { Ranged | NotFound | Unsupported }`, with a default impl that returns `Unsupported` so custom origins degrade safely. - HTTP adapter: `Range: bytes=a-(b-1)` data GET (requires 206 + exact-length body) + a sibling `{hex}.obao4` GET; redirects stay disabled (SSRF #579). - S3 adapter: ranged `GetObject().range(...)` + sibling `{key}.obao4`; exact-length gate rejects a range-ignoring 200; refuses compressed ranges. - Filesystem adapter: seek + exact read of the span + sibling outboard file. - Engine: `pull_through_range(hash, off, len, blob_size)` verifies the untrusted span+outboard against the root H via `encode_verified_range`, imports the verified span as a PARTIAL blob via `import_bao_bytes`, and meters only the pulled bytes (span+outboard) against origin egress; walks the origin fallback chain. Adds `export_range` for the serve side. Verification is self-validating against H per the ADR: a tampered range, tampered/foreign outboard, or wrong root all fail and degrade to a whole-blob pull. Absent `{H}.obao4`, no `Range`/206, or a short/wrong-length span likewise degrade — never a correctness or availability failure. Tests: range pull served-without-whole-blob (HTTP + S3 + fs), bao verify of partial bytes, no-outboard / range-ignored / wrong-length / oversize-outboard fallbacks, out-of-bounds reject, multi-origin fallback, and the zero-len to-end path. `cargo nextest run -p decdn-cache`: 222 passed. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(cache): enforce eviction guard and bound range-pull buffering (#962) Address PR #985 review on range pull-through wiring: - engine: enforce the logical-eviction guard at the start of pull_through_range (mirrors get/populate) so an evicted (DMCA/operator takedown) hash is never re-fetched and re-cached; fail fast on a local CacheError::Store during the chain walk instead of advancing to the next origin; return an explicit error from export_range when a partial blob's size is unreportable (no silent empty range); correct the # Errors docs to match actual Unsupported-on-origin-fault behavior. - s3: stream the ranged/outboard body chunk-by-chunk via ByteStream::try_next, aborting the moment cumulative bytes exceed the cap, instead of ByteStream::collect() buffering the whole body first; fast-fail on a Content-Length that mismatches the requested span before collecting. - http: fast-fail on a 206 whose Content-Length mismatches the requested span before reading the body. - fs: check {H}.obao4 length via metadata() before read() and degrade early if it exceeds the outboard cap. Tests: range pull on an evicted hash is refused (no egress, miss counted); oversized S3 outboard degrades via the streaming abort; oversized fs outboard rejected on metadata before read. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
What & why
#823: a node filling a cache miss from an opaque origin backend (S3/R2/B2/HTTP/fs) currently pulls the whole blob even to serve a byte range, paying full origin egress for bytes the client never asked for. This is the origin→node complement to the node↔node / node↔client bao range work in #915 / ADR 038 — which explicitly leaves the origin hop whole-blob. No code-surface overlap with #915.
This PR lands the decision (the issue's
missing-decision/adr-reviewlabels) plus the load-bearing, novel code, with the larger adapter/engine integration sequenced as a follow-up.Approach
When the origin publishes the blob's pre-order bao outboard at a sibling key
{H}.obao4, the node fetches only[a, b)+ the small outboard (~0.4% of blob size) and verifies the range against the rootHit already wants — self-validating: a tampered range, a tampered/foreign outboard, or a wrong root all fail (anchored toH, which the node supplies, not the origin). Absent outboard / noRangesupport degrades to the existing whole-blob pull, which is never a correctness or availability failure.Contents
origin_range_pull_enabledparam + acceptance criterion; caps compose unchanged), 005 (StreamRequest.byte_len+ §Bounded byte ranges), 012 (chunking sanctioned as the coarse answer; origin range pull is the fallback for non-chunked / sub-256-MiB).StreamRequest.byte_lenbase field (pre-testnet in-place edit) +requested_len()accessor.align_range+encode_verified_range— turn a raw origin range + untrusted outboard into a bao-encoded stream verified againstH, ready for iroh-blobsimport_bao_bytes. Proven end-to-end (import →export_rangesround-trip).Verification
cargo nextest: 13range_pull+ 202 cache + 118 protocol + 649 node — all passfmt --check,cargo doc,cargo deny, adr-ref-hygiene, markdownlint — cleanEncodeErrorsource, constructor-gatedAlignedRange, upstreamIROH_BLOCK_SIZEre-export, +6 tests.Not in this PR (follow-up)
Origin trait range+outboard adapters (HTTP
Range/ S3.range()/ fsseek), enginepull_throughrange wiring (encode_verified_range→import_bao_bytes), voucher metering over the bounded range, and the client serve path (composes with #915). The serving handler MUST route(byte_offset, byte_len)throughalign_rangeand sourceblob_sizefrom the signedStreamResponse.total_bytes.🤖 Generated with Claude Code