Skip to content

feat(client): add a public bundle pull, decdn_client::bundle - #2436

Merged
thiras merged 2 commits into
mainfrom
feat/2429-client-bundle-api
Oct 12, 2026
Merged

thiras merged 2 commits into
mainfrom
feat/2429-client-bundle-api

Conversation

@thiras

@thiras thiras commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

What

Part of #2429 (2 of 3). Stacked on #2434, so the base is its branch. CI runs once this is retargeted to main.

This PR moves the bundle engine from crates/cli into decdn-client behind a public API, decdn_client::bundle:

let nodes = select_nodes(&chain, &site, &discovery).await?;   // before any key unlock
let mut puller = BundlePuller::builder(chain, site, endpoint, store, funding, discovery, nodes)
    .observer(observer).jobs(4).build().await?;
let manifest = puller.fetch_manifest(hash, out_dir, true).await?;   // or BundleManifest::parse
let outcome = puller.pull(&manifest, out_dir, false, &cancel).await; // BundleOutcome { report, end, replaced }
puller.finish().await;                                                // settle watermark writes
  • Funding is either SelfOwned { signer, deposit } or Delegated { slot: CredentialSlot }.
  • BundleEnd is Complete, Interrupted, FundingNeeded { needed, error } or Stopped(error).
  • BundleObserver / FileObserver carry progress: run totals, a per-blob file bar, each landed entry, warnings and pool replacement.
  • decdn_client::session becomes public and holds the inputs: ChainConfig, PullSite, DepositPolicy, DiscoveryOptions (with a Default).

decdn bundle pull is now a thin caller. It still owns:

  • clap and the --include/--exclude filter
  • --select and dry-run
  • the progress bars, which implement FileObserver
  • Ctrl-C, which cancels a token; a second Ctrl-C still exits 130
  • the summary and the --json PullReport
  • the flag-naming error hints, through a hidden FaultHints hook

Reviewer notes

  • Read first: crates/client/src/bundle.rs (the public surface) and the new crates/cli/src/commands/bundle_pull.rs. bundle/engine.rs is the old bundle_pull.rs with its CLI parts removed. Its PullCtx now owns its state instead of borrowing it, and progress, cancel and the entry log go through the observer.
  • CLI output is unchanged. The same stderr lines (note:, warning:, failed:) and the same --json field order, and exit codes stay 0/1/75/130. The 20 anvil e2e tests that parse --json and stderr pass.
  • Error ordering: the delegated key/capability mismatch now fails when the slot is built, after the keystore unlock. Before, it failed at the first lane build. The wording is unchanged.
  • Out of scope for this PR: the credential slot is still read once (the PR3 work). The engine still builds a fresh slot per entry from the grant, as before. PR 3 makes lanes read slot.current() live and makes the funding signal cover the whole bundle.
  • The pull future is not Send. This is documented in the module docs.

Verification

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run -p decdn-client -p decdn-cli: 1594 passed
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items
  • Public API snapshot regenerated. It adds only decdn_client::bundle and decdn_client::session.
  • python3 .github/scripts/check_crate_edges.py: no edge change, and the CLI/client closures stay iroh-blobs/AWS-free
  • cargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(/^cli_(bundle_pull|fetch)/) | binary(no_inline_test_modules)': 34/34 passed, against freshly built binaries
  • User-visible change: CHANGELOG.md entry added (Added)

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings October 12, 2026 12:22
@thiras thiras self-assigned this Oct 12, 2026

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.

🟡 Changes recommended

Path-containment, reserved-state collisions, ignored region restrictions, cumulative reporting, and manifest-fetch interruption need correction.

5 open findings
What changed in this PR

Moves bundle pulling from the CLI into the public decdn-client SDK while retaining CLI behavior.

Changes:

  • Adds BundlePuller, funding, outcomes, manifests, and observer APIs.
  • Moves bundle execution and cache logic into the client crate.
  • Refactors the CLI into a thin SDK caller.
