Skip to content

fix(client): prime a streamed fetch's size open at the streamed drive's first leg - #2673

Merged
thiras merged 2 commits into
mainfrom
fix/stream-prime-first-leg
Oct 28, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/stream-prime-first-leg

Conversation

@thiras

@thiras thiras commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

What

With no size hint, LaneSources::first_claim read the size from a whole-blob open and primed that pull for the drive's first leg (PrimedSource::prime_next). A streamed drive cuts its first leg to the read-ahead window (WindowPacer), so the leg never matched align_range(0, 0, total). That covers decdn get -o - on the peer-store fast path, and a gateway pull whose size lookup finds none. The drive closed the primed pull and opened offset 0 again, after the node had written into the closed pull for up to a round trip.

Changes:

  • FirstLeg { Whole, Streamed { window, read_ahead } } is a new argument to first_claim. The CLI passes Streamed when the sink streams, with the same read-ahead stream_out uses (stream_read_ahead). The bundle engine passes Whole.
  • driver::streamed_first_leg predicts the streamed drive's first leg on an empty store. The draw is what the streamer's own pacer (streamer::stream_pacer, now shared with Streamer) decides on a fresh PaceState. The gap is the window widened to whole chunk groups, as the store reports it missing. The leg is cut by leg_range, the same function every drive leg uses.
  • open_first_leg opens that leg as if the blob runs past it (UNBOUNDED_SIZE), because the leg's end does not depend on the size while the blob is longer. It then primes the leg recomputed at the signed size, only when the pull covers exactly that span. A node clamps a pull that runs past the end, so on a shorter blob the clamped pull is the drive's first leg. A window that starts past the end (is_range_past_end) falls back to the whole open.
  • ADR 039 states the rule. CHANGELOG Fixed entry.

Closes #2644

Reviewer notes

  • Read first: streamed_first_leg in crates/client/src/driver.rs, then open_first_leg in crates/client/src/lane_sources.rs.
  • The waste is invisible on loopback. I measured the e2e with the fix reverted: the holders' decdn_bytes_served_total is identical (+64 B) and no stream counts as abandoned. The client's close reaches the node before it writes into the unadopted pull. On a WAN the waste is about bandwidth × RTT, up to a credit window. The fix also saves one open round trip per streamed fast-path fetch.
  • So the e2e checks the legs the client opens, not the served bytes. The new journey 3 in peer_store_probeless streams a 17 MiB + 1234 B blob, larger than the 16 MiB default read-ahead, to stdout on the fast path. It checks three things:
    • stdout equals the blob
    • the fetch did not probe: the timings line has no probe_start_ms, so the size open ran
    • no opening a paid leg … byte_offset=0 line appears, which means the drive adopted the size open's pull. Later legs do log, so the check can't pass vacuously.
  • Why not a single lane. --max-sources 1 would remove steal noise, but admit_sources truncates the candidates to 1, which is below the fast path's minimum of 3, so the fetch probes and never runs a size open.
  • Pre-existing flake, not from this PR. Journey 2's fetch #2 probed the holders N time(s) fails intermittently here: 3 of 6 runs with main's unmodified test file against these binaries. Fetch docs: Generalize architecture to content-agnostic CDN, refocus slashing on bad edges #2 is a file download, whose path this PR does not touch. The fast path re-probes in the background after the lanes start, and probes == 0 races against that. Worth its own issue.
  • lane_sources is #[doc(hidden)], so the decdn-client public-API snapshot is unchanged.

Verification

  • Unit tests (driver/tests.rs):
    • streamed_first_leg_is_the_range_a_streamed_drive_opens_first pins the predictor against a real drive under stream_pacer, over 8 cases: whole, prefix window, and off-group offsets, with and without a length, on blobs longer and shorter than the window. It also covers past-end and the held-bytes cap.
    • a_streamed_drive_adopts_a_pull_primed_at_its_first_leg: a pull primed at the predicted leg is adopted (one open of offset 0). One primed at the whole blob is reopened.
  • Mutation checks, one at a time, each caught:
    • the draw ignored
    • 1 KiB widening instead of chunk-group widening (which the pin test first caught as a real bug during development)
    • the held-bytes cap ignored
    • the CLI reverted to a whole size open (fails e2e journey 3)
  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features
  • cargo nextest run -p decdn-client -p decdn-cli: 2353 passed
  • anvil e2e peer_store_probeless: 3/3 on the final code. Siblings cli_fetch_stdout, gateway_concurrent_pulls, gateway_pointer, gateway_public, cli_fetch_multi_source, cli_fetch_resume, cli_fetch_recovers_one_holder and cli_fetch_topup: 12/12.
  • CARGO_BUILD_WARNINGS=deny cargo doc -p decdn-client -p decdn-cli --no-deps --document-private-items
  • pre-commit run on the change. cargo deny reports only the existing warn-only advisories.
  • adr/: make -C adr check-refs
  • CHANGELOG: one Fixed entry

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings October 28, 2026 03:41
@thiras thiras self-assigned this Oct 28, 2026

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

