Skip to content

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

Closed

Description

@alpergundogdu

Problem

bundle pull range-dedup does not fire for files that share content within a single fresh run, so a large file is paid for in full even when the run also fetches its chunks under other entries.

Two independent causes:

  1. Registration is completion-gated and the plan is computed once. An entry becomes a splice donor only after its whole blob finalizes (ChunkIndex::register at the end of pull_entry), and the consumer computes its donor/complement split once, up front, then pays the whole complement in a single drive(&plan.complement). It never revisits the decision.
  2. Consumer and donors run concurrently. With --jobs 4, a big consumer and its donor siblings are all in flight together, so when the consumer plans, no donor has registered → empty index → it pays for everything.

Observed

Pulling the gpt-oss-20b bundle 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% depends on the excluded metal/model.bin).
  • It nonetheless downloads in full at full price, because the shards haven't finished/registered when it plans.

Proposed fix: run-level shared-chunk coalescing (once-only)

Each shared chunk (a chunk hash appearing in ≥2 entry positions) is fetched and paid for exactly once across the run, by a single assigned entry, and spliced into every other entry — while all entries keep downloading in parallel. Deadlock-free; never pays more than today.

  • Static analysis (whole manifest, deterministic): classify each chunk hash as unique (count 1) or shared (count ≥2).
  • Fetcher assignment: assign each shared chunk to its smallest containing entry (tie-break by whole-file hash). Smallest finishes soonest → waiters are the larger files, whose tail comes later anyway. Deferral only points at strictly-smaller/tie siblings → the wait graph is a DAG over entry size (no cycles).
  • Per-entry partition (group-aligned, reusing plan_dedup): pay-now = unique + assigned-to-me chunks (+ un-splice-able edge groups); deferred = shared chunks assigned to a smaller sibling.
  • Schedule smallest-first, drive only pay-now ranges (paid stream never idles on deferred bytes).
  • Tail reconcile (only place an entry waits, with gate/lane permits released): splice deferred ranges as donors register; bounded-wait for stragglers; on timeout, reacquire a permit and drive+pay (liveness fallback). Then whole-file verify → promote → register → materialize, as today.

Invariants preserved

  • Whole-file BLAKE3 remains authoritative; splice source is always a completed, whole-file-verified <hex> (no .partial torn reads); run-end sweep_donor_sources unchanged.
  • No wire/manifest/ABI change — purely client-side pull scheduling. adr/appendix-bundles.md § "Chunked entries" updated to describe the new scheduling.
  • Group alignment unchanged (CHUNK_GROUP_BYTES = 16 KiB; --chunk-min ≥ 1 MiB, so chunks span ≥64 groups and always have a splice-alignable interior).

Effect on the observed bundle

original/model.safetensors pays ~1 GB (its unique complement) instead of 13.76 GB; run total paid ~14.7 GB vs ~27.4 GB today (~46% fewer paid bytes), with full parallelism retained.

Scope

All in crates/cli/src/commands/bundle_pull.rs + a doc update to adr/appendix-bundles.md. Follow-ups (out of scope): cross-run persistent range cache (already documented as deferred), parallelizing the tail reconcile, hard-linking the first materialize to cut ~2× peak disk.

Activity

  1. added
    kind:feature
    area:cli
    on Sep 21, 2026
  2. moved this from Backlog to In progress in deCDNon Sep 21, 2026
  3. moved this from In progress to Done in deCDNon Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:clikind:feature

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions