Skip to content

feat(client): let a delegated bundle pull swap credentials mid-run - #2437

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

thiras merged 2 commits into
mainfrom
feat/2429-client-live-credential

Conversation

@thiras

@thiras thiras commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

What

Closes #2429 (3 of 3). Stacked on #2436, which is stacked on #2434.

This PR wires the live credential swap that ADR 039 § Client SDK funding signal describes into both the fetch and the bundle pull.

  • Live lanes. LanePayer::Delegated(&CredentialSlot) replaces the fixed grant and signer. Every lane reads slot.current() when it is built, so a credential swapped in mid-pull takes over at the next voucher boundary. LaneKey.signer and each watermark write are keyed on the lane's own signer, so lanes under the old key and the new key settle separately.
  • One slot per run. LaneSources::credentials() returns the caller's slot instead of a fresh one per entry. The slot records the current key's earlier spend from the buyer store, once per slot generation, so a swapped-in key is counted from its own records.
  • A signal that covers the whole bundle. Each hash group holds a WorkShare of the run's planned download. Bytes come off it as they land, and the rest comes off when the group settles. Downloader::outstanding_work (hidden) passes the run total to the acquire loop, and credential_view prices max(entry missing, run outstanding). So RunningLow fires before the bundle stalls, and every entry reports the same need.
  • CLI. decdn fetch and decdn bundle pull build one zero-wait slot per command (fetch::delegated_slot) and behave as before. The key/capability mismatch keeps its wording.
  • Docs.
    • The crate guide's entry-point table and the README cover the bundle path.
    • The new bundle example is a delegated pull that swaps in the next key and capability on RunningLow.
    • adr/appendix-bundles.md § Pull describes the SDK engine, with the CLI as one caller.
    • ADR 039's projected-need rule now covers a bundle.
    • CHANGELOG.md has a Changed entry.

Out of scope, filed as #2435: a delegate's lane watermarks are still never persisted across runs, because write_lane returns UnknownPool for a delegate.

Reviewer notes

  • Read lanes.rs (LanePayer, build_multi_lane) and lane_sources.rs (credentials, seed_spend) first, then scheduler.rs::credential_view and bundle/engine.rs (WorkShare).
  • ensure_delegate_signer is gone. CredentialSlot::new already refuses a key the capability does not name, and the CLI maps that refusal to the old message (tested in a_delegated_slot_rejects_a_key_the_capability_does_not_name).
  • The swap mid-stream, the swap inside the wait, and the typed FundingNeeded endings are already covered by the scheduler tests, through a provider that reads slot.current(). That is what LaneSources now does.
  • The new the_running_low_signal_prices_the_runs_outstanding_work test was mutation-checked: pricing only the entry's own bytes makes it fail.

Verification

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run -p decdn-client -p decdn-cli: 1596 passed
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items
  • Public API snapshot: unchanged by this PR (the new seams are hidden)
  • python3 .github/scripts/check_crate_edges.py: no edge change
  • cargo build -p decdn-client --example bundle
  • cargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(/^cli_(bundle_pull|fetch)/) | binary(no_inline_test_modules)': 34/34 passed, including both delegated-fetch e2e tests
  • User-visible change: CHANGELOG.md entry added
  • Design change: ADR 039 and appendix-bundles.md updated

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings October 12, 2026 12:48
@thiras thiras self-assigned this Oct 12, 2026
@thiras
thiras added this pull request to stack #2438 October 12, 2026 12:49

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

Bundle funding demand can be cleared or overstated across concurrent and resumed entries.

2 open findings
What changed in this PR

Adds live delegated credential swapping to fetch and bundle pulls.

Changes:

  • Reads credentials per lane and persists watermarks by lane signer.
  • Adds bundle-wide outstanding-work funding signals.
  • Updates CLI integration, tests, examples, and ADRs.
File Description
crates/​client/​src/​streamer.rs Initializes standalone stream work tracking.
crates/​client/​src/​scheduler/​tests.rs Tests bundle-wide funding signals.
crates/​client/​src/​scheduler.rs Prices credentials against outstanding work.
crates/​client/​src/​lib.rs Documents the bundle API.
crates/​client/​src/​lanes/​tests.rs Tests per-lane signer watermarks.
crates/​client/​src/​lanes.rs Builds lanes from live credentials.
crates/​client/​src/​lane_sources.rs Shares slots and seeds signer spend.
crates/​client/​src/​funding/​tests.rs Removes obsolete signer-gate tests.
crates/​client/​src/​funding/​adoption_tests.rs Updates signer ownership setup.
crates/​client/​src/​funding.rs Uses credential-validated delegated signers.
crates/​client/​src/​downloader.rs Propagates run-wide outstanding work.
crates/​client/​src/​bundle/​engine/​tests.rs Tests work-share accounting.
crates/​client/​src/​bundle/​engine.rs Tracks bundle work and live credentials.
crates/​client/​src/​bundle.rs Retains delegated slots in pull contexts.
crates/​client/​README.md Documents delegated bundle pulls.
crates/​client/​examples/​bundle.rs Demonstrates credential swapping.
crates/​cli/​src/​commands/​fetch/​tests.rs Tests credential mismatch reporting.
crates/​cli/​src/​commands/​fetch.rs Creates one delegated slot per fetch.
crates/​cli/​src/​commands/​bundle_pull.rs Reuses delegated-slot construction.
CHANGELOG.md Records the behavior change.
adr/​appendix-bundles.md Documents SDK bundle pulling.
adr/​039-multi-source-parallel-fetch.md Defines bundle-wide projected need.

🧠 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 +1511 to +1512
let fetch_plan = build_fetch_plan(entries);
let planned = download_bytes(entries, &fetch_plan);

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 b3b8346. The run's planned work is now seeded in pull_all after the disk pre-pass, from planned_work: only groups that still have a destination to write and no whole-file donor, each at its planned download less the bytes its .partial already holds. A skipped or linked group holds an empty WorkShare, so it never counts while it waits for a jobs slot. A resumed group's share discounts its prefix from the positions it reports. Tests: planned_work_leaves_out_skipped_and_donor_groups, a_resumed_share_counts_only_this_runs_bytes.

Comment thread crates/client/src/scheduler.rs Outdated
let remaining = ranges_content_len(&missing_chunks(store, ranges).await?, store.total_bytes());
let own = ranges_content_len(&missing_chunks(store, ranges).await?, store.total_bytes());
// A bundle prices the work of the whole run, not of this entry alone.
let remaining = outstanding.map_or(own, |run| own.max(run.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 b3b8346. Every fetch of a run now shares one RunDemand (hidden): the planned work and a run-wide QuoteMax. Each acquire's lanes fold their quotes into it, and credential_view prices at the run's highest rate, so every entry computes the same view and a cheap entry cannot clear an expensive entry's RunningLow. Test: the_running_low_signal_prices_the_runs_highest_quote (a fetch quoted 1/MB under a run that saw 10/MB). Mutation-checked: pricing at the acquire's own quotes makes it fail.

thiras added a commit that referenced this pull request Oct 12, 2026
Address review on #2437. The run's outstanding work is seeded after the
disk pre-pass from the groups that still fetch, less what earlier runs
left in their partial files, so a group the pre-pass skips or links no
longer counts while it waits for a jobs slot. Every fetch of a run now
shares one RunDemand: the planned work and the highest quote any lane of
the run got, so a cheap entry cannot clear the RunningLow an expensive
one raised.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras force-pushed the feat/2429-client-live-credential branch from c14a280 to b3b8346 Compare October 12, 2026 13:35
thiras added a commit that referenced this pull request Oct 12, 2026
Address review on #2437. The run's outstanding work is seeded after the
disk pre-pass from the groups that still fetch, less what earlier runs
left in their partial files, so a group the pre-pass skips or links no
longer counts while it waits for a jobs slot. Every fetch of a run now
shares one RunDemand: the planned work and the highest quote any lane of
the run got, so a cheap entry cannot clear the RunningLow an expensive
one raised.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras force-pushed the feat/2429-client-live-credential branch from b3b8346 to 371c6d4 Compare October 12, 2026 13:36
@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 4c80b15 in the feat/2429-client-liv... 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-liv... 4c80b15 +/-
crates/cli/src/.../bundle_pull.rs 59% 47% -12%
crates/cli/src/...mmands/fetch.rs 51% 50% -1%
crates/client/s...c/downloader.rs 84% 83% -1%
crates/node/src...s/client/mod.rs 90% 89% -1%
crates/client/src/lanes.rs 60% 59% -1%
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:57 UTC

Base automatically changed from feat/2429-client-bundle-api to main October 12, 2026 13:47
thiras and others added 2 commits October 12, 2026 16:48
Closes #2429. Every lane reads the CredentialSlot's current key and
capability when it is built (LanePayer::Delegated), so a credential
the application swaps in takes over at the next voucher boundary.
A fetch shares one slot across its lanes and a bundle pull across its
entries; the slot records a swapped-in key's earlier spend from the
buyer store, and each lane's watermark is keyed on its own signer.

A bundle pull prices RunningLow on the bundle's undelivered download
(each hash group holds a WorkShare of it), so every entry reports one
bundle-wide need. decdn fetch and decdn bundle pull build one
zero-wait slot per command and behave as before.

Adds the `bundle` example (a delegated pull that swaps on RunningLow),
and updates the crate guide, README, the bundles appendix and ADR 039.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review on #2437. The run's outstanding work is seeded after the
disk pre-pass from the groups that still fetch, less what earlier runs
left in their partial files, so a group the pre-pass skips or links no
longer counts while it waits for a jobs slot. Every fetch of a run now
shares one RunDemand: the planned work and the highest quote any lane of
the run got, so a cheap entry cannot clear the RunningLow an expensive
one raised.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras force-pushed the feat/2429-client-live-credential branch from 371c6d4 to 4c80b15 Compare October 12, 2026 13:48
@thiras
thiras merged commit abbce74 into main Oct 12, 2026
31 checks passed
@thiras
thiras deleted the feat/2429-client-live-credential branch October 12, 2026 14:01
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.

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

2 participants