Repository navigation
fix(client): stop a steal's victim at the split on its open stream and split by rate - #2299
Merged
Merged
Conversation
…d split by rate (#2290) A work steal cancelled the victim's leg, so the victim re-queued its trimmed range and opened a new paid stream for it: a new handshake, a new payment ramp and, for a pull-through holder, a restarted upstream pull. With a midpoint split, a fast lane stole from a slow one again each time it went idle, so the slow lane restarted once per halving. A steal now lowers the victim's end to the split under the same lock as the trim. The victim's leg stops on its open stream once its verified prefix reaches the split (IngestEnd::Stopped), pays for every wire byte it received (BlobSource::stop / UpstreamPull::stop), closes the stream, and ends its unit as complete. The split lies past the victim's received frontier, durable or not, and weighs the remainder by the two lanes' observed rates, so at steady rates one steal leaves both finishing together. A share by rate below MIN_STOLEN declines the steal. ADR 039 describes the rate split and the stop at the split. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Queued frames can be consumed without payment, and the frontier-to-stop race can reintroduce overlapping delivery.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
This PR changes client tail-stealing so victims stop their existing stream at a rate-weighted split instead of reopening it.
Changes:
- Adds rate-weighted stealing with live frontier and stop-point tracking.
- Adds early pull settlement and verified partial-ingest stopping.
- Updates node adapters, tests, public API snapshots, and ADR 039.
| File | Description |
|---|---|
adr/039-multi-source-parallel-fetch.md |
Documents rate-weighted stealing and stopping. |
crates/bao-range/src/lib.rs |
Tests shorter Bao encoding prefixes. |
crates/cli/src/commands/fetch.rs |
Updates settlement documentation. |
crates/client/src/driver.rs |
Stops and settles shortened legs. |
crates/client/src/lib.rs |
Adds UpstreamPull::stop. |
crates/client/src/ranged_store.rs |
Supports dynamically lowered ingest ends. |
crates/client/src/scheduler.rs |
Implements frontier-aware, rate-weighted stealing. |
crates/client/src/segment.rs |
Calculates weighted splits and range subtraction. |
crates/client/src/source.rs |
Extends source and ingest interfaces. |
crates/client/src/streamer.rs |
Updates test source implementation. |
crates/client/tests/snapshots/public_api__public_api.snap |
Records public API changes. |
crates/node/src/node_origin/admit_store.rs |
Rejects node-side early stopping. |
crates/node/src/node_origin/backend_source.rs |
Rejects backend early stopping. |
crates/node/src/node_origin/timed_source.rs |
Delegates source stopping. |
crates/node/tests/client_loopback.rs |
Tests settlement and lane reuse after stopping. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…er race `UpstreamPull::stop` reads arrived frames, without waiting, to reach a rejection behind them. It discarded those frames unpaid. It now counts them as received, under the same promised-length and ceiling bounds as `next_chunk`, so the closing voucher pays for them. A steal read the victim's frontier, then lowered its end. A victim on another thread could verify past the split in between. The steal now lowers the end first and reads the frontier again, `SeqCst` on both sides. A victim already past the split moves the stolen tail's start up to its frontier, so the two overlap by at most one chunk group and no byte is left unowned. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A unit's rate counted from its pick, so a leg's open, a pull-through victim's cold first byte and time parked on the consumer all read as a slow source. The rate split then handed the stealer too large a share. The rate now counts from the unit's first verified byte and leaves out the time the unit spent parked on the consumer. `fill_gap` takes the unit's progress (verified bytes, frontier, first-byte time) as one `UnitProgress`. `ClientMessage::StreamEnd` is documented as the node's end of a fully delivered and paid range, which is how it is used. ADR 039 says a stopped victim stream forfeits its lane's ramp credit under ADR 003. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
|
Follow-ups in 8c51185:
|
…m-at-split-2290 # Conflicts: # crates/client/src/scheduler.rs
Code Coverage OverviewLanguages: Rust Rust / code-coverage/cargo-llvm-covThe overall line coverage in commit e848864 in the Show a line coverage summary of the most impacted files.
Updated |
…m-at-split-2290 # Conflicts: # crates/client/src/lib.rs # crates/client/src/scheduler.rs
3 tasks
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.

Closes #2290
Summary
Unit::stop_at) to the split under the sameWorklock as the trim. The victim's leg stops on its open stream once its verified prefix reaches the split (IngestEnd::Stopped). It then pays for every wire byte it received (BlobSource::stop→UpstreamPull::stop), closes the stream, and ends its unit as complete, with nothing re-queued. The cancel path stays for a proven size past the range and for consumption pacing.MIN_VICTIM_KEEP(4 MiB) past that frontier.r_v / (r_s + r_v)of the remainder, or half when either rate is unknown. A slow victim is stolen from once, not once per halving. A stealer's share by rate belowMIN_STOLEN(8 MiB) declines the steal, because the victim finishes it sooner than a fresh stream would.UpstreamPull::stop. It first reads, without waiting, anyVoucherRejectedthat has already arrived, and rewinds the rejected proof asfinishdoes. Our ownLocalPullFaultsurfaces as an error. A closing voucher that fails to send stays armed:settlement()counts it, and the next leg pays for those bytes again.LocalPullFault.min_victim_keep. The scheduler module docs are updated to match.Test plan
a_slow_victim_is_stolen_from_once: fast and slow throttled sources. Expect one steal, one stream for the victim, one stop, and no byte fetched twice. With the midpoint split forced back in, this test fails with two steals.a_steal_splits_the_victims_missing_remainder: the victim opens once and stops at the split.a_steal_lowers_the_victims_end_and_does_not_cancel_it.a_steal_splits_past_the_victims_received_frontier.a_steal_splits_by_the_two_lanes_rates.segmenttests: rate split, half fallback, keep floor, tiny-share decline,without_runs.ingest_stream_until_stops_at_a_lowered_end: the wire read equals the shorter range's encoding.a_shorter_range_encodes_as_a_prefix_of_a_longer_one.fill_gap_stops_its_leg_at_a_lowered_end: one open, one stop, pays the wire up to the split.a_pull_stopped_at_a_split_pays_what_arrived_and_the_lane_pulls_on, against a real node: the stopped pull pays exactly the received wire, and the next leg on the same ledger completes.node_admit_store_refuses_a_stop_point_as_a_local_fault.growth_is_asked_again_once_a_stream_freesnow asserts retry-clock timing directly. The dead node no longer has to come back: the busy lane's received bytes no longer count as missing, which leaves it under the steal floor.fmt, clippy--all-features -D warnings,cargo doc -D warningsand pre-commit pass. The public-API snapshot is regenerated.bundle pull. Expect no "cancelled leg re-queued" after a steal, and about one "stole the tail" per slow victim. Also check the "a lane stopped its stream at a steal split" lines.decdn_serve_stream_client_abandoned_totalshould rise at most once per victim unit.Known follow-up
The node still counts the victim's early close as an abandoned stream, and this probably forfeits that lane's ramp carry. It now happens once per victim unit, not once per steal.
🤖 Generated with Claude Code