Repository navigation
feat(client): let a delegated bundle pull swap credentials mid-run - #2437
Conversation
There was a problem hiding this comment.
🟡 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.
| let fetch_plan = build_fetch_plan(entries); | ||
| let planned = download_bytes(entries, &fetch_plan); |
There was a problem hiding this comment.
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.
| 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))); |
There was a problem hiding this comment.
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.
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]>
c14a280 to
b3b8346
Compare
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]>
b3b8346 to
371c6d4
Compare
Code Coverage OverviewLanguages: Rust Rust / code-coverage/cargo-llvm-covThe overall line coverage in commit 4c80b15 in the Show a line coverage summary of the most impacted files.
Updated |
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]>
371c6d4 to
4c80b15
Compare

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.
LanePayer::Delegated(&CredentialSlot)replaces the fixed grant and signer. Every lane readsslot.current()when it is built, so a credential swapped in mid-pull takes over at the next voucher boundary.LaneKey.signerand each watermark write are keyed on the lane's own signer, so lanes under the old key and the new key settle separately.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.WorkShareof 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, andcredential_viewpricesmax(entry missing, run outstanding). SoRunningLowfires before the bundle stalls, and every entry reports the same need.decdn fetchanddecdn bundle pullbuild one zero-wait slot per command (fetch::delegated_slot) and behave as before. The key/capability mismatch keeps its wording.bundleexample is a delegated pull that swaps in the next key and capability onRunningLow.adr/appendix-bundles.md§ Pull describes the SDK engine, with the CLI as one caller.CHANGELOG.mdhas a Changed entry.Out of scope, filed as #2435: a delegate's lane watermarks are still never persisted across runs, because
write_lanereturnsUnknownPoolfor a delegate.Reviewer notes
lanes.rs(LanePayer,build_multi_lane) andlane_sources.rs(credentials,seed_spend) first, thenscheduler.rs::credential_viewandbundle/engine.rs(WorkShare).ensure_delegate_signeris gone.CredentialSlot::newalready refuses a key the capability does not name, and the CLI maps that refusal to the old message (tested ina_delegated_slot_rejects_a_key_the_capability_does_not_name).FundingNeededendings are already covered by the scheduler tests, through a provider that readsslot.current(). That is whatLaneSourcesnow does.the_running_low_signal_prices_the_runs_outstanding_worktest was mutation-checked: pricing only the entry's own bytes makes it fail.Verification
cargo fmt -- --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo nextest run -p decdn-client -p decdn-cli: 1596 passedCARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-itemspython3 .github/scripts/check_crate_edges.py: no edge changecargo build -p decdn-client --example bundlecargo 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 testsCHANGELOG.mdentry addedappendix-bundles.mdupdated🤖 Generated with Claude Code