Skip to content

client: move bundle pull into decdn-client so embedders (decdn-sponsored) stop spawning the CLI #2429

Description

@thiras

Problem

decdn-client can only download single blobs. The bundle pull exists only inside the decdn CLI crate. That affects any application embedding deCDN that needs to pull a bundle. The first one is decdn/sponsord's decdn-sponsored.

The SDK's entry points are Downloader and Streamer, for one blob or a set of blobs. Its crate docs leave seven setup steps to the application: buyer key, pool, endpoint, discovery and probe, lane building, fetch, and recording settlement. Everything that makes up a bundle pull lives in crates/cli (about 7.7k lines):

This has two consequences:

  1. Embedders have to spawn the CLI. decdn-sponsored builds a decdn bundle pull argument vector (crates/decdn-sponsored/src/decdn.rs) and runs decdn as a child process. That makes decdn's CLI flags an untyped contract with software already in the field: a renamed flag breaks sponsored downloads at runtime, not at compile time. It also ships two binaries, each with its own pinned SHA256SUMS, and copies the node's expiry margin by hand (NODE_EXPIRY_MARGIN_SECS, Derive the wrapper's capability reuse margin from the node's expiry margin sponsord#10).
  2. ADR 039 § Client SDK funding signal can't be used for bundles. That ADR has a delegated client's application get new capabilities "from a sponsor gateway" and swap them into the CredentialSlot. The CLI "swaps in no new credential" (cli_sources.rs, credentials()), so a sponsored bundle pull that runs low on capability fails, and the user has to re-run the command to get a new key and capability through the onramp. The SDK already has the slot, the running-low signal and retirement at a voucher boundary. No bundle-level caller can reach them.

Proposed solution

Move the bundle pull into decdn-client as a public, bundle-level API. Make decdn bundle pull a thin caller of it.

Rough shape (names are illustrative):

  • A BundlePuller (or similar) taking: the manifest hash, an output directory, an optional namespace, an optional selection, the chain/deployment context, a data dir for the peer and buyer stores, and the funding source. The funding source is either a self-owned pool or a delegated CredentialSlot that the application keeps.
  • Progress reported through a callback or event stream (PullProgress events), not drawn to the terminal. The CLI keeps its rendering in pull_progress.rs/tab_progress.rs.
  • Typed outcomes: done, FundingNeeded (as fetch.rs maps it today), interrupted, or failed. That way an embedder can react without parsing stderr.
  • The running-low signal reachable from the bundle level, so the application can swap credentials mid-pull without restarting.
  • No CLI dependencies in decdn-client (no clap and no BundlePullArgs in the API). decdn_common::cli stays the CLI's concern.

Out of scope: any change to the wire protocol, the economics or the contracts. This changes where existing code lives and what the SDK makes public.

Follow-up downstream (sponsord, not this repo): decdn-sponsored links the new API directly, refreshes its capability through the onramp on the running-low signal, and stops shipping decdn in its installer and image.

Alternatives considered

  • Fold decdn-sponsored into the decdn CLI (decdn bundle pull --sponsor <onramp>). This removes the argv contract, but decdn would have to own the onramp's HTTP API: shared wire types, plus an ADR to describe that API. sponsord already depends on decdn, so this risks a dependency cycle between the two repos. It would also put one publisher-side product inside the protocol CLI.
  • Have sponsord reimplement bundle pull on the current SDK. That duplicates about 7.7k lines, which would drift from the CLI with every change.
  • Keep spawning the CLI. This works today, but keeps the problems above.

Related: #1021 (made discovery, probe, endpoint and provider public in the client).

Activity

  1. added
    kind:feature
    rust
    on Oct 12, 2026
  2. thiras commented on Oct 12, 2026

    @thiras
    ContributorAuthor

    Downstream consumer: decdn/sponsord#68 (decdn-sponsored pulls in-process and swaps credentials on the running-low signal).

  3. self-assigned this
    on Oct 12, 2026
  4. moved this from Backlog to In progress in deCDNon Oct 12, 2026
  5. thiras commented on Oct 12, 2026

    @thiras
    ContributorAuthor

    Tracking: PR 1/3 is #2434 (the network leg moves into decdn-client). Out of scope here and filed separately: #2435 (a delegated client's lane watermarks are never persisted).

  6. moved this from Done to In progress in deCDNon Oct 12, 2026
  7. moved this from In progress to Done in deCDNon Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:featurerust

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions