Repository navigation
feat(client-pull): Downloader on the multi-source core, fan-out + dedup (#1848) - #2112
Merged
alpergundogdu merged 2 commits intoSep 22, 2026
Conversation
…up) (#1848) Phase 3: reshape the Downloader onto the same shared core the Streamer uses, uncapped for full-throughput download. - Downloader::new now takes a Vec<StreamCandidate> (the shared provider-candidate type) instead of one source + pacer + ctx + ledger. fetch_to_dir builds one lane per candidate and drives each entry across them through multi_source_fetch with a BudgetPacer, no consumption pacing, and max_sources = every candidate (uncapped fan-out), then finalizes — promoting .partial to the file. So the two faces are now one engine: the Streamer caps the fan-out and paces on the consumer cursor; the Downloader uncaps it and runs full throughput. - Failover comes for free (shared-pool reassign, #1174). A resumed download — an existing .partial, e.g. a bundle layer's chunk-hint dedup pre-seeded into it — re-pulls only its missing ranges. Tests: two candidates stripe one blob BLAKE3-identical with both contributing; a pre-seeded prefix is fetched only as its complement (dedup/resume); the single-candidate BLAKE3-identical path is unchanged (no regression). Full client-pull suite 321/321. Stacked on the Phase 2 Streamer change. Follow-up (Phase 4): CLI rewiring (bundle pull -> Downloader, decdn fetch -o - -> Streamer, decdn fetch -o file -> Downloader). Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
It introduces at least one CI-breaking issue (unused import) and should add an explicit non-empty candidate precondition for clearer, earlier failure behavior.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
This PR reshapes client-pull’s Downloader to be a thin wrapper over the shared multi-source scheduler core used by Streamer, enabling uncapped fan-out across all provider candidates for full-throughput downloads while preserving resume/dedup via existing .partial stores.
Changes:
- Refactors
Downloaderto accept aVec<StreamCandidate>and drive downloads throughmulti_source_fetchwith aBudgetPacerand no consumption pacing. - Adds explicit download-side stall watchdog configuration (
DOWNLOAD_UNIT_DEADLINE) and promotes completed.partialstores viafinalize(). - Extends tests to cover multi-source striping and “pre-seeded prefix is not refetched” resume/dedup behavior.
| File | Description |
|---|---|
| crates/client-pull/src/downloader.rs | Reworks Downloader to use the shared multi-source scheduler core, adds full-throughput fan-out behavior, and expands test coverage for striping and resume/dedup. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Address Copilot review on #2112: `fetch_to_dir` now fails with a clear "needs at least one provider candidate" error before opening any store or building empty lane sets, instead of surfacing a less obvious fault deep inside multi_source_fetch on the first entry. Test locks the behaviour. (The other finding — an unused `RangedStore` import — is a false positive: the import is used by `store.finalize()`, a `RangedStore` trait method, and clippy under -D warnings is clean.) Co-Authored-By: Claude Opus 4.8 <[email protected]>
Base automatically changed from
claude/streamer-multi-source-failover
to
claude/trusting-raman-1b3304
September 22, 2026 12:44
thiras
pushed a commit
that referenced
this pull request
Sep 22, 2026
… a unified multi-source core (#2108) * feat(client-pull): reuse a warm connection across hashes (WarmConnection) Add WarmConnection: a caller-owned cdn/client/v1 connection dialled once and reused across many hashes, opening a fresh bi-stream per hash (one stream = one hash, no wire change). open_stream takes a ConnSource (dial a fresh one-shot connection or reuse a warm one); open_progressive_pull keeps the dial path and open_progressive_pull_on opens a pull on a warm connection. UpstreamPull now tracks whether it owns its connection: an owned one-shot dial is closed on the pull's terminal method, while a borrowed warm connection is left open for the next hash — only the current stream is torn down. The warm connection closes once, on its own Drop. Test: two distinct hashes fetched back-to-back over one WarmConnection dial the connection exactly once (client_loopback::two_hashes_reuse_one_warm_connection). Part of #1848 (T1). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): add PullConfig zero-config tunables scaffold Add config::PullConfig, the injected tunables the consumption faces (Downloader, Streamer, #1848) share. It holds only tunables, each with a sensible default, so PullConfig::default() is the whole configuration a caller needs; the required per-fetch inputs (identity, connection, spend budget, providers) stay on the engine's existing params, which is why PullConfig constructs with no network or chain access (proven by a const construction). The first tunable is the Streamer's read_ahead_bytes bound (default 16 MiB); more fields are added as Downloader (T4) and Streamer (T6) grow to consume them. The payment interval stays the fixed protocol const CHUNK_BYTES, not a tunable. Part of #1848 (T2). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): add ByteSink output + injected BlobCache traits Add the output side of a fetch to sink.rs (#1848 T3): - ByteSink: where the engine writes verified content bytes, at absolute offsets, so an out-of-order multi-source fetch lands each range at its position. The Downloader backs it with a file. - BlobCache: the injected (hash, offset) content cache the Streamer consults and fills. Pure — it names no blob store — so client-pull stays iroh-blobs-free; a blob-store-backed impl is injected from above. The default is the no-op NoCache (never hits, never stores). Both use the crate's boxed-future async-trait shape (SinkFuture). Test doubles VecByteSink and MemoryBlobCache ship under test-util for the Downloader/Streamer suites. check_crate_edges.py still passes (decdn-cli closure clean). Part of #1848 (T3). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): add Downloader (bundle/blob fetch-to-dir face) Add the Downloader consumption face (#1848 T4): fetch a set of content-addressed blobs — a bundle, or a single blob — to files in a directory. It is an output+scheduling adapter over the ONE paid pull engine, not a second engine: each (hash, total_bytes) entry opens a ClientRangedStore beside dir/<hex> and drives only its missing ranges through driver::drive, which bao-verifies every byte on ingest and promotes .partial to the final file on completion. So writes land out-of-order at their offsets, a resumed download re-pulls only what it lacks, and a bundle layer above can pre-seed held ranges (its chunk-hint dedup) into the store so the same drive fills only the complement. Bundles are the main scenario (a bundle is a set of entries → one file each, named by content-address hex; a single blob is a bundle of one). The pull machinery (source, pacer, funder, ctx, ledger) is injected and shared across every entry, so one provider connection and one payment channel serve a whole bundle. fetch_to_dir takes &PullConfig for symmetry with the Streamer; the Downloader fetches at full throughput, so no tunable changes its behaviour yet. decdn fetch / bundle pull are rewired onto this in later PRs. Part of #1848 (T4). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): add Streamer + VerifiedReader (consumption-paced fetch) Add the Streamer consumption face (#1848 T5+T6): stream one blob's verified, contiguous front to a consumer as it arrives, paced by how fast the consumer reads — the fetch-like, single-blob face (no chunk dedup, unlike the Downloader). One engine, two faces: the Streamer configures the SAME paid pull engine, not a second one. It drives the fetch through driver::drive with a WindowPacer whose window is PullConfig::read_ahead_bytes and whose downstream frontier is the CONSUMER'S read cursor — the bounded-read-ahead mode the driver already supports (window_pacer_gates_on_injected_served_paid), so T5 needs no engine change. The pull never runs more than one read-ahead window ahead of what the consumer has read, so a viewer who stops after five minutes never fetches (or pays for) the whole two-hour movie; that read-ahead bound IS the outstanding-spend bound. VerifiedReader is the tokio::io::AsyncRead the caller drains. It cooperatively polls the drive future inside poll_read and reads only the store's CHECKPOINTED present frontier, so it is clamped to the verified contiguous frontier by construction — a tampered chunk group fails the pull and surfaces as a read error rather than ever reaching the consumer. On a clean finish the whole verified blob is teed to the injected BlobCache; a revisit whose cache already holds the blob serves straight from memory and never touches the network. Tests: drained stream BLAKE3-identical; a tampered tail never surfaces (verified prefix only, then an error); a full cache hit fetches nothing; a slow consumer holds the in-flight bytes within the read-ahead bound. decdn fetch is rewired onto this in a later PR. Part of #1848 (T5, T6). Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(client-pull): surface store errors + fail-loud cursor in the Streamer Address Copilot review on #2108: - present_frontier no longer swallows a present_ranges() fault as "nothing present" (which could stall the reader or look like early EOF); it returns a Result and the read future surfaces it to the consumer. - The cursor advance converts the read length to u64 BEFORE handing out bytes and fails loudly on the (practically impossible) overflow, so the cursor can never desynchronize from bytes already delivered. - BlobCache docs now state the actual behaviour: a whole-blob cache hit serves without fetching, anything less is refetched in full (store resume, not the cache, avoids re-pulling a partial prefix today); partial-prefix complement is noted as a planned enhancement. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): consumption-pace the multi-source scheduler (#1848) Thread a ConsumptionPacing seam through multi_source_fetch to its per-lane workers, so a Streamer can bound a multi-source fetch to one read-ahead window ahead of a live consumer's read cursor — the keystone that lets the Downloader and Streamer become two configs over the one multi-source core instead of two engines. fill_gap already took `downstream` + `pacing_wait`; the scheduler just didn't pass them. Now multi_source_fetch (and run_worker) take `pacing: Option<&ConsumptionPacing>` and thread it to each worker's fill_gap. A WindowPacer then gates every lane against the shared consumer cursor: a lane whose delivered frontier runs a window past the cursor waits until the consumer reads more. `None` (every existing caller) keeps the eager, unbounded fan-out verbatim — the whole existing scheduler suite is unchanged. Test: a 1-lane fetch under WindowPacer + an injected consumer cursor completes byte-identical ONLY by parking on a full window and being unstuck via the pacing hook (proven to fail with cursor=0 when the seam is not threaded). Follow-up (Phase 2): the Streamer replaces its single-source drive with this consumption-paced multi_source_fetch (candidate failover + small-cap fan-out). Part of the Downloader/Streamer core-unification (spec 2026-09-22-multi-source-core-and-face-unification-design). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): Streamer on the multi-source core with candidate failover (#1848) Phase 2: replace the Streamer's single-source `drive` with the consumption-paced `multi_source_fetch`, so a stream fetches its front across a small, bounded set of provider candidates and fails over between them. - Streamer::new now takes a Vec<StreamCandidate> (source + paying ctx/ledger per provider) instead of one source. It drives multi_source_fetch with a WindowPacer(read_ahead) + the consumer cursor as the downstream frontier (ConsumptionPacing), capped to PullConfig::streamer_lane_cap (new tunable, default 2). VerifiedReader is unchanged. - A candidate that faults mid-stream is dropped and its remainder reassigned to another (shared-pool free failover, #1174), resuming from the store's verified frontier so no delivered byte is re-pulled or re-paid. - The no-verified-progress watchdog is off (unit_deadline ZERO): a paced stream parks lanes on the consumer cursor, which is not a stall — a genuinely silent source trips its own per-stream throughput floor instead. multi_source_fetch does not finalize, so the stream leaves the store at .partial (a stream is not kept as a file); the reader reads its checkpointed present frontier as before. Tests: a mid-stream candidate fault fails over and the drained stream is BLAKE3-identical (faulty candidate delivered a prefix first); the existing drain / tampered / cache / bounded tests all still pass on the multi-source core. Stacked on the Phase 1 scheduler change. Follow-up (Phase 3): Downloader reshaped onto this core as a wrapper (uncapped fan-out + dedup pre-seed). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): Downloader on the multi-source core (fan-out + dedup) (#1848) Phase 3: reshape the Downloader onto the same shared core the Streamer uses, uncapped for full-throughput download. - Downloader::new now takes a Vec<StreamCandidate> (the shared provider-candidate type) instead of one source + pacer + ctx + ledger. fetch_to_dir builds one lane per candidate and drives each entry across them through multi_source_fetch with a BudgetPacer, no consumption pacing, and max_sources = every candidate (uncapped fan-out), then finalizes — promoting .partial to the file. So the two faces are now one engine: the Streamer caps the fan-out and paces on the consumer cursor; the Downloader uncaps it and runs full throughput. - Failover comes for free (shared-pool reassign, #1174). A resumed download — an existing .partial, e.g. a bundle layer's chunk-hint dedup pre-seeded into it — re-pulls only its missing ranges. Tests: two candidates stripe one blob BLAKE3-identical with both contributing; a pre-seeded prefix is fetched only as its complement (dedup/resume); the single-candidate BLAKE3-identical path is unchanged (no regression). Full client-pull suite 321/321. Stacked on the Phase 2 Streamer change. Follow-up (Phase 4): CLI rewiring (bundle pull -> Downloader, decdn fetch -o - -> Streamer, decdn fetch -o file -> Downloader). Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(client-pull): reject an empty Downloader candidate set early Address Copilot review on #2112: `fetch_to_dir` now fails with a clear "needs at least one provider candidate" error before opening any store or building empty lane sets, instead of surfacing a less obvious fault deep inside multi_source_fetch on the first entry. Test locks the behaviour. (The other finding — an unused `RangedStore` import — is a false positive: the import is used by `store.finalize()`, a `RangedStore` trait method, and clippy under -D warnings is clean.) Co-Authored-By: Claude Opus 4.8 <[email protected]> * refactor(client-pull): let VerifiedReader borrow its sources (drop 'static) The Streamer required S: BlobSource + 'static, which the tests met (ScriptedSource is 'static) but a real PeerSource — which borrows &Endpoint — does not. Relax it: VerifiedReader / LiveReader gain a lifetime 'a, the drive future is boxed as `+ 'a` instead of 'static, and Streamer::open returns VerifiedReader<'a> with S: 'a, F: 'a. The store-read future still captures an Arc and stays 'static. This unblocks wiring the Streamer into `decdn fetch` (a borrowing PeerSource); behaviour is unchanged and the whole streamer/downloader suite still passes. Co-Authored-By: Claude Opus 4.8 <[email protected]> * docs(client-pull): describe ByteSink as it is — a seam with no production consumer The ByteSink module and trait docs claimed the Downloader "backs this with a file", but the Downloader writes its output through a ClientRangedStore (which promotes the verified .partial to the final file on finalize), never through ByteSink; the only implementor is a test Vec. Reword both doc sites to describe current behavior per the repo's present-tense-canon rule: ByteSink is an output seam with no production consumer yet, and the Streamer is what drives BlobCache. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): thread per-candidate coverage into the consumption faces (#1848) `StreamCandidate` gains an optional `coverage` field: the candidate's measured block coverage for the blob being fetched (#1506), or `None` to treat it as a full holder. Both faces build their lanes through a shared `source_lanes` helper that threads each candidate's coverage into its `SourceLane` (a `None` candidate maps to `Coverage::full` sized to the blob), replacing the hardcoded full-coverage assumption in `run_drive` and `fetch_to_dir`. This closes the no-regression gap before the CLI adopts the faces: today the inline multi-source path threads each node's real probed coverage, so a partial holder is never asked for a range it does not hold; without this the faces would ask a partial holder for its missing ranges. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): give the Downloader a progress hook (#1848) `fetch_to_dir` takes an optional `on_progress: Option<&ProgressCallback>` and forwards it into `multi_source_fetch`, so a CLI drawing a download bar gets the core's verified CONTENT progress for the entry currently fetching — `(position, total_bytes)`, both content bytes, resetting per entry. A single-entry download uses it directly; a multi-entry caller accumulates completed entries' totals itself. Previously the on_progress slot was hardcoded `None`, leaving the download face with no way to report progress. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): let the Downloader fetch to caller-chosen paths (#1848) Add `Downloader::fetch_to_paths(&[DownloadTarget], config, on_progress)`: each `DownloadTarget { hash, total_bytes, dest }` is fetched to its own `dest` path, with the `.partial` store and the promoted final file keyed by that name, so the finished file IS `dest` — no post-finalize rename, and a resumed download re-pulls only what it lacks. `fetch_to_dir` becomes a thin convenience over it that names each file by content-address hex under a directory (behavior unchanged). This is the surface the CLI needs to become a thin layer over the face: `decdn fetch -o <file>` writes one blob to that path, and `bundle pull` writes each entry to its manifest path. Also add `PullConfig::download_unit_deadline` (default 30s) and have the Downloader read it as the per-lane stall watchdog, replacing the hardcoded constant — so a CLI caller can keep honoring `--unit-deadline-ms`. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): let the Downloader share a bundle run's ledger registry (#1848) `Downloader::fetch_to_paths` gains an `ledgers: Option<&LaneLedgers>` parameter, threaded into `multi_source_fetch`. With a shared registry the core reads and credits EVERY lane registered across the run for its deposit-solvency view, so concurrent bundle entries drawing on ONE on-chain pool cannot jointly over-draw it; `None` folds only this fetch's own lanes, the right view for a solo download. `fetch_to_dir` delegates with `None`. This is the last surface `bundle pull` needs to run its per-entry whole-file fetch through the Downloader face (4a). Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(client-pull): don't materialize the whole blob to tee a non-caching sink (#1848) On a clean finish the `Streamer` teed the whole verified blob to its cache for a revisit — `store.read(0, total)` into one `Bytes`, then `cache.put`. That ran unconditionally, so `decdn fetch -o -` (which passes `NoCache`) read the entire blob into memory at the end of the stream just to hand it to a no-op cache and drop it, spiking a huge blob's whole size into RAM and defeating the point of a consumption-paced stream. `BlobCache` gains a `caches()` predicate (default `true`); `NoCache` returns `false`, and the tee's whole-blob read is now gated on it. A real cache still gets teed; a no-op one never triggers the read, so the stream stays memory-bounded (one read-ahead window) end to end. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(client-pull): drive the Streamer apart from its reads; unwedge a parked lane on a front fault The Streamer's fetch advanced only inside VerifiedReader::poll_read, and only once the buffered bytes were drained. While a slow or paused consumer held the reader, an open paid leg sent no vouchers and read no bytes, so the node's proof-read timeout or the client's own stall and throughput floors faulted the lane. Streamer::open now returns the reader plus a StreamDrive future the caller polls for the whole stream (StreamDrive::alongside runs a read loop beside it). The read-ahead window, not the reads, bounds how far it runs. The reader waits on the drive's progress wakeups and reads the verified prefix in bounded chunks. A drive dropped early ends the reader with an error instead of a hang. Under consumption pacing, a lane parked on a full window held a range that the consumer could never reach once a lane nearer the front faulted: its re-queued remainder had no free worker, and the stream hung with no bytes out. A parked lane now hands its range back when an earlier range it can serve waits in the queue, and a paced fetch picks the lowest-offset range first. read_ahead_bytes below PULL_WINDOW_FLOOR is raised to it; a smaller window could floor a lane's room to zero before the first byte and park forever. Tests: front-lane fault with a far-parked peer (hung before), a paused consumer still fills one window and no more, a sub-floor read-ahead completes, and the bounded read-ahead check at the effective floor. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01AZoHLSQnBwMc7sibyFC9E7 --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
thiras
pushed a commit
that referenced
this pull request
Sep 22, 2026
…es (#1848) (#2114) * feat(client-pull): reuse a warm connection across hashes (WarmConnection) Add WarmConnection: a caller-owned cdn/client/v1 connection dialled once and reused across many hashes, opening a fresh bi-stream per hash (one stream = one hash, no wire change). open_stream takes a ConnSource (dial a fresh one-shot connection or reuse a warm one); open_progressive_pull keeps the dial path and open_progressive_pull_on opens a pull on a warm connection. UpstreamPull now tracks whether it owns its connection: an owned one-shot dial is closed on the pull's terminal method, while a borrowed warm connection is left open for the next hash — only the current stream is torn down. The warm connection closes once, on its own Drop. Test: two distinct hashes fetched back-to-back over one WarmConnection dial the connection exactly once (client_loopback::two_hashes_reuse_one_warm_connection). Part of #1848 (T1). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): add PullConfig zero-config tunables scaffold Add config::PullConfig, the injected tunables the consumption faces (Downloader, Streamer, #1848) share. It holds only tunables, each with a sensible default, so PullConfig::default() is the whole configuration a caller needs; the required per-fetch inputs (identity, connection, spend budget, providers) stay on the engine's existing params, which is why PullConfig constructs with no network or chain access (proven by a const construction). The first tunable is the Streamer's read_ahead_bytes bound (default 16 MiB); more fields are added as Downloader (T4) and Streamer (T6) grow to consume them. The payment interval stays the fixed protocol const CHUNK_BYTES, not a tunable. Part of #1848 (T2). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): add ByteSink output + injected BlobCache traits Add the output side of a fetch to sink.rs (#1848 T3): - ByteSink: where the engine writes verified content bytes, at absolute offsets, so an out-of-order multi-source fetch lands each range at its position. The Downloader backs it with a file. - BlobCache: the injected (hash, offset) content cache the Streamer consults and fills. Pure — it names no blob store — so client-pull stays iroh-blobs-free; a blob-store-backed impl is injected from above. The default is the no-op NoCache (never hits, never stores). Both use the crate's boxed-future async-trait shape (SinkFuture). Test doubles VecByteSink and MemoryBlobCache ship under test-util for the Downloader/Streamer suites. check_crate_edges.py still passes (decdn-cli closure clean). Part of #1848 (T3). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): add Downloader (bundle/blob fetch-to-dir face) Add the Downloader consumption face (#1848 T4): fetch a set of content-addressed blobs — a bundle, or a single blob — to files in a directory. It is an output+scheduling adapter over the ONE paid pull engine, not a second engine: each (hash, total_bytes) entry opens a ClientRangedStore beside dir/<hex> and drives only its missing ranges through driver::drive, which bao-verifies every byte on ingest and promotes .partial to the final file on completion. So writes land out-of-order at their offsets, a resumed download re-pulls only what it lacks, and a bundle layer above can pre-seed held ranges (its chunk-hint dedup) into the store so the same drive fills only the complement. Bundles are the main scenario (a bundle is a set of entries → one file each, named by content-address hex; a single blob is a bundle of one). The pull machinery (source, pacer, funder, ctx, ledger) is injected and shared across every entry, so one provider connection and one payment channel serve a whole bundle. fetch_to_dir takes &PullConfig for symmetry with the Streamer; the Downloader fetches at full throughput, so no tunable changes its behaviour yet. decdn fetch / bundle pull are rewired onto this in later PRs. Part of #1848 (T4). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): add Streamer + VerifiedReader (consumption-paced fetch) Add the Streamer consumption face (#1848 T5+T6): stream one blob's verified, contiguous front to a consumer as it arrives, paced by how fast the consumer reads — the fetch-like, single-blob face (no chunk dedup, unlike the Downloader). One engine, two faces: the Streamer configures the SAME paid pull engine, not a second one. It drives the fetch through driver::drive with a WindowPacer whose window is PullConfig::read_ahead_bytes and whose downstream frontier is the CONSUMER'S read cursor — the bounded-read-ahead mode the driver already supports (window_pacer_gates_on_injected_served_paid), so T5 needs no engine change. The pull never runs more than one read-ahead window ahead of what the consumer has read, so a viewer who stops after five minutes never fetches (or pays for) the whole two-hour movie; that read-ahead bound IS the outstanding-spend bound. VerifiedReader is the tokio::io::AsyncRead the caller drains. It cooperatively polls the drive future inside poll_read and reads only the store's CHECKPOINTED present frontier, so it is clamped to the verified contiguous frontier by construction — a tampered chunk group fails the pull and surfaces as a read error rather than ever reaching the consumer. On a clean finish the whole verified blob is teed to the injected BlobCache; a revisit whose cache already holds the blob serves straight from memory and never touches the network. Tests: drained stream BLAKE3-identical; a tampered tail never surfaces (verified prefix only, then an error); a full cache hit fetches nothing; a slow consumer holds the in-flight bytes within the read-ahead bound. decdn fetch is rewired onto this in a later PR. Part of #1848 (T5, T6). Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(client-pull): surface store errors + fail-loud cursor in the Streamer Address Copilot review on #2108: - present_frontier no longer swallows a present_ranges() fault as "nothing present" (which could stall the reader or look like early EOF); it returns a Result and the read future surfaces it to the consumer. - The cursor advance converts the read length to u64 BEFORE handing out bytes and fails loudly on the (practically impossible) overflow, so the cursor can never desynchronize from bytes already delivered. - BlobCache docs now state the actual behaviour: a whole-blob cache hit serves without fetching, anything less is refetched in full (store resume, not the cache, avoids re-pulling a partial prefix today); partial-prefix complement is noted as a planned enhancement. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): consumption-pace the multi-source scheduler (#1848) Thread a ConsumptionPacing seam through multi_source_fetch to its per-lane workers, so a Streamer can bound a multi-source fetch to one read-ahead window ahead of a live consumer's read cursor — the keystone that lets the Downloader and Streamer become two configs over the one multi-source core instead of two engines. fill_gap already took `downstream` + `pacing_wait`; the scheduler just didn't pass them. Now multi_source_fetch (and run_worker) take `pacing: Option<&ConsumptionPacing>` and thread it to each worker's fill_gap. A WindowPacer then gates every lane against the shared consumer cursor: a lane whose delivered frontier runs a window past the cursor waits until the consumer reads more. `None` (every existing caller) keeps the eager, unbounded fan-out verbatim — the whole existing scheduler suite is unchanged. Test: a 1-lane fetch under WindowPacer + an injected consumer cursor completes byte-identical ONLY by parking on a full window and being unstuck via the pacing hook (proven to fail with cursor=0 when the seam is not threaded). Follow-up (Phase 2): the Streamer replaces its single-source drive with this consumption-paced multi_source_fetch (candidate failover + small-cap fan-out). Part of the Downloader/Streamer core-unification (spec 2026-09-22-multi-source-core-and-face-unification-design). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): Streamer on the multi-source core with candidate failover (#1848) Phase 2: replace the Streamer's single-source `drive` with the consumption-paced `multi_source_fetch`, so a stream fetches its front across a small, bounded set of provider candidates and fails over between them. - Streamer::new now takes a Vec<StreamCandidate> (source + paying ctx/ledger per provider) instead of one source. It drives multi_source_fetch with a WindowPacer(read_ahead) + the consumer cursor as the downstream frontier (ConsumptionPacing), capped to PullConfig::streamer_lane_cap (new tunable, default 2). VerifiedReader is unchanged. - A candidate that faults mid-stream is dropped and its remainder reassigned to another (shared-pool free failover, #1174), resuming from the store's verified frontier so no delivered byte is re-pulled or re-paid. - The no-verified-progress watchdog is off (unit_deadline ZERO): a paced stream parks lanes on the consumer cursor, which is not a stall — a genuinely silent source trips its own per-stream throughput floor instead. multi_source_fetch does not finalize, so the stream leaves the store at .partial (a stream is not kept as a file); the reader reads its checkpointed present frontier as before. Tests: a mid-stream candidate fault fails over and the drained stream is BLAKE3-identical (faulty candidate delivered a prefix first); the existing drain / tampered / cache / bounded tests all still pass on the multi-source core. Stacked on the Phase 1 scheduler change. Follow-up (Phase 3): Downloader reshaped onto this core as a wrapper (uncapped fan-out + dedup pre-seed). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): Downloader on the multi-source core (fan-out + dedup) (#1848) Phase 3: reshape the Downloader onto the same shared core the Streamer uses, uncapped for full-throughput download. - Downloader::new now takes a Vec<StreamCandidate> (the shared provider-candidate type) instead of one source + pacer + ctx + ledger. fetch_to_dir builds one lane per candidate and drives each entry across them through multi_source_fetch with a BudgetPacer, no consumption pacing, and max_sources = every candidate (uncapped fan-out), then finalizes — promoting .partial to the file. So the two faces are now one engine: the Streamer caps the fan-out and paces on the consumer cursor; the Downloader uncaps it and runs full throughput. - Failover comes for free (shared-pool reassign, #1174). A resumed download — an existing .partial, e.g. a bundle layer's chunk-hint dedup pre-seeded into it — re-pulls only its missing ranges. Tests: two candidates stripe one blob BLAKE3-identical with both contributing; a pre-seeded prefix is fetched only as its complement (dedup/resume); the single-candidate BLAKE3-identical path is unchanged (no regression). Full client-pull suite 321/321. Stacked on the Phase 2 Streamer change. Follow-up (Phase 4): CLI rewiring (bundle pull -> Downloader, decdn fetch -o - -> Streamer, decdn fetch -o file -> Downloader). Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(client-pull): reject an empty Downloader candidate set early Address Copilot review on #2112: `fetch_to_dir` now fails with a clear "needs at least one provider candidate" error before opening any store or building empty lane sets, instead of surfacing a less obvious fault deep inside multi_source_fetch on the first entry. Test locks the behaviour. (The other finding — an unused `RangedStore` import — is a false positive: the import is used by `store.finalize()`, a `RangedStore` trait method, and clippy under -D warnings is clean.) Co-Authored-By: Claude Opus 4.8 <[email protected]> * refactor(client-pull): let VerifiedReader borrow its sources (drop 'static) The Streamer required S: BlobSource + 'static, which the tests met (ScriptedSource is 'static) but a real PeerSource — which borrows &Endpoint — does not. Relax it: VerifiedReader / LiveReader gain a lifetime 'a, the drive future is boxed as `+ 'a` instead of 'static, and Streamer::open returns VerifiedReader<'a> with S: 'a, F: 'a. The store-read future still captures an Arc and stays 'static. This unblocks wiring the Streamer into `decdn fetch` (a borrowing PeerSource); behaviour is unchanged and the whole streamer/downloader suite still passes. Co-Authored-By: Claude Opus 4.8 <[email protected]> * docs(client-pull): describe ByteSink as it is — a seam with no production consumer The ByteSink module and trait docs claimed the Downloader "backs this with a file", but the Downloader writes its output through a ClientRangedStore (which promotes the verified .partial to the final file on finalize), never through ByteSink; the only implementor is a test Vec. Reword both doc sites to describe current behavior per the repo's present-tense-canon rule: ByteSink is an output seam with no production consumer yet, and the Streamer is what drives BlobCache. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): thread per-candidate coverage into the consumption faces (#1848) `StreamCandidate` gains an optional `coverage` field: the candidate's measured block coverage for the blob being fetched (#1506), or `None` to treat it as a full holder. Both faces build their lanes through a shared `source_lanes` helper that threads each candidate's coverage into its `SourceLane` (a `None` candidate maps to `Coverage::full` sized to the blob), replacing the hardcoded full-coverage assumption in `run_drive` and `fetch_to_dir`. This closes the no-regression gap before the CLI adopts the faces: today the inline multi-source path threads each node's real probed coverage, so a partial holder is never asked for a range it does not hold; without this the faces would ask a partial holder for its missing ranges. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): give the Downloader a progress hook (#1848) `fetch_to_dir` takes an optional `on_progress: Option<&ProgressCallback>` and forwards it into `multi_source_fetch`, so a CLI drawing a download bar gets the core's verified CONTENT progress for the entry currently fetching — `(position, total_bytes)`, both content bytes, resetting per entry. A single-entry download uses it directly; a multi-entry caller accumulates completed entries' totals itself. Previously the on_progress slot was hardcoded `None`, leaving the download face with no way to report progress. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(cli): stream decdn fetch -o - to stdout over the Streamer face (#1848) `decdn fetch -o -` now streams a blob's bao-verified bytes straight to stdout through the `decdn_client_pull::Streamer` consumption face, instead of writing a file literally named `-`. A file named `-` is still writable as `./-`. The path is thin over the face: it builds the candidate lanes exactly as the multi-source file path does (per-provider pool, ctx, ledger, real probed coverage threaded into each StreamCandidate), then opens a VerifiedReader and copies it to stdout. Only bao-verified bytes ever reach the pipe (safe to `| tar x`); the fetch is consumption-paced, so a slow or early-quit consumer stops the pull — and the spend — within one read-ahead window; a candidate that faults mid-stream fails over to another with no re-pull or re-pay. There is no resume-to-disk on a pipe. Progress draws on stderr and is suppressed when stdout is not a TTY, so a piped consumer sees clean bytes. Each lane's voucher watermark is persisted after the stream, exactly as the file path does — the face does not persist, so this thin CLI layer keeps doing it. Verified end-to-end (`cli_fetch_stdout`, anvil-gated): a real paid stream to a real node produces byte-identical stdout and a non-zero persisted watermark. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(cli): fail over the stdout stream's header probe across candidates (#1848) Address review of the `decdn fetch -o -` path: - Clamp `--max-sources` to at least one when admitting sources, so `0` no longer yields an empty admitted set (an immediate "no candidate holders" error) — the Streamer already caps at >=1 lane. - Learn `total_bytes` by failing over the header-only open ACROSS the admitted lanes until one answers, instead of only probing the first. An unreachable or refusing first holder no longer sinks the whole stream when others are healthy, so `-o -` gets candidate failover end to end. - Do not suppress a candidate for an `InsufficientDeposit` refusal (our deposit vs the node's floor, not a peer fault), mirroring `open_fetch_prelude`. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): let the Downloader fetch to caller-chosen paths (#1848) Add `Downloader::fetch_to_paths(&[DownloadTarget], config, on_progress)`: each `DownloadTarget { hash, total_bytes, dest }` is fetched to its own `dest` path, with the `.partial` store and the promoted final file keyed by that name, so the finished file IS `dest` — no post-finalize rename, and a resumed download re-pulls only what it lacks. `fetch_to_dir` becomes a thin convenience over it that names each file by content-address hex under a directory (behavior unchanged). This is the surface the CLI needs to become a thin layer over the face: `decdn fetch -o <file>` writes one blob to that path, and `bundle pull` writes each entry to its manifest path. Also add `PullConfig::download_unit_deadline` (default 30s) and have the Downloader read it as the per-lane stall watchdog, replacing the hardcoded constant — so a CLI caller can keep honoring `--unit-deadline-ms`. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(cli): route decdn fetch -o file through the Downloader face (#1848) The multi-source engagement for `decdn fetch -o <file>` now runs through the `decdn_client_pull::Downloader` face instead of the CLI calling `multi_source_fetch` inline. `download_to_file` applies the same gate (pre-probe and authoritative-header size checks), builds one payment lane per admitted candidate, then hands the candidate set to `Downloader::fetch_to_paths` with the output path — the face stripes across the holders, fails over between them, bao-verifies every byte, and promotes the `.partial` beside `--output` to `--output` (keyed by that name, so resume is unchanged). `--unit-deadline-ms` is honored via `PullConfig::download_unit_deadline`, and each lane's watermark is persisted after, exactly as before. When the gate declines (blob below the fan-out floor, or fewer than two operator-distinct holders), it returns `Ok(None)` and the single-source failover loop and store-fast-path rediscovery run unchanged — no regression. The stdout path (4b) and this file path now share three helpers: `build_admitted_lanes_and_total` (lane build + header-probe failover), `split_face_lanes` (MultiLane -> StreamCandidate + watermark handle), and `persist_face_watermarks`. The now-unused `try_multi_source_fetch` wrapper is removed; `bundle pull` keeps using `try_multi_source_fetch_from_admitted`. Verified end-to-end (anvil): cli_fetch_multi_source (the file path's multi-source engagement, now through the Downloader), cli_fetch_resume, cli_fetch_topup, cli_fetch_delegated, and cli_fetch_stdout all pass. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): let the Downloader share a bundle run's ledger registry (#1848) `Downloader::fetch_to_paths` gains an `ledgers: Option<&LaneLedgers>` parameter, threaded into `multi_source_fetch`. With a shared registry the core reads and credits EVERY lane registered across the run for its deposit-solvency view, so concurrent bundle entries drawing on ONE on-chain pool cannot jointly over-draw it; `None` folds only this fetch's own lanes, the right view for a solo download. `fetch_to_dir` delegates with `None`. This is the last surface `bundle pull` needs to run its per-entry whole-file fetch through the Downloader face (4a). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(cli): route bundle pull's whole-file fetch through the Downloader (#1848) `bundle pull`'s per-entry whole-file multi-source engagement now runs through the `Downloader` face, the last CLI fetch path still calling `multi_source_fetch` inline. Its `try_multi_source` hands its already-admitted candidate set — plus the bundle-wide open lock and shared `LaneLedgers` registry — to the new shared `fetch::multi_source_download`, which builds one lane per candidate, applies the authoritative header size gate, and fetches to the entry's staging path via `Downloader::fetch_to_paths` (threading the shared registry so concurrent entries keep one solvency view of the deposit). The range-dedup / chunk-hint splice path (`drive_ranges_ordered`) is untouched, so chunk-hint dedup keeps working exactly as before; the whole-file path is the one that now goes through the face. Refactor: `download_to_file` (4c) and bundle now share `multi_source_download`; the shared `build_admitted_lanes_and_total` grew `open_lock`/`ledgers` parameters. The inline `try_multi_source_fetch_from_admitted` and its `lane_watermarks` helper — the last direct `multi_source_fetch` callers in the CLI — are removed. Every CLI fetch path (`decdn fetch -o -`, `-o <file>`, and `bundle pull`) now goes through a consumption face. Verified end-to-end (anvil), no regression: cli_bundle_pull_multi_source (the whole-file path, now through the Downloader), _pool_id, _range_dedup (dedup, self-heal, from-optimize, cross-run reuse, shared-lane concurrency), plus cli_fetch_multi_source and cli_fetch_resume. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(client-pull): don't materialize the whole blob to tee a non-caching sink (#1848) On a clean finish the `Streamer` teed the whole verified blob to its cache for a revisit — `store.read(0, total)` into one `Bytes`, then `cache.put`. That ran unconditionally, so `decdn fetch -o -` (which passes `NoCache`) read the entire blob into memory at the end of the stream just to hand it to a no-op cache and drop it, spiking a huge blob's whole size into RAM and defeating the point of a consumption-paced stream. `BlobCache` gains a `caches()` predicate (default `true`); `NoCache` returns `false`, and the tee's whole-blob read is now gated on it. A real cache still gets teed; a no-op one never triggers the read, so the stream stays memory-bounded (one read-ahead window) end to end. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(client-pull): drive the Streamer apart from its reads; unwedge a parked lane on a front fault The Streamer's fetch advanced only inside VerifiedReader::poll_read, and only once the buffered bytes were drained. While a slow or paused consumer held the reader, an open paid leg sent no vouchers and read no bytes, so the node's proof-read timeout or the client's own stall and throughput floors faulted the lane. Streamer::open now returns the reader plus a StreamDrive future the caller polls for the whole stream (StreamDrive::alongside runs a read loop beside it). The read-ahead window, not the reads, bounds how far it runs. The reader waits on the drive's progress wakeups and reads the verified prefix in bounded chunks. A drive dropped early ends the reader with an error instead of a hang. Under consumption pacing, a lane parked on a full window held a range that the consumer could never reach once a lane nearer the front faulted: its re-queued remainder had no free worker, and the stream hung with no bytes out. A parked lane now hands its range back when an earlier range it can serve waits in the queue, and a paced fetch picks the lowest-offset range first. read_ahead_bytes below PULL_WINDOW_FLOOR is raised to it; a smaller window could floor a lane's room to zero before the first byte and park forever. Tests: front-lane fault with a far-parked peer (hung before), a paused consumer still fills one window and no more, a sub-floor read-ahead completes, and the bounded read-ahead check at the effective floor. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01AZoHLSQnBwMc7sibyFC9E7 * fix(cli): drive the stdout stream beside the copy; build fan-out lanes after the size gate `decdn fetch -o -` now runs the Streamer's drive beside the stdout copy (StreamDrive::alongside), so a blocked pipe no longer stops an open paid leg from paying and draining; the read-ahead window bounds how far it runs ahead. The stream also honors the multi-source kill switch (one lane at a time, the other holders stay failover candidates), draws its bar only when stderr is a terminal, and annotates an unbound-namespace cache miss on failure like the file path. probe_admitted_total builds lanes one candidate at a time and stops at the first holder that answers the header open. The file download and bundle pull build the remaining lanes only once the authoritative size gate engages, so a declined fan-out opens no extra pool and takes no extra open_lock turn. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01AZoHLSQnBwMc7sibyFC9E7 --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Stacked on #2111 (→ #2110 → #2108). Phase 3 of the Downloader/Streamer core-unification — the two faces are now one engine.
What & why
Reshapes the
Downloaderonto the same shared core theStreameruses (#2111), uncapped for full-throughput download:Downloader::newnow takes aVec<StreamCandidate>(the shared provider-candidate type) instead of one source + pacer + ctx + ledger.fetch_to_dirbuilds one lane per candidate and drives each entry across them throughmulti_source_fetchwith aBudgetPacer, no consumption pacing, andmax_sources= every candidate (uncapped fan-out), then finalizes — promoting.partialto the file.streamer_lane_cap) and paces on the consumer cursor; the Downloader uncaps it and runs full throughput. One resilience/verify/failover path..partial, e.g. a bundle layer's chunk-hint dedup pre-seeded into it — re-pulls only its missing ranges.Tests
client-pullsuite: 321/321.Follow-up
bundle pull→Downloader,decdn fetch -o -→Streamer,decdn fetch -o file→Downloader (behavior-preserving).Design spec:
~/Workspace/decdn/specs/2026-09-22-multi-source-core-and-face-unification-design.md.🤖 Generated with Claude Code