Skip to content

feat: serve fs-origin blobs zero-copy without importing into the store (#1511) - #1750

Closed
alpergundogdu wants to merge 11 commits into
mainfrom
claude/issue-1511-status-6d604d
Closed

alpergundogdu wants to merge 11 commits into
mainfrom
claude/issue-1511-status-6d604d

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #1511.

What

A node can now serve a content-addressed blob — whole or ranged — straight from a configured filesystem origin's file ({base}/{hex[0..2]}/{hex} + sibling {hex}.obao4 pre-order outboard), bypassing the iroh-blobs store entirely. No import, no second on-disk copy. Previously an fs-origin serve imported the blob (or a partial range) into the store first, costing two copies on the same disk for no benefit.

Zero-copy engages only when the outboard already exists; otherwise dispatch falls through to today's tiers unchanged — it is a pure optimization overlay with no regression when ineligible. The node daemon never writes to the origin tree; outboards are an operator-maintained artifact generated by a new CLI.

How

  • bao-range — a header-less, seekable range encoder (encode_verified_range_headerless, generic over positioned_io::ReadAt + Write) that streams a verified range straight from a File in O(chunk-group) RAM, and a streaming pre-order outboard computation (compute_pre_order_outboard, bounded memory).
  • cache — Origin::open_local_reader (fs override, symlink-containment guarded) yields a seekable LocalBlob; export_bao_range_stream_from_origin composes it with the .obao4 and the encoder, bridging the sync encoder to the async serve stream via a bounded channel (same stream type as the store path, so ChunkFramer/vouchers are untouched); origin_zero_copy_total is the dispatch gate.
  • node — deliver gains a ServeSource { Store, OriginZeroCopy } selector; dispatch carries an authoritative total past the shared size/floor/sign tail (the existing range_pulled_size pattern), guards the import tiers so neither runs when zero-copy is elected, and gates the whole thing behind pull_authorized.
  • cli — decdn origin index walks each configured fs origin and generates {hex}.obao4 siblings (streaming compute, hash-verified, idempotent, --force, atomic write). Stays iroh-blobs-free (CLI binary-split regression: publisher links cache crate (iroh-blobs/AWS SDK) #578): only decdn-bao-range, a leaf crate, is added.

Correctness / safety

  • Served bytes are validated against the requested content hash as they encode, so a corrupt or mismatched origin file faults (aborts the delivery, no closing voucher) rather than ever yielding corrupt bytes.
  • The zero-copy gate is behind pull_authorized — an unauthorized client cannot induce origin egress or be served origin bytes. Floor-reservation, voucher, and max_blob_size/bounds guards are shared with the store path (single deliver caller), so no payment/authorization guard is weakened.
  • open_local_reader reuses the same canonicalize + base-containment symlink guard as the existing fs fetch/size methods.

Testing

  • bao-range unit: header-less output equals the reference encoder minus its header (whole + interior ranges); tampered data faults; computed outboard matches the in-memory oracle and round-trips.
  • cache unit: gate reports the total with an outboard / None without; the origin export leaves the store empty; multi-origin fallback.
  • node loopback: whole-blob and ranged zero-copy serve with no store import; a discriminating control that a missing outboard falls through and imports (origin_fetches == 1).
  • e2e (anvil-e2e): a real paid client fetch (whole + ranged tail) against an fs-origin node leaves the node's blob store empty — proof of zero import (ran green repeatedly).

Full suites green on the branch: node 897/897, bao-range + cache + cli 799/799, clippy (anti-panic gate) clean across all touched crates.

Notes for reviewers

  • Reviewed whole-branch (multi-agent): no critical/blocking findings. Deferred follow-ups: an optional short-circuit of the origin-size probe on pure-remote/node-to-node deployments (perf, authz-gated), and a small shared outboard-size-validation dedup in bao-range (cosmetic).
  • An unrelated pre-existing contracts/foundry.lock working-tree change is deliberately not included.

🤖 Generated with Claude Code

…ault doc

open_local_origin_reader now accumulates a last_err and only surfaces it
after every origin declines, mirroring origin_fetch_outboard_bytes's
fallback discipline instead of failing on the first origin's transient
error. Also corrects export_bao_range_stream_from_origin's doc: a
vanished local reader/outboard after the caller has committed to the
zero-copy serve is a delivery fault, not a benign degrade.
Copilot AI lite review requested due to automatic review settings August 19, 2026 08:41

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

Adds a zero-copy serve path for filesystem origins: when a {hex}.obao4 pre-order outboard exists next to an origin file, nodes can stream verified bao (whole or ranged) directly from that file without importing into the iroh-blobs store. This fits the deCDN cache/miss ladder by adding an eligibility gate + a new export source while keeping the downstream framing/voucher logic unchanged.

Changes:

  • Add a new bao-range header-less, ReadAt-based verified range encoder plus streaming pre-order outboard computation.
  • Add cache + node plumbing to gate and stream origin-backed zero-copy delivery (ServeSource::OriginZeroCopy) while preserving existing fallback tiers.
  • Add decdn origin index to generate .obao4 siblings for configured filesystem origins, plus new loopback/e2e coverage.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/node/tests/client_loopback.rs Adds loopback tests for zero-copy whole + ranged serve and a missing-outboard fallback control.
crates/node/src/handlers/client/dispatch.rs Introduces the zero-copy eligibility gate and routes delivery via a new ServeSource selector.
crates/node/src/handlers/client/delivery.rs Teaches deliver to stream from either store-backed export or origin-backed zero-copy export.
crates/e2e/tests/fs_origin_zero_copy_paid_fetch.rs New anvil-e2e test proving paid fetches don’t import into the node store when outboards exist.
crates/e2e/src/node.rs Adds a helper to kill the daemon and reopen the cache dir to check store blob presence.
crates/common/src/cli/origin.rs Adds clap argument types for decdn origin index.
crates/common/src/cli/mod.rs Wires the new Origin command group into the shared CLI command model.
crates/cli/src/main.rs Dispatches Command::Origin to the new origin command handler.
crates/cli/src/commands/origin.rs Implements decdn origin index (walk fs origins, compute+write .obao4 siblings).
crates/cli/src/commands/mod.rs Registers the new origin command module.
crates/cli/Cargo.toml Adds decdn-bao-range as a CLI dependency (intended to preserve the iroh-blobs-free invariant).
crates/cache/src/origin/mod.rs Extends the Origin trait with open_local_reader and introduces LocalBlob.
crates/cache/src/origin/fs.rs Implements open_local_reader for FilesystemOrigin with canonicalize+containment guard.
crates/cache/src/engine.rs Adds the zero-copy gate (origin_zero_copy_total) and the origin-backed bao export stream.
crates/bao-range/src/lib.rs Adds encode_verified_range_headerless and compute_pre_order_outboard plus unit coverage.
Cargo.lock Locks the new workspace dependency wiring.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/cache/src/engine.rs Resolved
Comment thread crates/e2e/src/node.rs Resolved
Comment thread crates/cli/src/commands/origin.rs Resolved
…ync obao4, non-blocking child reap

- cache: reject a size-mismatched origin file before emitting any frame, so a
  file truncated/grown between the gate and serve can't produce a partial,
  already-billed delivery.
- cli: sync_all the .obao4 temp file before persist, matching the CLI's other
  atomic writers, so a power loss after rename can't leave an empty outboard.
- e2e: reap the killed daemon under block_in_place so the blocking wait doesn't
  stall the multi-thread runtime's worker.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 80.82% (was 80.84%, ▼ 0.02%) — 59097/73123 lines

File Coverage Lines Δ
crates/bao-range/src/lib.rs 93.10% 243/261 ▼ 0.77%
crates/cache/src/engine.rs 90.88% 3755/4132 ▼ 0.50%
crates/cache/src/origin/fs.rs 77.50% 644/831 ▼ 0.87%
crates/cache/src/origin/mod.rs 59.66% 71/119 ▲ +2.52%
crates/cli/src/commands/origin.rs 70.91% 78/110 new
crates/cli/src/main.rs 62.50% 25/40 ▼ 1.60%
crates/common/src/cli/mod.rs 100.00% 3/3 ● 0.00%
crates/e2e/src/node.rs 23.62% 120/508 ▼ 1.17%
crates/node/src/handlers/client/delivery.rs 95.63% 241/252 ▼ 0.27%
crates/node/src/handlers/client/dispatch.rs 84.23% 406/482 ▼ 0.07%
History
Commit Total Δ vs base
9649aa7 (HEAD) 80.82% ▼ 0.02%

@alpergundogdu

Copy link
Copy Markdown
Contributor Author

Closing without merging.

On review, the double-store this eliminates is bounded by the store's LRU cache (cache_size_mb), not an unbounded mirror of the origin — so the disk saving is modest, while serving fs+outboard blobs zero-copy gives up two things that matter more for popular content:

  • Cache hits — a cached blob serves without re-reading or re-verifying the origin; zero-copy re-verifies against the outboard on every serve.
  • Own-origin coalescing — concurrent same-hash misses share one fill instead of N independent reads/verifications.

The two_clients_coalesce_one_upstream_pull_each_pays journey surfaced this concretely: the zero-copy path bypasses serve_via_backend_origin, so concurrent misses neither coalesce nor promote a cache entry.

The one case where zero-copy still wins is a blob larger than the cache (importing it thrashes the working set and it can't be cached anyway). If that becomes a priority, the right shape is a size-aware gate — zero-copy only when the blob won't fit the cache — not an unconditional replacement of the import→cache→coalesce path. Captured on #1511.

The reusable building blocks (header-less ReadAt/Write range encoder + streaming pre-order outboard computation in bao-range, and decdn origin index) remain in this PR's commit history if a size-aware follow-up picks them up.

@alpergundogdu
alpergundogdu deleted the claude/issue-1511-status-6d604d branch August 19, 2026 15:27
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.

cache: fs-origin zero-copy pass-through (serve from {path}/{hex} without importing into the store)

2 participants