Repository navigation
fix(cli): dedupe bundle-pull entries by hash + guard part dir cross-process (#1306, #1303) - #1336
Conversation
…rocess (#1306, #1303) Two bundle-pull correctness bugs from the #1301 review, batched. - **#1306** — a bundle may hold one file's content at two paths (`ManifestEntry` carries `path` + `hash`, nothing dedupes by hash). Under `--no-keep-blobs` the first entry deleted its parts before the second ran, so the second re-fetched — and **re-paid for** — every chunk (a 100 GB file at two paths cost 200 GB), with nothing in the output saying so. `bundle pull` now fans out over *distinct blob hashes* (`group_by_hash` → `HashGroup`): `fetch_group` fetches/pays once, the first writable destination gets the materialized bytes, and every other is a hard link (or copy, on `EXDEV`) via `link_or_copy_atomic`. Covers raw and `DECDNMAN` entries alike, in both retention modes. Skip-existing/`--overwrite` stay per-destination (`plan_slots`). Deduped duplicates report a new `Linked` outcome so `fetched`/`total_bytes` count only paid pulls. - **#1303** — the per-manifest lock #1301 added was process-local, so two `decdn` invocations sharing a data dir still raced the shared part directory. `file_manifest::reconstruct` now holds a `rustix` exclusive `flock` on a persistent `<downloads_root>/<hex>.lock` (a sibling of the part dir, never inside it, so `--no-keep-blobs` cleanup can't take the lock target and reopen the race). The part dir is (re)created *inside* the locked region so a concurrent holder's cleanup can't strand a waiter on `ENOENT` mid-fetch. Dedup (in-process) + flock (cross-process) jointly retire the process-local `manifest_locks`. New workspace dep: `rustix` (features `fs`), already transitive. Docs: `appendix-bundles.md` § Pull dedup note; ADR 012 retention unchanged. Verified: 351 tests pass (10 new/updated), clippy `-D warnings`, fmt, rustdoc `-D warnings`, and `cargo deny` all clean. Closes #1306 Closes #1303 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (1)
Walkthrough
ChangesBundle pull deduplication and reconstruction locking
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant bundle_pull
participant fetch_group
participant file_manifest
participant Filesystem
User->>bundle_pull: run bundle pull
bundle_pull->>fetch_group: process ordered distinct-hash groups
fetch_group->>fetch_group: plan writable and skipped destinations
fetch_group->>file_manifest: reconstruct manifest blob when needed
file_manifest->>Filesystem: acquire persistent reconstruction lock
fetch_group->>Filesystem: fetch and write canonical bytes once
fetch_group->>Filesystem: link or copy duplicate destinations
bundle_pull-->>User: report fetched, linked, skipped, and failed outcomes
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
There was a problem hiding this comment.
Code Review
This pull request optimizes bundle pulling by grouping manifest entries by their blob hash, ensuring duplicate blobs are fetched and paid for only once and then hard-linked or copied locally. It also introduces cross-process advisory locking using rustix to serialize concurrent reconstructions sharing a data directory. The review feedback correctly identifies that the use of Unix-specific imports (std::os::fd::OwnedFd) and APIs in file_manifest.rs will break compilation on Windows, and suggests using cross-platform alternatives like std::fs::File alongside target-gating for the locking logic.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
This PR fixes two correctness issues in decdn’s bundle pull path: (1) duplicate bundle entries that reference the same blob hash no longer trigger duplicate paid fetches, and (2) chunk-reconstruction part directories are now guarded across processes (not just within one invocation) to prevent cross-process races.
Changes:
- Group bundle manifest entries by distinct blob hash so each blob is fetched/paid once, then materialized to multiple destinations via hard-link (or copy fallback), with reporting that distinguishes
FetchedvsLinked. - Add a cross-process lock around
DECDNMANreconstruction using a persistent lockfile in the downloads root, and move part-dir creation inside the locked region. - Update documentation to reflect per-distinct-blob behavior and dedup semantics.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/cli/src/commands/bundle_pull.rs | Dedup by hash, add link/copy materialization, new Linked outcome and reporting updates |
| crates/cli/src/commands/file_manifest.rs | Add cross-process lockfile + flock guarding reconstruction and part-dir lifecycle |
| crates/cli/Cargo.toml | Add rustix dependency for filesystem locking |
| Cargo.toml | Add workspace rustix dependency (fs feature) |
| Cargo.lock | Lockfile updates for rustix inclusion |
| adr/appendix-bundles.md | Document dedup-by-hash semantics and per-distinct-blob node selection/concurrency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 81.72% (was 81.72%, ▲ +0.01%) — 51373/62862 lines
History
|
Review (Gemini, Copilot): the #1303 lock used `std::os::fd::OwnedFd` + `rustix::fs` flock, which is Unix-only and would break the `x86_64-pc-windows-msvc` release build (release.yml builds decdn-cli → decdn.exe on windows-latest). PR CI is Linux-only, so it passed. Switch `acquire_part_lock` to `std::fs::File::lock` — stable since Rust 1.89 (MSRV here is 1.95), a cross-platform OS advisory lock (flock on Unix, LockFileEx on Windows). This gives a *real* lock on every release target rather than a Windows stub, and needs **no** third-party crate: the `rustix` direct dep is dropped entirely (workspace + cli), leaving the Cargo.lock change a net no-op vs main. The returned File is the lock guard; the OS frees it on drop/exit, so no staleness bookkeeping. Verified: 351 tests pass, clippy -D warnings, fmt, rustdoc -D warnings, cargo deny all clean; cli no longer depends on rustix/fs4. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Two bundle-pull correctness bugs surfaced by the #1301 review, batched into one PR.
#1306 —
--no-keep-blobsre-pays for a file duplicated at two bundle pathsA bundle may hold one file's content at two paths (
ManifestEntrycarriespath+hash; nothing dedupes by hash). Under--no-keep-blobsthe first entry deleted its parts before the second ran, so the second re-fetched — and re-paid for — every chunk (a 100 GB file at two paths cost 200 GB), with nothing in the output saying so.Fix:
bundle pullnow fans out over distinct blob hashes (group_by_hash→HashGroup).fetch_groupfetches/pays once; the first writable destination gets the materialized bytes and every other is a hard link (or a copy onEXDEV) vialink_or_copy_atomic. Covers raw andDECDNMANentries alike, in both retention modes. Skip-existing/--overwritestay per-destination (plan_slots). Deduped duplicates report a newLinkedoutcome sofetched/total_bytescount only paid pulls.#1303 — chunk part directories unguarded across processes
The per-manifest lock #1301 added was process-local, so two
decdninvocations sharing a data dir still raced the shared part directory.file_manifest::reconstructnow holds arustixexclusiveflockon a persistent<downloads_root>/<hex>.lock— a sibling of the part dir, never inside it, so--no-keep-blobscleanup can't take the lock target and reopen the race. The part dir is (re)created inside the locked region so a concurrent holder's cleanup can't strand a waiter onENOENTmid-fetch.Notes
manifest_locks— a net simplification.rustix(featuresfs), already present transitively.appendix-bundles.md§ Pull gains a dedup note; ADR 012 § Blob retention is unchanged (dedup reconstructs once).Review
This branch went through a 5-agent review (code, tests, silent-failure, types, comments). Key items fixed before opening:
create_dir_all(part_dir)— a concurrent--no-keep-blobsholder could remove the dir mid-window, causing a spuriousENOENTafter already paying for a chunk. Now created inside the lock.Linkedoutcome so the summary never implies a double payment; extractedplan_slots+ injectablematerialize_groupand added direct tests for the "fetched once / linked rest" invariant, the retry path, and the per-destination skip matrix.Slot::Write { label, dest },HashGroupcarrying the shared hash, precise per-distinct-blob wording.Verification
351 tests pass (10 new/updated),
clippy -D warnings,fmt --check, rustdoc-D warnings, andcargo deny checkall clean.Closes #1306
Closes #1303
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
decdn bundle pullnow fetches shared blobs only once and reuses them across destinations.Bug Fixes
Documentation