Repository navigation
feat(cli): coalesce shared chunks in bundle pull so each is fetched once per run - #2095
Conversation
…nce per run (#2094) A bundle pull grouped entries by hash and, for a hint-carrying entry, computed its donor/complement split once from the ChunkIndex snapshot, then paid for the whole complement. Donors only registered at whole-file completion, and with the default `--jobs 4` a large consumer and its donor siblings ran concurrently — so the consumer planned against an empty index and paid full price for content its siblings were fetching in parallel. Excluding an unrelated subtree (e.g. `--exclude 'metal/*'`) did not help: the dedupable bytes come from the other entries in the run. Now the run assigns every chunk shared by two or more entries to its smallest holder (deterministic, from the whole manifest), schedules groups smallest-first, and has each entry drive only its own ranges up front. Each entry reconciles its deferred (sibling-assigned) ranges at its tail: it splices each as the assigned holder registers it, waiting on the holder via the index's progress signal — not a clock, because the deferred bytes are exactly what the holder is still downloading — and drives a deferred range itself only if that holder finishes without producing it (a failed fetch). Each shared chunk is therefore fetched and paid for once per run and spliced into every other entry, while all entries keep downloading in parallel; the whole-file BLAKE3 stays the authoritative check and the path is never worse than a direct fetch. No wire/manifest/ABI change — client-side scheduling only. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new smallest-first scheduling and ChunkIndex updates contain correctness/concurrency issues (size selection for ordering and a lock-order inversion) that should be addressed before approval.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
This PR updates decdn’s bundle pull implementation to coalesce shared chunk-hints across entries within a single run, so each shared chunk is fetched/paid once and then spliced into other entries as it becomes available, while keeping parallelism.
Changes:
- Add a run-wide shared-chunk
FetchPlanand tail reconciliation that waits on index progress (not time) and falls back to paid fetches if the assigned fetcher finishes without producing a chunk. - Schedule hash-groups smallest-first to reduce deferred wait time and make coalescing deterministic.
- Update
adr/appendix-bundles.mdand module docs to describe the new present-tense behavior.
| File | Description |
|---|---|
| crates/cli/src/commands/bundle_pull.rs | Implements run-level shared-chunk assignment, smallest-first group scheduling, deferred-tail splice reconciliation, and new ChunkIndex signaling to unblock waiters. |
| adr/appendix-bundles.md | Updates bundle semantics documentation for chunked entries to match the new once-per-run shared chunk fetching and tail reconcile behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 83.46% (was 83.39%, ▲ +0.07%) — 84982/101821 lines
History
|
… order Two Copilot review findings on the shared-chunk coalescing: - `order_groups_smallest_first` derived a group's size from `entries.first()`, but the file's convention (see `total_content_bytes`) is that a group's size is any same-hash entry that declares one. A group whose first duplicate path is unsized but another is sized would sort last and schedule its donor late. Use `entries.iter().find_map(|e| e.size)`; add a regression test. - `ChunkIndex::sources` locked `seeded` then `map`, the reverse of the `map`-first order every other site uses. Acquire `map` before `seeded` so all sites share one lock order and no future concurrent path can invert into a deadlock. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…uction + discovery states (#2097) * feat(cli): honest download-metered bundle pull progress with reconstruction + discovery states (#2096) After shared-chunk coalescing (#2095) the progress display misled: the total bar was denominated by the whole content size and credited spliced-from-disk bytes, so a dedup'd pull read "25.6/25.66 GiB, ETA 1s" while only ~14.8 GB was actually transferred; the tail whole-file verify (hashing a multi-GB blob) ran with no callback and looked frozen; and a blob stalled on discovery hid behind a near-full total. Now: - The total bar meters the run's DOWNLOAD — the bytes actually fetched after dedup (`download_bytes`, computed up front from the fetch plan) — and only delivered bytes fold into it, capped per file at its download size, so its rate and ETA describe real transfer. A one-line header shows `<dir> · <download> to download · <content> on disk`, making the dedup saving visible. - Each per-file row reads `downloaded/download-total (reconstructed)` plus a phase word: `discovering…` before the first byte, `pending siblings…` while a deferred chunk is still being fetched by its holder, and `reconstructing…` during the whole-file verify — which now streams its running byte count into the bar so a multi-GB reconstruction never sits frozen (`hash_partial_with_progress`). No wire/protocol change; progress rendering only. Follow-up to #2094/#2095. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(cli): unsized bundle-pull entries borrow the stream length for display An entry the manifest declares no size for has download_total 0, so its per-file bar length stayed 0 and never moved. The row now borrows the stream's `expected` length for display once delivery starts, so it tracks progress like any other row — while still contributing nothing to the total bar's download meter (the fold is capped at download_total, which is 0 for an unsized entry). The counts render as a bare delivered figure when no size is known, rather than `x/0 B`. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>

Closes #2094.
Problem
bundle pulldidn't dedup files that share content within a single fresh run, so a large file was paid for in full even while the run fetched its chunks under sibling entries. Two causes: donors only register at whole-file completion, and a consumer computes its donor/complement split once, up front, then pays the whole complement. With the default--jobs 4, a big consumer and its donor siblings run concurrently → the consumer plans against an empty index → pays for everything.Concretely, pulling
gpt-oss-20bwith--exclude 'metal/*':original/model.safetensors(13.76 GB) is 92.4% coverable from the three siblingmodel-000XX-of-00002.safetensorsshards (only 0.2% depended on the excludedmetal/model.bin), yet it downloaded in full.Change
Run-level shared-chunk coalescing, fully parallel, deadlock-free:
Each shared chunk is fetched and paid for once per run and spliced into every other entry. Whole-file BLAKE3 stays authoritative; splice sources are always completed, whole-file-verified blobs (no
.partialtorn reads); pre-seeded/cross-run donors and resume still work.Effect on the observed bundle
original/model.safetensorspays ~its ~1 GB unique complement instead of 13.76 GB; run total paid ≈ 14.7 GB vs ~27.4 GB before (~46% fewer paid bytes), with full parallelism retained.Scope / safety
adr/appendix-bundles.md§ "Chunked entries" and thebundle_pullmodule doc updated to present-tense canon.Tests
RangeDriver+ sharedChunkIndex): a late-registered donor is spliced (never driven); a failed assigned fetcher falls back to a paid drive (liveness).decdn-clisuite green (740 tests);cargo clippy --workspace --all-targets --all-features,cargo fmt --check, and the rustdoc-D warningsgate all clean.Follow-ups (out of scope)
Cross-run persistent range cache (already documented as deferred); hard-linking the first materialize to cut the ~2× peak staging disk.
🤖 Generated with Claude Code