Repository navigation
fix(client-pull): surface resume base on the progress bar before the first chunk - #1978
Merged
Merged
Conversation
…first chunk A partially-downloaded file's per-file progress bar sat at 0 through the pre-fetch window (discovery, channel open, pool resolve) even though bytes were already present on disk from a prior interrupted run, then jumped to the resume point once the first chunk arrived. The delivery reporter only fires from inside `ingest_stream` once streaming begins, reporting `base_present + received`, so the already-present base was never surfaced until the first delivered byte. Emit the resume base once before the pre-fetch window: in single-source `drive` before the gap loop, and in `multi_source_fetch` right after the aggregator is seeded to `base_present`. The value is exactly what the reporter emits at `received == 0` — content bytes, matching the reporter's own unit and whole-blob `total_bytes` denominator (the driver path is content-metered end to end; the `ProgressCallback` "wire" doc covers only the legacy `receive_and_pay` path). In multi-source the aggregator already holds `base_present` and lanes fold only leg deltas on top, so emitting the seed is a display, not a fold — no double-count. Affects `decdn fetch` and `decdn bundle pull`; node-to-node serve legs pass `on_progress = None`, so they are unaffected. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
ProgressCallback is documented as reporting wire bytes, but these paths emit content-byte progress, so the public API documentation should be updated or the callback types split to prevent unit confusion.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes resumed-download progress reporting in the decdn-client-pull crate so per-file progress bars start at the already-downloaded “resume base” immediately, rather than staying at 0 until the first chunk is delivered.
Changes:
- Emit a one-time
on_progress(base_present, total_bytes)update before any streaming begins in the single-sourcedrivepath. - Emit the same “seed value” before workers start in
multi_source_fetch, so the multi-source progress bar reflects already-present bytes during discovery/channel-open/pool-resolve. - Add resume-scenario tests for both paths to assert the first progress sample equals the resume base (not
0orbase + first_chunk).
File summaries
| File | Description |
|---|---|
| crates/client-pull/src/driver.rs | Emits initial resume-base progress before the gap loop; adds a single-source resume progress test. |
| crates/client-pull/src/scheduler.rs | Emits initial resume-base progress after seeding the shared aggregator; adds a multi-source resume progress test. |
Review details
- Files reviewed: 2/2 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.
…s content) The `ProgressCallback` doc claimed both counts are wire bytes, but only the legacy `stream_fetch*`/`receive_and_pay` path reports wire; the resumable `drive`/`multi_source_fetch` path the CLI actually uses reports content bytes. Document both call sites so callers don't misread units. No behavior change — each path keeps both slots in one self-consistent unit, so a bar keyed on `(received, expected)` fills to 100% either way. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Coverage reportTotal: 82.63% (was 82.61%, ▲ +0.02%) — 76263/92298 lines
History
|
alpergundogdu
added a commit
that referenced
this pull request
Sep 10, 2026
…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]>
alpergundogdu
added a commit
that referenced
this pull request
Sep 14, 2026
…parallelism (#1982) * feat(client-pull): add run-scoped LaneLedgers registry * feat(client-pull): pool-wide spent/credit from LaneLedgers in multi_source_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. * feat(cli): source per-lane ledger from LaneLedgers on both fetch paths * refactor(cli): replace pool_serial + LaneLocks with shared LaneLedgers * feat(cli): global bundle-pull concurrency gate (semaphore) over all blob fetches * feat(cli): fetch a chunked file's chunks concurrently under the global gate * feat(cli): default bundle-pull --jobs to 16, redocumented as global blob-fetch cap * docs(cli): bundle-pull + ledgers comments describe concurrent shared-ledger delivery * test(e2e): concurrent chunked-file bundle pull from one node pays once * fix(cli): bound bundle-pull live bar fan-out at --jobs and reconcile 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]> * fix(cli): thread ledgers arg into merged caller; bound chunk fan-out 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]> * chore(cli): retire per-chunk-fanout jobs default + e2e ahead of range-dedup Co-Authored-By: Claude Sonnet 5 <[email protected]> * feat(cli): origin import --optimize stores whole-file blobs + chunk hints 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]> * feat(cli): drive_ranges fetches a set of blob ranges into an unfinalized 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]> * feat(cli): bundle pull dedups chunk-hint ranges against an in-run index 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]> * test(cli): unit-test the range-dedup splice byte path 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]> * docs: bundles use chunks as range-dedup hints, not stored blobs 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]> * test(e2e): optimized bundle pull dedups an overlapping range instead 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]> * fix(cli): bundle self-heal must not hash a promoted .partial 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]> * test(e2e): drive bundle range-dedup from a real origin import --optimize 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]> * docs(cli): correct bundle pull --jobs help for range-dedup entries 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]> * fix(cli): harden bundle range-dedup resume, planning, sweep, and progress 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]> * fix(cli): report range-dedup outcomes, fix credit_all lock order, harden 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]> * feat(cli): --max-lane-streams caps concurrent same-lane bundle pulls (default 1) Co-Authored-By: Claude Opus 4.8 <[email protected]> * docs: correct bundle range-dedup docs, ADRs, and comments to the shipped model Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(cli): box the top-level run() future to satisfy clippy::large_futures 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]> --------- 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.
What
A partially-downloaded file's per-file progress bar (in
decdn fetchanddecdn bundle pull) sat at 0 through the pre-fetch window — discovery, channel open, pool resolve — even though bytes were already present on disk from a prior interrupted run, then jumped to the resume point once the first chunk arrived.This surfaces the already-present resume base on the bar immediately, so a resumed file's bar starts at its true resume position.
Why it happened
The delivery progress reporter lives inside
fill_gapand is only invoked from withinstore.ingest_stream(...)— i.e. once bytes actually stream. It reportsbase_present + received, so the already-present base (base_present) was never surfaced until the first delivered byte.The fix
Emit the resume base once, before the pre-fetch window, on each path:
crates/client-pull/src/driver.rs— single-sourcedrive, before the gap loop.crates/client-pull/src/scheduler.rs—multi_source_fetch, right after the aggregator is seeded tobase_present.The emitted value is exactly what the reporter emits at
received == 0.Reviewer notes
ingest_streamreportsreceived_end − fetch_start(content/leaf offsets),total_bytesis the header content size, andbase_present = ranges_content_len(...). TheProgressCallbackdoc comment that says "wire bytes" describes only the legacyreceive_and_pay/stream_fetchpath (now used bycrates/e2etests). So the resume base isbase_present(content), consistent with the reporter's own subsequent deltas — converting it to wire would break that consistency.multi_source_fetchalready seedsprogress_aggtobase_present, and lanes fold only their leg deltas on top. The new emit displays that seed — it is not a fold — so it cannot double-count against the aggregator.drivesites passon_progress = None, so the emit is a no-op there.client-pulland touches none of the CLI files PR fix(cli): stop bundle-pull total bar tearing and fix its denominator #1974 touches, so it composes cleanly whether fix(cli): stop bundle-pull total bar tearing and fix its denominator #1974 lands before or after. fix(cli): stop bundle-pull total bar tearing and fix its denominator #1974's total-barcontent_contributor(size × received/expected, viafetch_max) depends only on the ratio and still lands on the file's content size at completion.Tests
TDD — added a resume-scenario test on each path (
resume_base_is_reported_before_the_first_chunkin bothdriver.rsandscheduler.rs). Both first failed showing the initial position wasbase_present + first_chunk(49152 vs 32768), then passed after the fix.Gates run green:
cargo build,cargo clippy --all-targets --all-features,cargo fmt -- --check, the doc gate (RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items), andcargo nextest run -p decdn-cli -p decdn-client-pull(901/901).🤖 Generated with Claude Code