Skip to content

feat(cli): coalesce shared chunks in bundle pull so each is fetched once per run - #2095

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/bundle-reconstruction-perf-8c5b87
Sep 21, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/bundle-reconstruction-perf-8c5b87

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #2094.

Problem

bundle pull didn'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-20b with --exclude 'metal/*': original/model.safetensors (13.76 GB) is 92.4% coverable from the three sibling model-000XX-of-00002.safetensors shards (only 0.2% depended on the excluded metal/model.bin), yet it downloaded in full.

Change

Run-level shared-chunk coalescing, fully parallel, deadlock-free:

  • Assign each chunk shared by ≥2 entries to its smallest holder (deterministic, from the whole manifest; tie-break by whole-file hash). Smallest finishes soonest, so waiters are the larger files.
  • Schedule groups smallest-first, so a shared chunk's holder starts before the entries that splice from it.
  • Drive only each entry's own ranges up front (unique + self-assigned chunks + un-splice-able edges); defer the rest.
  • Tail reconcile: splice each deferred range as its 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. Drive a deferred range oneself only if that holder finishes without producing it (a failed fetch), which keeps the run live and never worse than a direct fetch.

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 .partial torn reads); pre-seeded/cross-run donors and resume still work.

Effect on the observed bundle

original/model.safetensors pays ~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

  • No wire/manifest/ABI/config change — client-side scheduling only.
  • adr/appendix-bundles.md § "Chunked entries" and the bundle_pull module doc updated to present-tense canon.

Tests

  • Unit: fetcher assignment (smallest wins, order-independent tie-break); pay-now/deferred partition incl. sub-group fallback; smallest-first ordering.
  • Behavioral (fake RangeDriver + shared ChunkIndex): a late-registered donor is spliced (never driven); a failed assigned fetcher falls back to a paid drive (liveness).
  • Full decdn-cli suite green (740 tests); cargo clippy --workspace --all-targets --all-features, cargo fmt --check, and the rustdoc -D warnings gate 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

…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]>
Copilot AI lite review requested due to automatic review settings September 21, 2026 15:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Medium severity

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 FetchPlan and 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.md and 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.

Comment thread crates/cli/src/commands/bundle_pull.rs Resolved
Comment thread crates/cli/src/commands/bundle_pull.rs Resolved
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 83.46% (was 83.39%, ▲ +0.07%) — 84982/101821 lines

File Coverage Lines Δ
crates/cli/src/commands/bundle_pull.rs 71.75% 2560/3568 ▲ +4.17%
History
Commit Total Δ vs base
1f97916 83.46% ▲ +0.67%
d4816a1 (HEAD) 83.46% ▲ +0.07%

… 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]>
@alpergundogdu
alpergundogdu merged commit deea638 into main Sep 21, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/bundle-reconstruction-perf-8c5b87 branch September 21, 2026 17:07
alpergundogdu added a commit that referenced this pull request Sep 22, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bundle pull: coalesce shared chunks so each is fetched once per run (fixes full-price refetch of dedupable large files)

2 participants