Repository navigation
Description
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:
- Registration is completion-gated and the plan is computed once. An entry becomes a splice donor only after its whole blob finalizes (
ChunkIndex::registerat the end ofpull_entry), and the consumer computes its donor/complement split once, up front, then pays the whole complement in a singledrive(&plan.complement). It never revisits the decision. - 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 siblingmodel-000XX-of-00002.safetensorsshards (only 0.2% depends on the excludedmetal/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) orshared(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.partialtorn reads); run-endsweep_donor_sourcesunchanged. - 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.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity
feat(cli): coalesce shared chunks in bundle pull so each is fetched o…
feat(cli): honest download-metered bundle pull progress with reconstr…