Active issues cause empty-blob streams without size hints to reject valid holders and capped range streams to reopen identical spans, retaining the duplicate-open cost.

2 open issues
What changed in this PR

This PR addresses #2644 by aligning a streamed fetch’s size-discovery open with its first transfer leg, avoiding an extra open when no size hint is available.

Changes:

  • Adds whole-download and streamed first-leg selection, with shared pacing and read-ahead calculations.
  • Primes size-discovery pulls for adoption by streamed transfers.
  • Adds regression coverage and documents the behavior.
File Description
crates/​e2e/​tests/​peer_store_probeless.rs Adds a probe-less stdout streaming journey that checks pull adoption.
crates/​client/​src/​streamer.rs Shares the stream pacer constructor.
crates/​client/​src/​lane_sources.rs Opens and primes the selected first leg for size discovery.
crates/​client/​src/​driver/​tests.rs Tests first-leg prediction and primed-pull adoption.
crates/​client/​src/​driver.rs Predicts the first streamed leg on an empty store.
crates/​client/​src/​bundle/​engine.rs Explicitly selects whole-blob size opens.
crates/​cli/​src/​commands/​fetch.rs Selects streamed legs and shares read-ahead resolution.
CHANGELOG.md Records the streamed size-open fix.
adr/​039-multi-source-parallel-fetch.md Documents first-leg size discovery and pull reuse.

Review effort: Balanced

Comment thread crates/client/src/lane_sources.rs Resolved
Comment thread crates/client/src/lane_sources.rs Resolved
@github-code-quality

github-code-quality Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 078606a fix/stream-prime-fir... 64b03b6 +/-
77% 77% 0%
View coverage of the 6 most impacted files.
File main 078606a fix/stream-prime-fir... 64b03b6 +/-
crates/client/src/lib.rs 89% 89% 0%
crates/cli/src/...mmands/fetch.rs 46% 46% 0%
crates/client/src/scheduler.rs 94% 94% 0%
crates/client/src/streamer.rs 88% 88% 0%
crates/client/src/driver.rs 96% 96% 0%
crates/client/s...lane_sources.rs 39% 40% +1%

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


Updated October 28, 2026 04:49 UTC

thiras and others added 2 commits October 28, 2026 07:39
…'s first leg

With no size hint, `LaneSources::first_claim` read the size from a
whole-blob open and primed that pull for the drive's first leg. A streamed
drive (`decdn get -o -`, a gateway pull with no size) cuts its first leg to
the read-ahead window, so the leg never took the pull. It closed the pull
and opened offset 0 again, after the node had written into the closed pull
for up to a round trip.

`first_claim` now takes the first leg the drive opens (`FirstLeg`). A
streamed size open pulls `streamed_first_leg`, which the window pacer's
first draw on a fresh state and the drive's own leg cut define, so the
open and the drive cannot drift. It opens the leg as if the blob runs past
it, primes the leg recomputed at the signed size, and falls back to a
whole open for a window that starts past the end. A download still opens
the whole blob.

Closes #2644

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed leg at the store size

A holder serves the empty blob only whole and refuses any other range of
it with `Declined`, which is not a past-end fault, so a no-hint streamed
fetch of it dropped every holder. Its size open is now the whole open.

The streamer sizes its store at the size the cap on held bytes lets the
window reach, and a drive leg's range carries that size, so a primed leg
keyed at the signed size was never adopted on a blob past the cap. The
primed leg is now built against the store's size, and still checked
against the span the node served at the signed size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras force-pushed the fix/stream-prime-first-leg branch from 4d717c9 to 64b03b6 Compare October 28, 2026 04:42
@thiras
thiras merged commit 0ab68bb into main Oct 28, 2026
37 checks passed
@thiras
thiras deleted the fix/stream-prime-first-leg branch October 28, 2026 04:54
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: a streamed fetch with no size hint still drops the pull it opened for the size

2 participants