File Description
CHANGELOG.md Documents the public bundle API.
crates/​cli/​src/​commands/​bundle_pull.rs Adopts BundlePuller.
crates/​cli/​src/​commands/​bundle_pull/​tests.rs Updates CLI-focused tests.
crates/​cli/​src/​commands/​fetch.rs Shares hash parsing and fault context.
crates/​cli/​src/​commands/​mod.rs Removes obsolete bundle modules.
crates/​cli/​src/​commands/​pull_progress.rs Implements SDK observer callbacks.
crates/​cli/​src/​commands/​pull_progress/​tests.rs Tests observer-based progress.
crates/​client/​src/​bundle.rs Defines the public bundle API.
crates/​client/​src/​bundle/​engine.rs Houses bundle execution logic.
crates/​client/​src/​bundle/​engine/​tests.rs Tests bundle execution behavior.
crates/​client/​src/​bundle/​manifest_cache.rs Implements manifest caching.
crates/​client/​src/​bundle/​manifest_cache/​tests.rs Tests manifest caching.
crates/​client/​src/​bundle/​skip_cache.rs Maintains incremental skip state.
crates/​client/​src/​bundle/​skip_cache/​tests.rs Tests skip-cache behavior.
crates/​client/​src/​lane_sources.rs Exposes fetch fault context.
crates/​client/​src/​lib.rs Exports bundle and session modules.
crates/​client/​src/​session.rs Adds public discovery defaults.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Records the expanded SDK surface.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +3682 to +3686
let mut comps = Path::new(seg).components();
match (comps.next(), comps.next()) {
(Some(Component::Normal(s)), None) => out.push(s),
_ => bail!("rejected unsafe component {seg:?} in entry path {rel:?}"),
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Real, but it is on main already: safe_join was lexical in the CLI too, and this PR only moves it. A manifest cannot create the symlink, so one must already exist locally, but containment should still hold against it. Tracked in #2439 (no-follow / openat-style resolution).

Comment on lines +742 to 745
// Watched from here on: the first Ctrl-C cancels the pull, which stops
// every fetch where it is and still reports what landed; a second one
// exits at once.
let mut interrupt = Interrupt::watch();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On main already: Interrupt::watch started after obtain_manifest before this PR, and the PR keeps that order. Tracked in #2439: watch from before the manifest fetch, and make that fetch cancellable.

Comment on lines +407 to +418
// Reserve the staging dir: an entry resolving inside
// `<out_root>/.decdn-partial/` would collide with a per-hash staging
// file, and `remove_staging` could then delete a materialized output.
Ok(dest) if dest.starts_with(out_root.join(STAGING_DIR)) => {
Slot::Failed(EntryOutcome::failed(
&en.path,
&anyhow::anyhow!(
"manifest path {:?} is inside the reserved staging directory {STAGING_DIR}/",
en.path
),
))
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On main already: plan_slots reserved only .decdn-partial/ before this PR. Tracked in #2439: reserve .decdn-manifest.json and .decdn-bundles/ the same way.

Comment on lines +856 to +857
fn entry_candidates(registry: &[NodeCandidate], region: Option<&str>) -> Vec<NodeCandidate> {
discovery::select_candidates(registry.to_vec(), region, discovery::SELECT_K)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is on main already: the CLI bundle path never applied the allowlist. To keep this PR a move, 43fbc5d makes the PullSite::region_allowlist doc say so (a bundle samples region-first and does not apply it). Applying it with fetch's widening rule is tracked in #2439.

Comment thread crates/client/src/bundle/engine.rs Outdated
Comment on lines +1553 to +1556
let dedup = DedupSummary {
spliced_bytes: self.dedup_stats.spliced_bytes.load(Ordering::Relaxed),
hints_ignored: self.dedup_stats.hints_ignored.load(Ordering::Relaxed),
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 43fbc5d: DedupStats::take swaps both counters to zero when a pull builds its report, so each BundleReport counts only its own pull. Test: dedup_counters_are_per_pull.

@thiras
thiras added this pull request to stack #2438 October 12, 2026 12:49
thiras added a commit that referenced this pull request Oct 12, 2026
Address review on #2436: a BundlePuller that runs several pulls
reports only each pull's own spliced bytes and ignored hints, and
PullSite::region_allowlist says the bundle path samples region-first
instead of applying it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras force-pushed the feat/2429-client-bundle-api branch from 14ddffb to 43fbc5d Compare October 12, 2026 13:11
@github-code-quality

github-code-quality Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit 0727829 in the feat/2429-client-bun... branch remains at 75%, unchanged from commit 77649bf in the main branch.

Show a line coverage summary of the most impacted files.
File main 77649bf feat/2429-client-bun... 0727829 +/-
crates/cli/src/.../bundle_pull.rs 59% 47% -12%
crates/node/src/dht/publish.rs 80% 78% -2%
crates/cli/src/...mmands/fetch.rs 51% 50% -1%
crates/node/src...s/client/mod.rs 90% 89% -1%
crates/client/src/lib.rs 88% 88% 0%
crates/cli/src/...ull_progress.rs 66% 67% +1%
crates/client/src/bundle.rs 0% 17% +17%
crates/client/s...undle/engine.rs 0% 61% +61%
crates/client/s...nifest_cache.rs 0% 98% +98%
crates/client/s...e/skip_cache.rs 0% 100% +100%

Updated October 12, 2026 13:46 UTC

Base automatically changed from feat/2429-client-network-leg to main October 12, 2026 13:35
thiras and others added 2 commits October 12, 2026 16:36
Part of #2429. The bundle engine moves from the decdn CLI into
decdn-client behind a public API: BundlePuller (built from
ChainConfig, PullSite, an endpoint, a BuyerPoolStore and Funding),
select_nodes, BundleManifest, BundleObserver/FileObserver for
progress, a CancellationToken to stop, and a typed BundleOutcome
with a BundleReport. The inputs live in the now-public
decdn_client::session module.

decdn bundle pull becomes a caller of it: it keeps clap, the
--include/--exclude filter, --select, dry-run, the progress bars,
Ctrl-C, the summary and --json report, and its error hints, and its
output and exit codes do not change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review on #2436: a BundlePuller that runs several pulls
reports only each pull's own spliced bytes and ignored hints, and
PullSite::region_allowlist says the bundle path samples region-first
instead of applying it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras force-pushed the feat/2429-client-bundle-api branch from 43fbc5d to 0727829 Compare October 12, 2026 13:36
@thiras
thiras merged commit 495cceb into main Oct 12, 2026
31 checks passed
@thiras
thiras deleted the feat/2429-client-bundle-api branch October 12, 2026 13:47
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