Repository navigation
feat(cli): bundle pull via chunk-hint range dedup (whole-file blobs) - #1982
Conversation
…ource_fetch multi_source_fetch takes an optional run-wide LaneLedgers registry. When present, the deposit gate's spent/credit span every lane the bundle-pull run has registered, not just this fetch's own lanes, so concurrent fetches sharing a deposit gate correctly. When absent, behavior is unchanged: the gate folds over only this fetch's lanes, as a solo `decdn fetch` always did.
…lane deposit on reuse Code-review fixes for bundle-pull-parallel-shared-ledger: - bundle_pull.rs: pull_plain/pull_chunked's outer streams were widened to buffer_unordered(len), instantiating one live progress bar per manifest entry/group before it ever acquires PullCtx.gate — a terminal-flooding regression on large bundles. Re-bound both outer streams at --jobs (new PullCtx.jobs field) while leaving the inner per-chunk stream and the global gate untouched, so a many-chunk file still saturates --jobs. - fetch.rs: lane_ledger discarded a freshly-built PoolContext on a registry-reuse touch, even when open_or_reuse_pool had just performed a low-water top-up raising the on-chain deposit above the registry's stored value. The pool-wide spent/credit gate reads that stale value and could refuse (PoolExhausted) prematurely. Reconcile the shared handle's ctx.deposit upward to the fresher reading on every touch (a no-op when the touch's own build won the registry race). - bundle_pull.rs: drop stray changelog-voice "now" from two comments. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Chunked-file fan-out currently buffers one future per chunk (buffer_unordered(chunks.len())), which can cause avoidable memory/scheduling blowups on very large chunked files despite the semaphore already bounding real I/O concurrency.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR makes decdn bundle pull truly parallel by introducing a run-scoped per-lane voucher-ledger registry so concurrent pulls on the same (pool_id, signer, provider) lane share one monotonic issuer, while also enforcing a pool-wide “spent” view to prevent concurrent disjoint-lane fetches from over-issuing against a single deposit.
Changes:
- Add
LaneLedgersregistry ((pool_id, signer, provider) -> LaneHandle) and thread it through both multi-source and single-source fetch paths so lanes share oneArc<PoolLedger>+ shared context. - Replace bundle-pull serialization with a global
--jobssemaphore gating all blob fetches (whole blobs and chunks), and fan out chunks within a file concurrently. - Update CLI docs/defaults (
--jobsdefault 4 → 16) and add unit + anvil e2e coverage for the new concurrency/payment invariants.
File summaries
| File | Description |
|---|---|
| crates/e2e/tests/cli_bundle_pull_concurrent_chunks.rs | New anvil-backed e2e validating concurrent chunk assembly and exactly-once payment watermarking. |
| crates/common/src/cli/bundle.rs | Redefines --jobs as global concurrent blob-fetch cap and raises default to 16. |
| crates/client-pull/src/scheduler.rs | Adds optional LaneLedgers to enable pool-wide spent/credit across a run; adds unit test for pool-wide gating. |
| crates/client-pull/src/lib.rs | Exposes new ledgers module and re-exports registry types. |
| crates/client-pull/src/ledgers.rs | Implements the run-scoped (lane -> ledger+ctx) registry plus helpers (total_committed, credit_all) with unit tests. |
| crates/cli/src/commands/fetch.rs | Threads optional registry into fetch/drive paths and uses registry-backed pool-wide gating when present. |
| crates/cli/src/commands/bundle_pull.rs | Removes per-lane locks + pool-serial mutex; adds global semaphore gate; enables per-file chunk fan-out under --jobs. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…rallel-chunks-54c2bc
…at --jobs Merging main brought in a new multi_source_fetch test caller (PR #1978) that predates the ledgers parameter; pass None there. Also bound the per-file chunk stream at --jobs (buffer_unordered) so a file with very many chunks no longer buffers one future per chunk — the global gate is the real in-flight-fetch cap (addresses the Copilot review note). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Addressed the review + a merge-integration fix in bb907f8:
Green locally after the merge: full workspace |
Coverage reportTotal: 82.65% (was 82.78%, ▼ 0.13%) — 77690/93997 lines
History
|
…-dedup Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ints Flip --optimize to store each file as one whole-file blob + its .obao4 outboard, exactly like a plain import, and emit the chunk list only as manifest dedup hints. Previously --optimize stored per-chunk blobs and left the whole-file blob unstored; nodes serving whole files (already supported) is what makes client-side range dedup possible later. import_optimized_file streams the file twice: import_one_file writes the whole-file blob once, then a no-op-sink chunk_file pass computes the hint list, with its whole_hash/total_size cross-checked against the written blob to catch a concurrent-modification read race. Drops the chunks_written status counter (there is no longer a dedup-storage count to report); chunks_total is now the chunk-hint count. Updates the existing optimize integration tests to assert whole-file storage instead of per-chunk storage. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…zed partial Adds the two client-side primitives the range-dedup hints work needs: complement_runs (pure range math, unit-tested) turns a donor's covered byte ranges into the gaps still worth a paid pull, and drive_ranges opens a blob's pool + ranged store once and drives a set of ranges into its .partial without finalizing, so a later assembly step can promote it once donor bytes fill the rest. Factors drive_fetch's handshake/store-open/source-build prelude into open_fetch_prelude so both functions share it instead of duplicating it; drive_fetch's own tests continue to pass unchanged, confirming the refactor is behavior-preserving. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Treat a bundle entry's chunk list as a range-dedup hint rather than a per-chunk fetch plan. Every entry is fetched and verified by its authoritative whole-file BLAKE3; when a chunk it names is already materialized on disk by a sibling entry this run, the fetch pays only for the complement (the group-aligned bytes no donor covers) and splices the rest from the sibling's finalized blob. - `pull_entry` replaces the per-chunk `pull_chunked`/`pull_chunked_file` path: plan the dedup against a run-wide `ChunkIndex`, drive only the complement into the entry's `.partial`, splice each donor range after re-hashing the whole donor chunk against its hint hash (a lying donor hint or short read falls back to a paid re-fetch), then verify the reassembled `.partial` against the whole-file hash. A lying recipient hint (wrong placement) is caught by that check and recovered by re-driving the full blob. - `drive_ranges` now persists the lane's voucher watermark once its ranges are driven, exactly as `drive_fetch` does (committed on success, settlement HIGH on ambiguous failure), so a failed or resumed chunked pull never re-pays a byte already bought. - Delete the per-chunk path (`ChunkCell`, `ChunkedPlan`, `plan_chunked`, `assemble_plan`, `parse_chunk_hashes`, `assemble_chunks`, the chunked progress-bar API) and unify `pull_all` on one by-hash grouping through `pull_entry`. A donor's finalized staging blob is kept until the run ends, then swept. - Remove the per-chunk-blob shared-chunk e2e; its premise (chunk as standalone blob) is gone. A range-dedup e2e lands in a later task. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Add pure unit tests for splice_donors/chunk_verified/copy_exact/ hash_partial: a happy-path subset copy that lands the correct bytes at the recipient offset with an empty refetch list, a corrupted-donor case that is pushed to refetch with no bytes written, plus direct chunk_verified/copy_exact/hash_partial coverage. Verified the corrupted-donor test genuinely bites by temporarily short-circuiting chunk_verified to always return true (test failed as expected), then reverted. Co-Authored-By: Claude Sonnet 5 <[email protected]>
An optimized bundle stores each file as one whole-file blob; its manifest chunks list is an advisory range-dedup hint, never a separately stored or fetched blob. Rewrite appendix-bundles.md's Chunked files/Generation/Pull sections in present-tense ASD-STE100 to match, and sweep stale comments in manifest.rs, chunker.rs, and bundle_pull.rs that still described chunks as stored/served/ concatenated blobs. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…of re-downloading Two files sharing a 4 MiB chunk-group-aligned run are pulled from one node in a single `decdn bundle pull` invocation. Asserts byte/BLAKE3-exact output, that the shared lane bills exactly the first file's whole-file wire size plus the second file's complement wire size (strictly less than re-downloading both whole files), and that a lone non-overlapping file bills exactly its whole-file wire size (dedup parity). Co-Authored-By: Claude Sonnet 5 <[email protected]>
On the range-dedup self-heal paths, re-driving ranges that complete the blob lets `drive` finalize and rename `<hex>.partial` -> `<hex>`, after which `hash_partial`/`promote_partial` operate on a `.partial` that no longer exists and the entry fails spuriously even though `drive` already bao-verified the whole blob against the manifest hash. Guard both self-heal re-drives (the all-donors-corrupt refetch and the whole-file-mismatch `[(0,total)]` re-drive): if the finalized `staging` now exists, the blob is verified and promoted, so register the donor chunks and return `Ok` instead of hashing an absent `.partial`. The happy dedup path (complement-only drive) never completes the blob, so `staging` does not exist there and the splice+hash+promote flow is unchanged. Add an anvil e2e that arms the self-heal with a lying recipient hint (a real donor chunk placed where the recipient's bytes differ, so the donor splice verifies but the whole-file BLAKE3 mismatches). It runs the measured pull single-shot so the serve-race retry loop cannot mask the bug; without the guard it fails with `open <hex>.partial: No such file`. Also soften the `downloaded` metric docs (range-dedup does not lower it below `reconstructed` on a single-path blob) and note the ~2x staging disk retention until the run-end sweep. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…rallel-chunks-54c2bc # Conflicts: # crates/cli/src/commands/pull_progress.rs
Add cli_bundle_pull_from_optimize_import_dedups: runs the real `decdn origin import --optimize` over an on-disk source tree (pinning --chunk-avg/--chunk-min/--chunk-max to fastcdc's MINIMUM_MAX so the chunker degenerates to fixed-size cuts landing on the shared/tail seam), asserts the import wrote whole-file blobs + outboards (and no separately-stored chunk-hash objects), serves the import store's actual bytes (manifest + both whole files) from a NodeFixture, and `bundle pull --hash`es the import-emitted bundle hash. Closes the gap where the existing range-dedup e2e seeds whole-file blobs directly and hand-builds the manifest, never exercising the import -> hint -> pull seam. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Correctness review (head
|
A chunk is no longer a fetch unit; each distinct blob is one unit of work holding one --jobs slot across its complement drive, donor splice, and any re-fetch. Rewrite the stale help text (present tense) to match (PR #1982 review item 6). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ress Address PR #1982 review (money-band correctness on the bundle chunk-hint range-dedup path). All in crates/cli/src/commands/bundle_pull.rs. - #1 (resume): after the FIRST complement drive, check staging.try_exists() and return success when the drive finalized the blob (a resumed run whose .partial already held the donor-overlap ranges) instead of opening a now-renamed .partial and failing the entry. Same guard shape already used after the refetch and whole-blob re-drives; now covers all three. The dedup reassembly is extracted into reassemble_dedup over a RangeDriver trait so this seam is unit-testable without a live endpoint or pool. - #2 (bad hint = re-download, never fail): plan_dedup skips a donor whose registered length disagrees with the recipient's claimed length (leaves the range in the paid, bao-verified complement); splice_donors treats a per-donor seek/copy error (a mismatched span or truncated donor that would EOF) as untrusted -> refetch rather than a fatal error. - #3 (never re-pay a paid blob): a donor group whose blob is fetched and registered but whose materialize failed is mark_retained on the ChunkIndex, and the run-end sweep skips retained sources, so a rerun resumes from the finalized <hex> instead of re-driving and re-paying the whole blob. - #4 (progress): on any dedup-path success, true the file + total bars up to 100% (spliced donor bytes never flow through drive's progress callback). Monotonic, so paths already at 100% are unaffected; the plain-entry path is untouched. - #5 (one probe per entry): resolve the range-drive provider order once per dedup entry and thread it into every sub-drive, so a self-heal entry no longer re-probes up to 3x. Happy path still probes once. - #7: inline should_remove_staging (now just !any_failed), reconciled with #3. Regression tests (each shown to bite pre-fix): reassemble_dedup succeeds when the first drive finalizes (#1); plan_dedup skips a length-mismatched donor and splice_donors refetches an EOF-ing copy (#2); the run-end sweep keeps a retained donor and removes a normal one (#3). cli unit suite green; the anvil e2e (cli_bundle_pull_range_dedup, incl. self-heal) passes, confirming the extraction is behavior-preserving. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
All seven addressed in
Green: |
Review (5-agent pass: code, tests, silent failures, docs, type design)Design is sound: donor chunks are re-hashed before splice, complement ranges are bao-verified at their true positions, the whole-file BLAKE3 is the sole promotion gate, splices never enter Critical
Important
Suggestions
Strengths
🤖 Generated with Claude Code |
…den self-heal test Address the still-live code findings from the second review of the bundle chunk-hint range-dedup path (money-band). Critical-4: the self-heal e2e asserted a cumulative `paid >= wire_min` that the warm-up already satisfied, so it could not tell the self-heal path from a plain fetch. Snapshot the lane watermark after the warm-up and assert the measured run's EXACT delta: a's whole file plus b's complement plus b's re-driven head. Harden `run_bundle_pull_until_ready` to bail on a non-transient reconstruction fault instead of absorbing (and re-paying for) it via the serve-race retry. Important-5: an already-finalized `<hex>` staging blob has no `.ranges` sidecar (promotion deletes it), so re-driving it would `open_or_create` -> `create` -> truncate and re-pay for the whole blob. `pull_entry` now hash- verifies an existing staging once and materializes from it, never re-driving. The misleading "no-op" comment is corrected to the real invariant. Important-6: `LaneLedgers::credit_all` locked each lane `ctx` while holding the map lock — the inverse of the driver's ctx-then-map order, a latent deadlock. It now clones the ctx handles under the map lock, releases it, then writes each deposit, and recovers a poisoned ctx with `into_inner` like the other methods (making it infallible). Important-12: the CLI installs no tracing subscriber, so ignored-hint and self-heal `warn!`/`debug!` lines were no-ops and a bundle whose hints all lie paid an unhinted price with an identical summary. `PullReport` now carries `spliced_bytes` (bytes served from a local donor splice) and `hints_ignored` (hints dropped by a fault), surfaced in both the human summary and `--json`. Reporting only; payment is unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…(default 1) Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ped model Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ures CI runs `clippy --workspace --all-targets` (no --all-features); the range-dedup + --max-lane-streams locals pushed main's aggregated future 48 bytes over the 16 KiB large_futures threshold. Boxing run() keeps main's future off the stack. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…rallel-chunks-54c2bc # Conflicts: # crates/cli/src/commands/pull_progress.rs
|
Second review round addressed (head Critical
Important
Also: Suggestions (newtypes, |
…rallel-chunks-54c2bc # Conflicts: # crates/cli/src/commands/pull_progress.rs
Summary
Reworks
decdnbundles so that chunks are client-side range-dedup hints, not stored/served blobs — fixing why chunk-dedupped (--optimize) pulls were slow and node-storming.The original slowness was per-chunk round-trips: each chunk was a separate
cdn/client/v1blob (probe + QUIC open + signed StreamRequest/StreamResponse + voucher per chunk), so a ~13.7 GB model was ~3,400 round-trips. This branch replaces that with whole-file range pulls plus client-side dedup.What changed
origin import --optimizenow stores each file as ONE whole-file blob (+.obao4outboard) — range-servable, exactly like a plain import — and emits the manifest'schunkslist as advisory{hash, size}hints. No chunk blobs are stored; a chunk hash is not independently addressable; nodes serve whole files only.bundle pullfetches a chunked entry by pulling only the complement of the ranges it already holds this run (sub-rangedrive, bao-verified against the whole-file hash), splicing the held ranges in locally (each verified by re-hashing the whole donor chunk against its hint hash), and promoting on a whole-file BLAKE3 == manifest hash check. A wrong/lying hint self-heals by re-fetching; it can never corrupt output.LaneLedgerspayment concurrency (this branch's earlier work) is kept and now governs concurrent whole-file fetches.--jobsdefault lowered to 4.adr/appendix-bundles.mdrewritten to the hint model. No wire/contract/node-serve change.Trust / money-safety
Complement ranges are bao-verified against the whole-file hash at their true positions; donor splices are chunk-hash verified; the whole-file BLAKE3 is the sole promotion gate.
drive_rangespersists the lane voucher watermark, so a resumed/failed pull never re-pays, and shared bytes are never paid for twice.Testing
complement_runs,plan_dedup/hints_of, and the splice byte-path (splice_donors/chunk_verified/copy_exact/hash_partial) including a corrupted-donor→refetch case.cli_bundle_pull_range_dedup: an optimized bundle with a shared aligned run payswire(A) + wire(B_complement)— the shared range is spliced locally, not re-downloaded — plus a lying-hint self-heal test (verified to fail without the fix).cargo nextest3426 passed / 0; clippy--all-targets --all-features -D warnings, doc gate,cargo denyclean.Known follow-ups (v1 scope)
materializeis a follow-up.🤖 Generated with Claude Code