Repository navigation
feat(cli,node): prime the multi-source probe and the node's upstream handshake - #2138
Merged
Merged
Conversation
…handshake The multi-source probe and the node's serve-miss handshake each opened the whole blob only to read the signed size, then dropped the pull. The upstream treats every open as real, so each one cost a throwaway fill and delayed the real first leg (#2063). When the size is known before the first open, that open is now a lane's first unit and the drive adopts it through `PrimedSource`: - decdn-client: a scheduler first-unit hook (`SourceLane::first_unit`, carried on `StreamCandidate`), `download_first_unit` / `stream_first_unit` naming the range each face opens first, a pacer bound on `first_leg`, `ClientRangedStore::has_record`, and a public `PRIMED_MAX_IDLE`. - cli: with a size (the bundle manifest's, else the probe hint) and no resume record, build every lane first, then open the face's first unit and park it on the answering lane. A failed bounded open retries the whole blob, so a wrong hint never sinks a healthy holder; a signed size that differs drops the pull and runs unprimed. - node: carry the probe's `total_bytes` hint on `Candidate` and the probe cache. The window pull-through handshake opens the pull leg's predicted first leg, and the first run adopts it only on the same source, pool, ledger and leg while it is fresh. The buffered pull adopts its whole-blob handshake when the store holds none of the blob. With no size, or a size that turns out wrong, the whole-blob open behaves as before. Refs #2123 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unresolved moderate issues affect priming correctness and can reintroduce abandoned upstream work.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
Adds first-leg priming to CLI multi-source downloads and node upstream handshakes, reducing duplicate upstream opens.
Changes:
- Adds first-unit scheduling and primed-source adoption.
- Propagates manifest and probe size hints through CLI and node paths.
- Updates handshake behavior, tests, metrics, and public API snapshots.
| File | Reviewed changes |
|---|---|
crates/node/tests/node_origin_pull.rs |
Updates handshake tests and adds priming coverage. |
crates/node/src/selection.rs |
Adds candidate size hints. |
crates/node/src/node_origin/pull_leg.rs |
Implements handshake priming and adoption. |
crates/node/src/node_origin/mod.rs |
Propagates hints and primes buffered pulls. |
crates/node/src/node_origin/abandon_drain.rs |
Documents primed connection handling. |
crates/node/src/metrics.rs |
Clarifies handshake metrics. |
crates/node/src/handlers/client/window.rs |
Supplies predicted prime legs. |
crates/node/src/handlers/client/mod.rs |
Updates handshake documentation. |
crates/node/src/dht/probe_cache.rs |
Persists provider size hints. |
crates/client/tests/snapshots/public_api__public_api.snap |
Updates the public API snapshot. |
crates/client/src/streamer.rs |
Adds streaming first-unit support. |
crates/client/src/source.rs |
Exposes priming idle limits. |
crates/client/src/scheduler.rs |
Reserves primed first units. |
crates/client/src/ranged_store.rs |
Adds resume-record detection. |
crates/client/src/lib.rs |
Exports priming APIs. |
crates/client/src/driver.rs |
Supports bounded first-leg calculation. |
crates/client/src/downloader.rs |
Adds download first-unit support. |
crates/client/examples/common/mod.rs |
Initializes new candidate fields. |
crates/cli/src/commands/fetch.rs |
Primes CLI fetch lanes. |
crates/cli/src/commands/bundle_pull.rs |
Passes bundle size hints. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
`align_range(0, 0, 0)` is the empty range, not an error, and every other unit starts at 0 and ends inside the blob, so neither helper errors. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Code Coverage OverviewLanguages: Rust Rust / code-coverage/cargo-llvm-covThe overall line coverage in commit 5948593 in the Show a line coverage summary of the most impacted files.
Updated |
Address the #2138 review. - A bounded first open retries the whole blob only when the range ran past the blob's end (`decdn_client::is_range_past_end`: an open-stage `NotFound`, or the local range fault against a relay's smaller signed size). Every other failure is classified at once, so a dead candidate costs one open against `outer_pull_deadline`, not two. The range fault now keeps its typed `RangeVerifyError` cause. - `PrimedSource::prime` takes the pull's open time, so the idle bound runs from the open. The buffered `pull_from_candidate` pull and the serve-miss handshake pull are no longer re-aged when parked; `PrimeKey` drops its own age check. - The CLI opens the first unit only on a lane whose coverage holds it. - A size mismatch logs at `warn!` with the peer; a store fault while matching the primed leg is told apart from a leg mismatch. - Tests: `predicted_leg` equals `first_leg` over the planner's first run across ranged offsets, ceilings and an open ramp; lane eligibility; age from open; the range-fault classifier. The same-hash coalescing test waits for B's claim, since the gated upstream answers the header before it gates. - Docs: the hint, handshake, gated-double and ADR observability wording. Refs #2123 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Two open-then-drop sites remained after #2063. Each opened the whole blob only to read the signed
total_bytes, then dropped the pull:probe_admitted_totalon the CLI's multi-source path.handshake_total_byteson the node's serve-miss leg. The bufferedpull_from_candidatedid the same.The upstream treats every open as real: it signs, claims a fill, and draws from origin on a miss. So each throwaway open cost a fill nobody paid for, and the same range was then opened a second time.
A bounded open needs the size first, since an out-of-bounds range is refused, clamped, or fails locally. So priming happens only when a size is known before the first open:
size;ProbeResponseExt.total_bytes).With no size, or a wrong one, the whole-blob open behaves as today.
Refs #2123. This covers the two priming bullets; the other four stay open there.
SourceLane::first_unit, carried onStreamCandidate. An honoured unit is reserved for its lane and the rest of the blob is planned around it.download_first_unit/stream_first_unitname the range each face opens first.first_legtakes a pacer bound (up_to_bytes).ClientRangedStore::has_recordand a publicPRIMED_MAX_IDLE.decdn_client::is_range_past_end) retries the whole blob. Any other failure fails the lane at once.bundle pullpasses the manifest size, else the probe hint.CandidateandProbedProvidercarrytotal_bytes_hint.PrimeLeg::predicted_leg: the request cut to the ramp window at paid 0, the source's covered span, and the received-byte ceiling.PrimeKey::answersholds: same source, same pool, same ledgerArc, and same first leg.PrimedSourceenforces freshness, measured from when the pull opened, whichprimenow takes as an argument.outer_pull_deadline.Reviewer notes
Work::pick/reserve_first_unitsinscheduler.rs.prime_admitted_lanesinfetch.rs.PrimeLeg/PrimeKey/adopt_primedinnode_origin/pull_leg.rs..rangesrecord beside the output, keeps the size-probe path: its first gap is not the first unit.size. A mismatch just runs unprimed.a_probe_cache_hit_*now count 1 upstream connection instead of 2: the handshake is the drive's leg.serve_gated_correct_bytesdouble answers every header before gating the chunk data. The primed handshake is the real pull, and B needs its header to claim the fill. The coalescing test waits for B's claim before it launches leaf 2.Verification
cargo fmt -- --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo nextest run -p decdn-client -p decdn-cli -p decdn-node --all-features: 2450 passed. This includes the regenerateddecdn-clientpublic-API snapshot.RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-itemscli_fetch_multi_source,cli_fetch_stdout,cli_bundle_pull_multi_source,cli_bundle_pull_range_dedup,node_to_node_coalesce.a_lanes_first_unit_is_adopted_from_its_primed_pullanda_first_unit_is_honoured_only_when_wholly_missing_and_coverable(scheduler).a_primed_first_unit_is_adopted.a_windowed_first_leg_is_the_range_the_drive_opens_first.prime_tests::*(node), includingthe_predicted_leg_is_the_first_runs_first_leg, which checkspredicted_legagainstfirst_legover the planner's first run.only_a_capped_covering_lane_opens_the_first_unit(CLI). It also covers the age-from-open and range-fault classifier cases in the client.window_pull_through_handshake_is_the_first_pull_leg: upstream serves 2 legs, not 3.CHANGELOG.mdentry added (n/a)adr/added or updated (n/a, no ADR describes the handshake)🤖 Generated with Claude Code