Skip to content

refactor(cli): route bundle pull through the streaming top-up loop - #1612

Merged
alpergundogdu merged 1 commit into
mainfrom
feat/unify-cli-paid-pull
Aug 5, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
feat/unify-cli-paid-pull

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

What

decdn bundle pull now streams every blob through the same paid-pull loop decdn fetch uses (fetch_blob_streaming), instead of the buffered fetch_blob. So bundle pull gains reactive mid-fetch top-up (#1497) and O(1) memory (no whole-blob Vec). Both CLI commands now share one loop; the buffered fetch_blob and the now-dead write_blob_atomic are deleted.

How

Per distinct blob hash, bundle pull streams into a staging file out_root/.decdn-partial/<hex>.partial, then materializes to each destination path by atomic file-copy (first path copied, the rest hard-linked/copied from it — the existing fetch-once/link-rest #1306 invariant, now over a file source instead of a Vec).

Preserved exactly: once-per-hash fetch-and-pay, per-provider open locks, buffer_unordered concurrency, dedup, skip-existing-destinations.

Money-correctness: a staging file is left in place on any fetch or materialize failure, so a rerun resumes from the paid prefix rather than re-fetching (re-paying) from zero; it's removed only when every destination landed. (An independent review caught an earlier version that deleted staging on total-materialize-failure — fixed.)

Scope

CLI only. The node keeps its own separate paid-pull loop (node_origin/resume.rs) — a deliberate choice (the loops differ on sink shape, funder, logging, and persistence); converging it would trade the duplication for several trait objects, to be re-evaluated separately.

Verification

cargo build -p decdn-cli
cargo nextest run -p decdn-cli          # 416 passed
cargo clippy -p decdn-cli --all-targets -- -D warnings
cargo fmt -- --check
RUSTDOCFLAGS='-D warnings' cargo doc -p decdn-cli --no-deps --document-private-items
cargo test --no-run -p decdn-e2e --features anvil-e2e   # compiles

All clean.

Follow-ups

  • bundle-pull top-up e2e — mirror crates/e2e/tests/cli_fetch_topup.rs through bundle pull (a manifest blob larger than the initial deposit tops up and completes). The loop is already covered by the fetch e2e suite; this would additionally exercise the staging/fan-out under a real top-up.
  • Chunk-aligned complete-resume re-pay — a pre-existing fetch_blob_streaming limitation (affects decdn fetch too): a complete .partial whose blob size is an exact multiple of CHUNK_GROUP_BYTES resumes at byte_offset == total_bytes, which the serve gate answers as NotFound, triggering a full restart + re-pay. Not introduced here; tracked for a focused fix.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Bundle pulls now download data progressively, reducing memory usage for large bundles.
    • Interrupted downloads can resume from retained partial data instead of restarting.
    • Downloads support improved deadline, rate-limit, and deposit handling during transfers.
  • Bug Fixes

    • Failed downloads or materialization attempts preserve staged data for later retries.
    • Staged data is cleaned up automatically after successful completion.
    • Manifest retrieval now benefits from the same reliable staged-download behavior.

Copilot AI lite review requested due to automatic review settings August 5, 2026 14:04
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@alpergundogdu, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 43 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: ed3f5cdb-5eae-4f83-ae0f-9475a3aed55a

📥 Commits

Reviewing files that changed from the base of the PR and between 6421881 and 33badd1.

📒 Files selected for processing (4)
  • crates/cli/src/commands/bundle_pull.rs
  • crates/cli/src/commands/fetch.rs
  • crates/client-pull/src/lib.rs
  • crates/node/tests/node_origin_pull.rs

Walkthrough

Bundle pulls now stream blobs into per-hash staging files. The files support resumed downloads and materialization retries. Shared fetch code validates resumed prefixes and exposes streaming APIs for bundle use.

Changes

Streaming bundle pull

Layer / File(s) Summary
Shared streaming fetch kernel
crates/cli/src/commands/fetch.rs, crates/client-pull/src/lib.rs, crates/node/tests/node_origin_pull.rs
The CLI exposes streaming fetch APIs, shares resumed-prefix verification, removes obsolete buffered helpers, and updates retry-path documentation.
Bundle staging and materialization
crates/cli/src/commands/bundle_pull.rs
Bundle pulls stream blobs and manifests through staging files, support reactive top-ups, reuse staged data for retries, and clean up files after successful materialization.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BundlePull
  participant fetch_blob_streaming
  participant Provider
  participant StagingFile
  participant materialize_group

  BundlePull->>fetch_blob_streaming: fetch blob with staging path
  fetch_blob_streaming->>Provider: stream blob and request top-ups
  Provider-->>fetch_blob_streaming: blob chunks
  fetch_blob_streaming->>StagingFile: write or resume partial data
  fetch_blob_streaming-->>BundlePull: completed staged fetch
  BundlePull->>materialize_group: read staged blob for destinations
  materialize_group-->>BundlePull: success or retained staging file
Loading

Note

🎁 Summarized by CodeRabbit Free

Your 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 @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.29% (was 80.32%, ▼ 0.02%) — 57060/71065 lines

File Coverage Lines Δ
crates/cli/src/commands/bundle_pull.rs 48.98% 454/927 ▼ 0.19%
crates/cli/src/commands/fetch.rs 39.97% 584/1461 ▲ +0.24%
crates/client-pull/src/lib.rs 90.15% 1428/1584 ● 0.00%
History
Commit Total Δ vs base
deee443 80.27% ▼ 0.05%
33badd1 (HEAD) 80.29% ▼ 0.02%

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.

Pull request overview

This PR refactors decdn bundle pull to reuse the same streaming paid-pull loop as decdn fetch (fetch_blob_streaming), enabling mid-fetch reactive top-ups and keeping memory usage O(1) by streaming verified chunk groups directly to disk. The old buffered fetch_blob path (and its write_blob_atomic helper) is removed, and bundle pull now stages each distinct hash to a per-hash .partial file before materializing to destination paths via atomic copy/link fan-out.

Changes:

  • Route bundle pull blob transfers through fetch_blob_streaming, including resumed-prefix verification via a shared verify_resumed_prefix.
  • Replace in-memory fan-out with a per-hash staging file and atomic materialization/link-or-copy to all destination paths.
  • Remove the buffered fetch_blob and the now-dead write_blob_atomic helper/test.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
crates/node/tests/node_origin_pull.rs Updates test documentation to reflect CLI moving off the buffered fetch_blob path.
crates/client-pull/src/lib.rs Updates docs about the byte_offset == 0 retry wrapper now being exercised primarily by test-only callers.
crates/cli/src/commands/fetch.rs Makes streaming fetch primitives reusable by bundle pull; deletes buffered fetch + atomic writer helper; adds verify_resumed_prefix.
crates/cli/src/commands/bundle_pull.rs Implements staging-file-based bundle pulling and atomic materialization/link fan-out; adds staging cleanup helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/cli/src/commands/bundle_pull.rs Resolved
Comment thread crates/cli/src/commands/bundle_pull.rs Resolved
Comment thread crates/cli/src/commands/bundle_pull.rs Resolved
decdn bundle pull buffered each blob via fetch_blob and had no reactive
top-up. It now streams every blob through the same fetch_blob_streaming loop
decdn fetch uses (#1497), into a per-hash staging file under
out_root/.decdn-partial/, and materializes to each destination path by atomic
file-copy — so bundle pull gains reactive mid-fetch top-up AND O(1) memory
(no whole-blob Vec). Both CLI commands now share one paid-pull loop; the
buffered fetch_blob (and the now-dead write_blob_atomic) are deleted.

Once-per-hash fetch-and-pay, per-provider open locks, dedup, and skip-existing
are unchanged. A staging file is left in place on error (resume, same contract
as fetch's .partial) and removed on success. The node keeps its own separate
loop (node_origin/resume.rs) — to re-evaluate later.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu force-pushed the feat/unify-cli-paid-pull branch from deee443 to 33badd1 Compare August 5, 2026 14:22
@alpergundogdu
alpergundogdu merged commit 0d00789 into main Aug 5, 2026
24 checks passed
@alpergundogdu
alpergundogdu deleted the feat/unify-cli-paid-pull branch August 5, 2026 14:25
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.

2 participants