Skip to content

fix(client): start the size open's lane before any other lane builds - #2742

Merged
thiras merged 1 commit into
mainfrom
fix/primed-first-leg-adoption
Oct 28, 2026
Merged

thiras merged 1 commit into
mainfrom
fix/primed-first-leg-adoption

Conversation

@thiras

@thiras thiras commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Summary

peer_store_probeless failed about 1 run in 5 to 10 at the served-bytes check of journey 1's fetch #2. The holders wrote 397476 bytes for a 198610-byte pull, so they served the blob twice.

Cause. A fetch with no size hint opens the whole blob for its signed size, primes the pull on the answering lane, and parks the lane for the download's first leg to adopt. The parked lane reached the acquire loop through connect, as a build future beside the other holders' fresh builds. The loop plans the work across every build that has finished when it looks (now_or_never batching). When another holder's lane built just as fast, the first batch held two lanes and the plan split the blob. The parked lane's first leg was then half the blob, so PrimedSource closed the primed pull after the node had written the blob into it, and the two legs pulled the blob again.

Client debug log of the failing fetch #2:

planned the missing ranges across the first lanes total_bytes=197842 lanes=2 pending=0+114688,114688+83154
a primed pull the next open did not take is closed
opening a paid leg … byte_offset=0 byte_len=114688
opening a paid leg … byte_offset=114688 byte_len=83154

Every passing run logs lanes=1 pending=0+197842 and opens no leg.

Fix. SourceProvider::built (default None) hands over a lane the provider built before the set. The acquire loop starts such a lane in the pass that starts its provider, before it polls any build (SourceSet::take_built). The first batch then holds that lane alone, and the plan gives it the whole blob. LaneSources returns its parked lane there. ADR 039 states the rule.

#2724 unmasked the race; it did not introduce it. #2724 changed only the discovery trigger. The batching and the connect path are unchanged, and the biased select! polls a discovery future after the builds. Before #2724, a slow fetch also let the first-pass discovery probe the holders mid-transfer, so a slow run failed earlier, at the probe assertion. The one failing run here was also the slow run (total_ms=984 against 125 to 176 ms).

Test plan

  • New scheduler::tests::a_size_opens_lane_adopts_its_primed_pull_beside_a_lane_that_builds_at_once: a kept lane with a primed whole-blob pull beside a lane whose build resolves at once. Mutation check: with the scheduler's take_built branch removed, it fails with [(0, 2097152), (0, 1048576)], the same half-blob re-open as the e2e. Restored from a copy and touched.
  • peer_store_probeless: 10 runs before the fix, 1 failed. 20 runs with the fix, 20 passed (1 test each, run under concurrent clippy and test load).
  • cargo nextest run -p decdn-client --no-fail-fast: 1201 passed.
  • E2E binaries cli_fetch_multi_source, cli_fetch_stdout, cli_fetch_resume, cli_fetch_recovers_one_holder, gateway_concurrent_pulls, gateway_pointer, gateway_public, origin_stream_while_store, warm_upstream_connection and peer_store_probeless pass. cli_bundle_pull_multi_source flakes with and without this change (2 of 6 runs with the fix disabled), filed as e2e: cli_bundle_pull_multi_source flakes: no single pull splits the large entry across both holders #2741.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo fmt -- --check, CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items, and the decdn-client public API snapshot.

Closes #2740

🤖 Generated with Claude Code

…2740)

A fetch with no size hint opens the whole blob on one holder for its
signed size, primes that pull on the lane, and parks the lane. The
download's first leg adopts the pull only when the leg is the whole
blob.

The parked lane reached the acquire loop through `connect`, as a build
future beside the other holders' fresh builds, and the loop plans the
work across every build that has finished when it looks. When another
holder's lane built just as fast, the first batch held two lanes, the
blob was split between them, and the parked lane's first leg was half
the blob. `PrimedSource` then closed the primed pull after the node had
written the blob into it, and the two legs pulled it again. This is the
`peer_store_probeless` double write (397476 bytes for a 198610-byte
pull): in a 10-run loop, the one failure was the one run whose first
batch held two lanes.

`SourceProvider::built` (default `None`) hands over a lane the provider
built before the set. The acquire loop starts such a lane in the pass
that starts its provider, before it polls any build, so the first batch
holds it alone and the plan gives it the whole blob. `LaneSources`
returns its parked lane there. ADR 039 states the rule.

#2724 did not introduce the race; it unmasked it. The batching and the
`connect` path are unchanged by it, and a discovery future is polled
after the builds. Before #2724, a slow fetch also let the first-pass
discovery probe the holders mid-transfer, so a slow run failed at the
probe assertion first.

Closes #2740

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main bb37102 fix/primed-first-leg... 51f0463 +/-
77% 77% 0%
View coverage of the 5 most impacted files.
File main bb37102 fix/primed-first-leg... 51f0463 +/-
crates/client/src/scheduler.rs 94% 94% 0%
crates/client/s...lane_sources.rs 40% 40% 0%
crates/client/s...c/source_set.rs 93% 93% 0%
crates/protocol/src/framing.rs 92% 93% +1%
crates/node/src/dht/publish.rs 78% 80% +2%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

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.

🟢 Approval recommended

No active review issues remain for the scheduling change that prioritizes the primed lane to avoid duplicate downloads.

No open issues 🎉

What changed in this PR

Fixes #2740 by starting the client lane that supplied the blob’s size before polling other lane builds. This lets its first download leg reuse the primed whole-blob pull instead of splitting the work and downloading bytes twice.

Changes:

  • Adds a prebuilt-lane handoff from source providers to the scheduler.
  • Adds a regression test covering a primed lane beside an immediately completing build.
  • Updates the ADR, changelog, and end-to-end test comments to describe the scheduling rule.
File Description
crates/​e2e/​tests/​peer_store_probeless.rs Clarifies the lane-start ordering in test comments.
crates/​client/​src/​source_set.rs Adds provider and source-set support for taking prebuilt lanes.
crates/​client/​src/​scheduler/​tests.rs Tests primed-pull reuse when another lane builds immediately.
crates/​client/​src/​scheduler.rs Starts prebuilt lanes before polling pending builds.
crates/​client/​src/​lane_sources.rs Exposes the parked size-open lane through the prebuilt handoff.
CHANGELOG.md Records the duplicate-download fix.
adr/​039-multi-source-parallel-fetch.md Documents first-leg planning for the retained lane.

Review effort: Balanced

@thiras
thiras merged commit 2214834 into main Oct 28, 2026
38 checks passed
@thiras
thiras deleted the fix/primed-first-leg-adoption branch October 28, 2026 23:21
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: the size open's primed whole-blob pull is closed when another lane builds in the same first batch

2 participants