Skip to content

feat(cache,protocol): range origin pull-through — ADR decision + bao verify helper (#823) - #961

Merged
thiras merged 3 commits into
mainfrom
feat/823-range-origin-pull-through
Jun 20, 2026
Merged

thiras merged 3 commits into
mainfrom
feat/823-range-origin-pull-through

Conversation

@thiras

@thiras thiras commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

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-review labels) 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 root H it already wants — self-validating: a tampered range, a tampered/foreign outboard, or a wrong root all fail (anchored to H, which the node supplies, not the origin). Absent outboard / no Range support degrades to the existing whole-blob pull, which is never a correctness or availability failure.

Contents

  • ADRs (the decision): 037 (Origin-tier pull-through subsection + origin_range_pull_enabled param + 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).
  • protocol: StreamRequest.byte_len base field (pre-testnet in-place edit) + requested_len() accessor.
  • cache::range_pull: align_range + encode_verified_range — turn a raw origin range + untrusted outboard into a bao-encoded stream verified against H, ready for iroh-blobs import_bao_bytes. Proven end-to-end (import → export_ranges round-trip).

Verification

  • cargo nextest: 13 range_pull + 202 cache + 118 protocol + 649 node — all pass
  • clippy (workspace, all-targets), fmt --check, cargo doc, cargo deny, adr-ref-hygiene, markdownlint — clean
  • Reviewed by the pr-review-toolkit agents (code / tests / silent-failure / type-design / comments); no critical bugs, all findings applied: typed EncodeError source, constructor-gated AlignedRange, upstream IROH_BLOCK_SIZE re-export, +6 tests.

Not in this PR (follow-up)

Origin trait range+outboard adapters (HTTP Range / S3 .range() / fs seek), engine pull_through range 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) through align_range and source blob_size from the signed StreamResponse.total_bytes.

🤖 Generated with Claude Code

…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]>
Copilot AI review requested due to automatic review settings June 20, 2026 19:21

@gemini-code-assist gemini-code-assist Bot 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.

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.

Comment thread crates/cache/src/range_pull.rs Resolved
Comment thread crates/cache/src/range_pull.rs Resolved

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.

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/v1 StreamRequest with byte_len (0 = whole tail) plus a requested_len() helper and round-trip test.
  • Add decdn_cache::range_pull with align_range and encode_verified_range to verify ranged origin bytes against a bao outboard and produce import_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: 0 through 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.

Comment thread crates/cache/src/range_pull.rs Resolved
Comment thread crates/cache/tests/range_pull.rs Resolved
Comment thread adr/037-regional-proxy-warming.md Resolved
Comment thread adr/005-protocol.md Resolved
@github-actions

github-actions Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 83.82% (was 83.79%, ▲ +0.02%) — 39482/47106 lines

File Coverage Lines Δ
crates/cache/src/lib.rs 100.00% 28/28 ● 0.00%
crates/cache/src/range_pull.rs 95.70% 89/93 new
crates/client-pull/src/lib.rs 85.37% 502/588 ▲ +0.15%
crates/protocol/src/client.rs 97.68% 631/646 ▼ 0.42%
History
Commit Total Δ vs base
fe586a3 83.81% ▲ +0.01%
d7366d1 83.81% ▲ +0.02%
8113366 (HEAD) 83.82% ▲ +0.02%

thiras and others added 2 commits June 20, 2026 22:30
… 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]>
@thiras
thiras merged commit f99ab49 into main Jun 20, 2026
22 checks passed
@thiras
thiras deleted the feat/823-range-origin-pull-through branch June 20, 2026 19:50
thiras pushed a commit that referenced this pull request Jun 25, 2026
…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]>
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