Skip to content

fix(client): stop a steal's victim at the split on its open stream and split by rate - #2299

Merged
thiras merged 5 commits into
mainfrom
fix/steal-stops-victim-at-split-2290
Oct 2, 2026
Merged

thiras merged 5 commits into
mainfrom
fix/steal-stops-victim-at-split-2290

Conversation

@thiras

@thiras thiras commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Closes #2290

Summary

  • No reopen after a steal. A steal lowers the victim's per-unit end (Unit::stop_at) to the split under the same Work lock 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.
  • Split past what the victim already holds. Each unit publishes its verified frontier. A steal treats the victim's received bytes as delivered even when they are not yet durable, so the stealer never takes bytes the victim already received. The victim keeps at least MIN_VICTIM_KEEP (4 MiB) past that frontier.
  • Rate-weighted split. The victim keeps 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 below MIN_STOLEN (8 MiB) declines the steal, because the victim finishes it sooner than a fresh stream would.
  • UpstreamPull::stop. It first reads, without waiting, any VoucherRejected that has already arrived, and rewinds the rejected proof as finish does. Our own LocalPullFault surfaces as an error. A closing voucher that fails to send stays armed: settlement() counts it, and the next leg pays for those bytes again.
  • Node. The node never lowers an end. Its admit store and backend source refuse a stop, typed as LocalPullFault.
  • Docs. ADR 039 now covers the rate split, the stop at the split, and 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.
  • segment tests: 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.
  • bao-range 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.
  • Loopback 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_frees now 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.
  • Client, bao-range, node and CLI suites: 2989 passed. fmt, clippy --all-features -D warnings, cargo doc -D warnings and pre-commit pass. The public-API snapshot is regenerated.
  • Testnet: re-run the issue's 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_total should 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

…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]>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 11:27

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.

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 High severity

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.

Comment thread crates/client/src/lib.rs Resolved
Comment thread crates/client/src/scheduler.rs Resolved
thiras and others added 2 commits October 2, 2026 14:46
…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]>
@thiras

thiras commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Follow-ups in 8c51185:

  • Rate clock. A unit's rate now runs from its first verified byte and leaves out time parked on the consumer. Before this, a leg's open, a pull-through victim's cold first byte, or the consumer's pace could make a source read as slow and skew the rate split.
  • ClientMessage::StreamEnd doc. It now says node → payer, sent once the range is fully delivered and paid, which is how the code uses it.
  • ADR 039. A stopped victim stream forfeits its lane's ramp credit under ADR 003 § Credit Window. Ending the victim's stream cleanly at the split would need a wire change on both node serve paths, and the payoff is about 1 s of window regrowth per steal-stop, so it stays out of scope.

…m-at-split-2290

# Conflicts:
#	crates/client/src/scheduler.rs
@github-code-quality

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

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit e848864 in the fix/steal-stops-vict... branch remains at 87%, unchanged from commit 87916de in the main branch.

Show a line coverage summary of the most impacted files.
File main 87916de fix/steal-stops-vict... e848864 +/-
crates/node/src...timed_source.rs 100% 98% -2%
crates/client/src/driver.rs 98% 97% -1%
crates/node/src...ckend_source.rs 92% 91% -1%
crates/client/src/lib.rs 92% 92% 0%
crates/client/src/scheduler.rs 95% 95% 0%
crates/client/src/source.rs 92% 92% 0%
crates/cli/src/.../bundle_pull.rs 80% 80% 0%
crates/client/src/streamer.rs 91% 91% 0%
crates/client/s...ranged_store.rs 95% 95% 0%
crates/client/src/segment.rs 94% 94% 0%

Updated October 02, 2026 14:29 UTC

…m-at-split-2290

# Conflicts:
#	crates/client/src/lib.rs
#	crates/client/src/scheduler.rs
@thiras
thiras merged commit 2b41189 into main Oct 2, 2026
30 checks passed
@thiras
thiras deleted the fix/steal-stops-victim-at-split-2290 branch October 2, 2026 14:32
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 work steal cancels and reopens the victim's leg, so a slow tail restarts once per halving

2 participants