Skip to content

Partial/range origin pull-through: avoid fetching a whole blob from origin to serve a byte range on cache miss #823

Description

@alpergundogdu

Context

When a node has a cache miss and must fill the request from origin, the origin pull-through engine fetches the entire blob, even when the in-flight request only needs a byte range (e.g. the second GB of a multi-GB file). The node pays full origin egress (S3/R2/B2 metered bandwidth) and spends disk/time on bytes the client never asked for. For a client that wanted one GB of a large object, this is unrecouped origin cost on every cold range request.

ADR 037 (#723, completed) already addressed the node→node side of this — its window-paced pull-through plus iroh-blobs partial blobs + bao verified-streaming make a partially-held blob first-class and bound speculative loss to pull_ahead_bytes. But ADR 037's mechanism only applies when the upstream is a cdn/dht/v1 peer (another iroh-blobs node that can serve verified chunk ranges against the root hash). The origin tier — opaque S3/HTTP/B2 backends serving raw bytes by hash — is untouched and remains strictly whole-blob.

Evidence in code

  • Origin trait is whole-blob only. crates/cache/src/origin/mod.rs:230 — fetch(&self, hash: Hash, max_bytes: u64). max_bytes is an advisory cap, not a range selector. No offset/start/end/range parameter exists anywhere in the trait or adapters.
  • HTTP adapter (crates/cache/src/origin/http.rs) builds {base_url}/{blake3_hex} and reads the body start→EOF. No Range request header, no Content-Range handling.
  • S3 adapter (crates/cache/src/origin/s3.rs) issues GetObject with no Range set — serves the whole object.
  • Filesystem adapter (crates/cache/src/origin/fs.rs) opens the file and reads from byte 0; no seek/offset.
  • Engine (crates/cache/src/engine.rs pull_through / pull_through_attempt) receives the full stream, computes BLAKE3 over all received bytes, verifies against the requested hash, then commits. get(hash) takes a hash only — no range — and returns the full Bytes.

The hard part: verifying a partial range from a raw origin

Content is BLAKE3-addressed and the node MUST verify received bytes against the content address. For a node→node pull this is solved by bao verified streaming (the peer is an iroh-blobs store that produces the hash-tree). A raw origin serves opaque bytes by hash with no bao outboard, so a node cannot verify a sub-range [a, b) against the BLAKE3 root without the hash-tree — which today only exists after the whole blob has been fetched and imported at least once. This is the core design question, not just a missing HTTP header. Candidate directions to evaluate:

  1. Origin serves the bao outboard alongside data (e.g. a sibling key {hash}.obao4 + HTTP Range on the data object). Cleanest verification story; requires an origin-side publishing convention and an Origin trait that can request the outboard + a range. Raises the SSRF/redirect surface already noted in Origin pull-through SSRF + metrics_bind non-loopback warning #579 for an additional request.
  2. Fetch-whole-once, range-serve-after. Build the outboard on first full pull, then serve ranges from the cached partial. Does nothing for the cold case the user is worried about (the first range request still pulls the whole file).
  3. Lean on ADR 012 chunk/manifest granularity. Large files are already split into 256 MiB chunk-blobs at ingest with a manifest (ADR 012 §256 MiB / §manifest), each chunk independently BLAKE3-addressed. "The second GB" of a manifest-published file is ~4 distinct chunk-blobs, each pulled whole (256 MiB), not the whole multi-GB file. This substantially bounds the worst case for manifest content — the residual exposure is (a) single-large-blob publishes that skip the manifest, and (b) sub-256-MiB ranges. Worth deciding explicitly whether origin range-pull is even needed given chunking, or whether we just document chunking as the answer and tighten the max-blob cap.
  4. Require bao-encoded origins. Origins store/serve bao-encoded blobs natively; node range-fetches with inline verification. Strongest guarantee, heaviest publishing requirement.

Interaction with existing economic guards

The unrecouped-leech budget and per-peer share ratio from ADR 037 / #821 bound how much speculative pull-through a node absorbs, but they bound it in served-vs-pulled bytes — a whole-blob origin pull to serve a one-GB range still burns the budget on bytes the client never requested. Range-scoped origin pulls would make those caps tighter/cheaper, so this composes with rather than duplicates that work.

Scope / questions for an ADR

This is primarily a design / missing-decision item (likely an amendment to ADR 037 §pull-through and/or ADR 005 §protocol, possibly a new ADR — next number 038):

  1. Do we add a range-capable Origin::fetch (e.g. fetch(hash, range, max_bytes)), and which adapters support it (HTTP Range, S3 GetObject.range, fs seek)?
  2. How is a partial range from a raw origin verified against the BLAKE3 root — outboard-alongside-data (option 1), or do we declare chunking (option 3) the sanctioned answer and not add origin ranges?
  3. If we add it: how does a client-side range request (the cdn/client/v1 StreamRequest.byte_offset already exists in ADR 005) propagate down to a range-scoped origin pull rather than a whole-blob pull?
  4. SSRF/redirect hardening (Origin pull-through SSRF + metrics_bind non-loopback warning #579) for any second request (outboard fetch) and for Range requests.

Out of scope

References

Filed from a repository investigation; scoping a decision before the cdn/client/v1 paid-delivery handler (TODO #317) lands the origin range path.

Activity

  1. added
    kind:feature
    on Jun 5, 2026
  2. added
    design:economics
    design:missing-decision
    on Jun 5, 2026
  3. github-actions commented on Jun 5, 2026

    @github-actions

    🎯 Triage report

    This is a well-scoped design/missing-decision issue filed by a collaborator identifying that the origin pull-through path (Origin trait + all three adapters) is strictly whole-blob with no range capability, unlike the node→node path which gained partial-blob/bao verified-streaming support via ADR 037. The core blocker is verification: a raw origin serves opaque bytes with no bao outboard, so range verification against the BLAKE3 root requires either an out-of-band outboard fetch or reliance on ADR 012 chunking (which already bounds the worst case for manifest content to ~256 MiB per chunk). The issue cleanly enumerates four design directions and their trade-offs. No implementation work can start without an ADR decision.

    📊 Assessment

    Dimension Value Reasoning
    Type unchanged (Feature) Already set; correct — this is a new capability / design decision, not a bug
    Labels unchanged enhancement, adr-review, economics, technical, missing-decision are all accurate and sufficient
    Coding agent Not suitable Requires architectural decision across 4 candidate directions, likely a new ADR (038); needs ADR 037/012/005 alignment and economic trade-off evaluation before any implementation can begin

    🔗 Similar issues

    💡 Notes and suggestions

    Decision gate before implementation: The four candidate directions in §The hard part map to meaningfully different implementation and publishing-convention costs:

    • Option 1 (sibling .obao4 + HTTP Range): Cleanest verification; requires origin publishing convention change and adds a second request (SSRF surface — see Origin pull-through SSRF + metrics_bind non-loopback warning #579). Origin trait needs fetch_outboard(hash) + fetch_range(hash, range).
    • Option 2 (fetch-whole-once, range-serve-after): No publishing changes; does not help cold requests at all. Low ROI.
    • Option 3 (declare chunking the answer): Lowest implementation cost — document ADR 012 chunking as the sanctioned boundary and add a configurable max_blob_size cap to prevent non-manifest single-blob publishes from re-exposing the problem. This should be evaluated first; it may fully satisfy the constraint for PoC-scale.
    • Option 4 (bao-encoded origins): Strongest guarantee, highest publishing barrier.

    Suggested ADR 038 scope: A single decision record that (a) evaluates options 1–4 against the BLAKE3 verification constraint, (b) records whether option 3 is sufficient or whether an offset/range extension to the Origin trait is warranted, and (c) defines the propagation path from StreamRequest.byte_offset (ADR 005) down to a range-scoped origin pull if option 1 is chosen.

    Code entry points for implementation (whichever direction):

    • crates/cache/src/origin/mod.rs — Origin::fetch signature (line ~230)
    • crates/cache/src/origin/http.rs — add Range: bytes=start-end header
    • crates/cache/src/origin/s3.rs — populate GetObjectRequest.range
    • crates/cache/src/origin/fs.rs — seek(SeekFrom::Start(offset))
    • crates/cache/src/engine.rs — pull_through / pull_through_attempt to accept optional range and route partial import through iroh-blobs bao outboard path

    Dependency ordering: Block this on the cdn/client/v1 paid-delivery handler (#317) only for end-to-end wiring; the ADR and Origin trait extension can proceed independently.

    Generated by Agentic Triage for issue #823 · sonnet46 446.1K · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  4. alpergundogdu commented on Jun 5, 2026

    @alpergundogdu
    ContributorAuthor

    Scoping: amendments, not a new ADR — but validate the unknowns first

    Mapped the surface. This lands as amendments to existing ADRs (037 owns pull-through; 005/012 are conditional), not a new ADR. The mechanism looks straightforward, but it rests on two things we have not verified — a bao/iroh-blobs capability and a wire-protocol fork — so we should validate those before drafting the amendment text.

    Where it amends (and what's notably not in an ADR)

    • ADR 037 — owns pull-through; primary amendment site. Its window-paced/chunk-paced pull-through and "partial blobs are first-class" rest entirely on a bao-verified iroh-blobs upstream: the node "pulls from an upstream provider discovered via the normal cdn/dht/v1 path, verifying each chunk against the root hash" (037:57) and "bao verified-streaming make a partially-held blob first-class" (037:59). Nowhere does it cover a raw origin (S3/HTTP/B2), which has no bao tree. The amendment adds an explicit origin-tier subsection defining how a ranged origin fetch is verified. The economic caps (pull_ahead_bytes, max_unrecouped_leech_bytes, share_ratio, 037:84–98) are pure byte-counters and compose unchanged — a range-scoped pull just shrinks the "pulled" side.
    • The Origin trait is in no ADR. Origin status is governance-only (OriginAssignment; "the protocol does not distinguish origin from cache at probe time", 005:53–55, 011:456). The adapter contract (fetch(hash, max_bytes) in crates/cache/src/origin/mod.rs:230) is pure implementation. So adding a range parameter is a code change, and its verification contract gets written into the new ADR 037 origin subsection rather than a standalone ADR.
    • ADR 022 — no change. Range-addressed discovery stays deferred (037:80–82); whole-blob-only STORE holds. Partial origin pulls remain discoverable via RTT routing only, exactly as 037 already states.
    • ADR 005 / 012 — conditional, see the fork below.

    The decision fork that determines blast radius

    The biggest scoping question: do we need sub-blob ranges at all, or does chunk-granularity already cover the demand?

    • If 256 MiB chunk granularity is acceptable: the ADR 012 chunk/manifest model already solves the user's worry with zero wire change — "the second GB" of a manifest-published file is ~4 distinct chunk-blobs (each its own BLAKE3 hash), and the node pulls only those chunks whole. The residual gap is then only (a) sub-256-MiB precision and (b) single-large-blob/non-manifest publishes. In this branch the amendment is small: ADR 012 documents chunking as the sanctioned coarse answer, ADR 037 gets the origin subsection, no ADR 005 change, no cdn/client/v2.
    • If we want true sub-blob ranges (StreamRequest{hash, [a,b)}): this is where the protocol modification bites. byte_offset today is resume-only START with no END (005:167); expressing a bounded range needs a new field. Per ADR 013 an optional field is Tier-1 (no ALPN bump), but a range bound is billing-relevant and ADR 013 has no "must-understand optional field" notion — an old node that ignores it over-delivers/over-bills with no slash evidence. To be enforceable it must join the signed field set, which is Tier-3 → cdn/client/v2 (013:332–358, 005:375). That's a real protocol bump, so we should only take this branch if chunking is demonstrably insufficient.

    Missing parts to validate before writing amendments

    1. bao partial verification against an external outboard (load-bearing). Confirm iroh-blobs can verify a byte range [a,b) against root H using a separately supplied outboard, and — critically — that a bao outboard is self-verifying against H (so an origin can serve an untrusted outboard and the node validates range + outboard against H in one step). If that property holds, the raw-origin verification story is clean; if not, the whole feature needs a different design. Validate the exact iroh-blobs/bao API (decode_ranges / export-with-outboard / .obao4 format).
    2. Outboard availability for a cold blob. The outboard only exists after a full import today. For the cold case (the one that matters) the origin must serve it — define a publishing convention (sibling key {hash}.obao4?) and the fallback when it's absent (degrade to whole-blob pull). Decide whether requiring outboards at origin is acceptable.
    3. The chunk-vs-sub-blob fork above — answer this first; it decides whether ADR 005 / cdn/client/v2 are even in scope.
    4. Voucher/billing over a bounded range — total_bytes vs range length, voucher metering scoped to [a,b), and the ADR 013 "must-understand" gap if we go sub-blob.
    5. SSRF surface (Origin pull-through SSRF + metrics_bind non-loopback warning #579) for the extra outboard request and for Range requests (redirect policy already hardened for the data fetch; a second request reopens it).

    Proposing we resolve #1 and #3 first (a spike on the iroh-blobs bao API + a call on whether chunk-granularity suffices), since together they decide whether this is a small two-ADR amendment or a cdn/client/v2 protocol change. Will draft the amendment text once those are settled.


    Generated by Claude Code

  5. alpergundogdu commented on Jun 5, 2026

    @alpergundogdu
    ContributorAuthor

    Correction: ignore the protocol-bump logistics above

    cdn/client/v1 isn't on testnet yet, so breaking changes are fine — there's no cdn/client/v2, no Tier-3 ceremony, no signed-field/"must-understand" gymnastics. If we want a range bound on StreamRequest, we just add it in place (and put it in the signed set directly). Scratch that whole branch of the previous comment.

    That collapses the decision fork: the chunk-vs-sub-blob choice is now purely a design-merit call, not a cost/blast-radius one. Both options are cheap.

    • Sub-blob ranges: add a range bound (byte_len/end) to StreamRequest alongside the existing byte_offset, signed, done. The only real work is the origin-tier verification (the bao-outboard question, validation item Add devcontainer for secure Claude Code sessions #1) and the cache-engine/Origin::fetch range plumbing.
    • Chunk-granularity (ADR 012): still the zero-new-surface option — already gives "pull only the chunks you need." Worth keeping as the answer for coarse cases even if we add sub-blob ranges, since it needs nothing.

    Revised validation priority: the protocol shape is no longer a blocker, so the only load-bearing unknowns left are the origin-side ones — #1 (does bao let us verify a range against a self-verifying, externally-supplied outboard) and #2 (outboard availability/serving for a cold blob). Resolve those two and the amendment is writable; the StreamRequest change is mechanical. ADR 037 still owns the origin-tier subsection; ADR 012 documents chunking; ADR 005's StreamRequest gets the new field as a straight breaking edit; ADR 022 unchanged.

    (Couldn't edit the prior comment in place — the GitHub tooling here only supports adding comments, not editing — so treat this as superseding its "decision fork that determines blast radius" and "missing parts" §3/§4 protocol bits.)


    Generated by Claude Code

  6. assigned and unassigned on Jun 19, 2026
  7. assigned and unassigned on Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

design:economicsdesign:missing-decisionkind:feature

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions