Skip to content

feat(client-pull,cli): range-minimized decdn fetch via gap-driven driver (P3-client of #1621) - #1631

Merged
alpergundogdu merged 9 commits into
mainfrom
feat/1621-p3-client-blobsource
Aug 7, 2026
Merged

alpergundogdu merged 9 commits into
mainfrom
feat/1621-p3-client-blobsource

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

What

Phase A (P3-client) of #1621 / #1608. decdn fetch now satisfies range R of blob H by pulling and paying for only missing_ranges(R) — held ranges are read locally, never re-pulled, never re-paid. Introduces the four substrate-agnostic driver axes, built node-capable so the node serve-miss (Phase B) is adoption, not a retrofit.

Six commits:

  1. axes — BlobSource (dumb source of raw bao bytes) + Funder (injected top-up seam) + Pacer/BudgetPacer (pure decision; error classification lifted to the driver as exhaustion_confirmed). client-pull.
  2. PeerSource — wraps the paid progressive pull behind BlobSource; threads a bounded byte_len through open_progressive_pull → StreamRequest so a middle gap [offset,len) can be requested (the wire already carried the field).
  3. ClientRangedStore::ingest_stream — streams a gap's raw bao into positioned .partial + accumulating .obao4 at O(chunk-group) memory, with 4 MiB fsync-before-record checkpoints so a mid-gap fault resumes without re-paying the received prefix.
  4. drive(...) — the gap loop, folding the resume / top-up / settle-wait / reseed logic behind the Pacer+Funder axes. Money-assertion test: opened ranges == the gaps exactly.
  5. route decdn fetch through drive over a ClientRangedStore; channel context shared via Arc<Mutex<ChannelContext>> (no lock across .await); CLI Funder; the whole-file resume re-hash is dropped (subsumed by the store's per-byte bao verify + finalize's valid_ranges sweep).
  6. doc + dedup — corrected checkpoint re-pay-window doc; relocated the settle-wait constants to client-pull.

For your conscious ratification (from the final review)

Mid-gap-fault re-pay window. On a mid-gap fault, content received since the last 4 MiB checkpoint is re-pulled and re-paid on resume — up to ~one 4 MiB checkpoint interval (≈4 default 1 MiB voucher intervals) × MAX_RESUME_ATTEMPTS. Checkpointed bytes are never re-paid, and faults are rare + bounded, so on large files this is <0.1%. The knob is INGEST_CHECKPOINT_BYTES (4 MiB): smaller = fewer re-paid bytes on fault but more fsyncs; aligning to the voucher interval (1 MiB) drives it toward the payment granularity. Kept at 4 MiB — flagging so you can decide the cadence.

Deferred to later phases (non-blocking, tracked)

  • PaceDecision::Draw{up_to_bytes} is currently ignored (TODO in driver.rs) — benign with BudgetPacer (full remainder); the node WindowPacer (Phase B) must honor it (a localized clamp).
  • Foreign-partial resume UX: a leftover .ranges from a different hash at the same --output fails the first run opaquely (no money lost — finalize's sweep catches it). Cheap root sanity-check is a follow-up.
  • One throwaway header-only handshake to learn total_bytes (pays nothing).
  • bundle pull still uses the legacy fetch_blob_streaming loop — P4 migrates it and deletes the second path.

Not in this PR

Verification

  • cargo build && cargo clippy --all-targets --all-features -- -D warnings — clean
  • cargo nextest run -p decdn-client-pull -p decdn-cli — 601/601 (incl. the money-assertion + all gap scenarios + mid-gap-fault-resume)
  • cargo fmt -- --check — clean
  • cargo test --no-run -p decdn-e2e --features anvil-e2e — compiles
  • cargo tree -p decdn-cli -e normal -i iroh-blobs — nothing (CLI binary-split regression: publisher links cache crate (iroh-blobs/AWS SDK) #578 holds)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • decdn fetch now downloads only missing byte ranges, improving resume efficiency.
    • Interrupted downloads can recover from checkpointed progress and finalize atomically.
    • Improved handling of payments, top-ups, and settlement during long-running fetches.
  • Bug Fixes

    • More reliable verification and recovery from corrupted or incomplete download data.
    • Improved handling of stale resume states and transfer interruptions.

alpergundogdu and others added 6 commits August 6, 2026 14:31
…n driver

Defines the substrate-agnostic driver axes (#1608): BlobSource (dumb raw-bao
source), Funder (injected top-up seam), Pacer/BudgetPacer (pure draw/top-up/wait
decision). Scripted test doubles + pure BudgetPacer unit tests. No PeerSource or
driver yet.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ests

open_progressive_pull now threads byte_len into StreamRequest so a middle gap
[offset,len) can be requested (wire already carried the field). PeerSource wraps
the paid progressive pull behind BlobSource (Reader=PullReader, finish drains to
the voucher watermark). Existing callers pass byte_len=0 (to-end, unchanged).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Consumes a gap's raw bao stream into positioned .partial + accumulating .obao4 at
O(chunk-group) memory, checkpointing present-ranges durably (fsync-before-record)
so a mid-gap fault resumes without re-paying the received prefix. Evolves
decode_to_sink: Leaf written positioned, Parent persisted to the outboard.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…_ranges

drive(store, source, pacer, funder, ...) fills each gap of missing_ranges(R)
via a paced PeerSource pull streamed through ingest_stream, folding the resume/
top-up/settle-wait/reseed loop behind the Pacer+Funder axes. Held ranges are
read locally, never pulled, never re-paid. Money-assertion test: opened ranges
== the gaps exactly.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…tRangedStore

decdn fetch now pulls only missing_ranges(R): the single-cursor stream loop is
replaced by drive() over a ClientRangedStore + PeerSource + BudgetPacer + a CLI
Funder. Channel context is shared (interior-mutable) so the driver's top-up/reseed
and the source's pull see one state. Whole-file resume re-hash dropped (the store
bao-verifies every byte + valid_ranges sweep). Held ranges never re-paid.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
… settle-wait constants

The mid-gap-fault re-pay window is up to one 4 MiB checkpoint interval (~4 default
voucher intervals) x MAX_RESUME_ATTEMPTS, not "under one interval" — checkpointed
bytes are still never re-paid. Relocate MAX_TOPUP_SETTLE_WAITS/TOPUP_SETTLE_BACKOFF
to client-pull so drive() and bundle pull's legacy loop share one definition.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 6, 2026 15:25
@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: e72ec361-61ec-444f-abf5-f4be7746fd26

📥 Commits

Reviewing files that changed from the base of the PR and between ebf5d79 and 2033ef2.

📒 Files selected for processing (6)
  • crates/client-pull/src/driver.rs
  • crates/client-pull/src/pacer.rs
  • crates/client-pull/src/ranged_store.rs
  • crates/client-pull/src/source.rs
  • crates/e2e/Cargo.toml
  • crates/e2e/tests/cli_fetch_resume.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/client-pull/src/source.rs

Walkthrough

This change adds a gap-driven ranged pull pipeline for blob fetches. It introduces source, pacing, driver, and ranged-store layers, wires them into CLI fetch, updates bounded range opens, and validates checkpointed resume, corruption recovery, foreign checkpoints, and free promotion.

Changes

Gap-driven pull pipeline

Layer / File(s) Summary
Range-bound pull contracts
crates/client-pull/src/lib.rs, crates/client-pull/src/sink.rs, crates/cli/src/commands/fetch.rs, crates/node/src/node_origin/*
client-pull exports driver, pacer, and source APIs. Progressive opens accept byte_len, aligned_wire_len supports bounded ranges, and whole-tail callers pass 0 explicitly.
Source and pacing seams
crates/client-pull/src/source.rs, crates/client-pull/src/pacer.rs
New source and funder interfaces support range-scoped pulls and reactive top-ups. PeerSource opens requested ranges, and BudgetPacer returns draw, top-up, done, or refuse decisions.
Checkpointed ranged store ingest
crates/client-pull/src/ranged_store.rs
ClientRangedStore opens resumable stores and ingests verified bao ranges with positioned writes and durable checkpoints. Tests cover recovery, promotion, faults, and corruption.
Driver orchestration and CLI fetch wiring
crates/client-pull/src/driver.rs, crates/cli/src/commands/fetch.rs, crates/e2e/tests/cli_fetch_resume.rs
drive fetches missing gaps, handles payment and top-ups, and finalizes complete blobs. CLI fetch uses ranged storage and CliFunder; end-to-end tests cover checkpointed resume scenarios.

Estimated code review effort: 5 (Critical) | ~100 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI as decdn fetch
  participant Driver as drive
  participant Source as PeerSource
  participant Store as ClientRangedStore
  participant Funder as CliFunder

  CLI->>Driver: start fetch
  Driver->>Source: open missing gap
  Source-->>Driver: header and reader
  Driver->>Store: ingest_stream(range, reader)
  Store-->>Driver: checkpointed progress
  Driver->>Funder: top_up(additional) when required
  Driver->>Source: finish(reader)
  Driver-->>CLI: finalize complete blob or keep resumable state
Loading

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands.

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

Implements Phase A of the range-minimized, gap-driven fetch path: decdn fetch now fills only missing_ranges for a requested blob by driving a new client-pull fetch driver over ClientRangedStore, using a bounded byte_len progressive pull for mid-gap requests.

Changes:

  • Add the gap-driven fetch driver (drive) with injected BlobSource/Funder/Pacer axes and associated test doubles.
  • Introduce streaming, checkpointed ranged-store ingest (ClientRangedStore::ingest_stream) and plumb byte_len through progressive pulls to support bounded gap requests.
  • Route decdn fetch through the new driver and store, retaining the legacy streaming loop for bundle pull (for now).

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/node/src/node_origin/resume.rs Passes byte_len=0 explicitly for whole-tail node resume pulls.
crates/node/src/node_origin/mod.rs Passes byte_len=0 explicitly for whole-tail node candidate-fallback pulls.
crates/client-pull/src/source.rs Adds BlobSource/Funder axes and PeerSource adapter (bounded range open via byte_len).
crates/client-pull/src/sink.rs Exposes PullReader/StashedFault and an into_inner path needed by the new source/driver plumbing.
crates/client-pull/src/ranged_store.rs Adds open_or_create and streaming ingest with durability checkpoints for resumable gap fills.
crates/client-pull/src/pacer.rs Introduces pure pacing axis (Pacer, BudgetPacer) for driver decisions.
crates/client-pull/src/lib.rs Exports new driver/pacer/source APIs; plumbs byte_len through progressive pull open and wire-cost sizing.
crates/client-pull/src/driver.rs New gap-driven driver (drive) coordinating store gaps, pulls, top-ups, settle-waits, and reseed logic.
crates/cli/src/commands/fetch.rs Switches decdn fetch to the new driver + ranged store; keeps legacy loop for bundle pull.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/client-pull/src/pacer.rs Resolved
alpergundogdu and others added 2 commits August 6, 2026 17:04
BudgetPacer returned Wait whenever awaiting_settle, and fill_gap set it after
every top-up, so the driver slept the full settle budget (30x500ms) before
retrying. Retry the open immediately after a top-up; the bounded settle-wait now
fires only when a re-open actually fails resume_may_be_stale, matching the legacy
CLI loop.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…edStore

The resume journeys seeded a raw .partial (old model); the gap-driven fetch
resumes only from its sidecar record. Add ClientRangedStore::seed_checkpointed_prefix
(test-util) and rewrite the journeys to construct a real checkpointed on-disk
state: resume-saves, corrupt-caught-by-finalize-sweep, foreign-no-wedge, and the
#1622 complete-partial free-finish, all under new-model semantics.

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

github-actions Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.52% (was 80.46%, ▲ +0.05%) — 59359/73723 lines

File Coverage Lines Δ
crates/cli/src/commands/fetch.rs 37.63% 596/1584 ▼ 1.75%
crates/client-pull/src/driver.rs 95.26% 583/612 new
crates/client-pull/src/lib.rs 89.85% 1451/1615 ▼ 0.37%
crates/client-pull/src/pacer.rs 98.89% 89/90 new
crates/client-pull/src/ranged_store.rs 90.01% 964/1071 ▲ +2.33%
crates/client-pull/src/sink.rs 92.73% 536/578 ▼ 0.48%
crates/client-pull/src/source.rs 66.67% 194/291 new
crates/node/src/node_origin/mod.rs 93.04% 1030/1107 ● 0.00%
crates/node/src/node_origin/resume.rs 93.75% 630/672 ▲ +0.03%
History
Commit Total Δ vs base
0a3ad1d 80.51% ▲ +0.05%
2033ef2 (HEAD) 80.52% ▲ +0.05%

…ion + paid-frontier resume

The node delivers the whole blob within its credit window (ADR 003/037), so
ingest_stream checkpoints bytes the vouchers haven't paid for yet. BudgetPacer
returned Done on delivered>=requested, stopping before the delivered-but-unpaid
tail was billed (under-pay). Done now requires PAID(wire) >= the range's wire
cost; an unpaid tail tops up and re-opens at content_paid_frontier(leg_start,
total, paid_wire) to re-deliver and bill it, terminating when paid catches up.
A fresh/cross-invocation resume (paid_wire==0) still resumes from the disk
frontier with no re-pay.

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

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Contracts coverage

Line coverage: 90.07% (2629/2919 lines)
▲ +0.00pp vs base (90.07% → 90.07%)
Run: 31166715499

@alpergundogdu
alpergundogdu merged commit afc7062 into main Aug 7, 2026
27 checks passed
@alpergundogdu
alpergundogdu deleted the feat/1621-p3-client-blobsource branch August 7, 2026 09:47
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