Skip to content

fix(client): let a partial holder steal the covered tail of a busy leg (#2303) - #2304

Merged
thiras merged 1 commit into
mainfrom
fix/steal-covered-tail-2303
Oct 3, 2026
Merged

thiras merged 1 commit into
mainfrom
fix/steal-covered-tail-2303

Conversation

@thiras

@thiras thiras commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What

A freed lane stole from a busy lane only when its 64 MiB block coverage held the victim's whole range in flight. A partial holder that covered the back of a big leg could never steal it. In the 2026-10-03 testnet mistral-7b bundle pull, fra1 held blocks 0–43 of shard b32596 as one 2.95 GB leg. hel1 covered blocks 18–45 and went idle in seconds, so fra1 served the leg alone: 497.7 s at ~6 MB/s, with the node idle 98% of the time waiting on the client. That leg set the run's wall time.

  • coverage_plan::covered_suffix_start gives the start of the longest suffix of a range whose blocks the source covers. It returns None when the source does not cover the range's last block.
  • segment::steal_split takes covered_from in place of covers. It first drops any range below MIN_SPLIT_SIZE overall, or below MIN_STOLEN in its covered suffix. It then picks the range whose covered suffix misses the most. A split by rate that lies before the suffix moves to the suffix's start, and the victim keeps every byte before it.
  • Work::plan_steal is the read-only half of Work::steal. has_work_for calls it, so a holder starts only when it would steal now. A late partial holder starts and steals. A holder whose only option is a tail below the floors does not take a lane slot just to park.
  • ADR 039 (§ Dynamic segmentation and tail-stealing, and Decision 6) and the CHANGELOG describe the covered-part rule.

Closes #2303

Reviewer notes

  • Fully covered ranges behave as before. covered_suffix_start returns Some(start) in exactly the cases where covers_byte_range returned true. The floor filter before the argmax keeps the old victim, including on ties.
  • A stolen tail never starts before the covered suffix. The suffix start is a block boundary, and a block is a multiple of a chunk group. The race branch in Work::steal, which restarts the tail at the victim's frontier, stays at or past the split.
  • A lane whose blocks stop before a range's last block still cannot steal from that range. In the example above, a lane covering blocks 25–42 cannot steal fra1's 0–43 leg.
  • has_work_for is approximate. Its dry run treats every byte in flight past a victim's received frontier as missing, and it has no rate for the stealer. So it declines only steals that the size floors or the coverage rule forbid.
  • Out of scope (minor items in client: a lane cannot steal a victim's tail unless it covers the victim's whole range, so one partial-coverage leg runs alone #2303): a lane's extra worker can steal from its own sibling stream, and the steal debug line has no hash field.

Verification

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run -p decdn-client (554 passed) and -p decdn-node -p decdn-cli (2446 passed)
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items
  • New tests:
    • a_late_tail_holder_steals_the_covered_tail_and_fetches_each_byte_once runs end to end.
    • a_tail_holder_steal_moves_the_split_into_its_covered_suffix
    • a_tail_holder_has_work_only_while_its_covered_suffix_is_stealable
    • a_partial_holder_steals_the_covered_tail_of_a_busy_leg
    • Covered-tail cases in steal_split and covered_suffix_start.
    • With the old full-coverage rule put back, all four scheduler tests fail.
  • Live testnet run, mistral-7b, fleet on 418c5522, with an earlier version of this patch (same steal logic, before has_work_for ran the steal check):
    • b32596 took 305 s, against 501 s on main.
    • There were 35 steals, 14 victim stops, and no WARN or ERROR.
    • That run's wall time was 11m02s, against 8m42s on main. Most of the extra time came from bcl's legs for 7cbb48, which only bcl serves. They ran at 1–2 MB/s each, against ~6 MB/s on main, with the same 145 legs and the same 73 extra streams. bcl's serve spans show the node 97% idle waiting on the client, so the cause looks like the bcl→client path. One run cannot prove that.
  • Live testnet run with this PR's commit cc9efd2b, 02:06 UTC, same fleet: 5m42s, 0 failed, same bytes, no WARN or ERROR, 16 steals, 9 victim stops, nothing re-queued.
  • CHANGELOG.md entry added
  • ADR 039 updated
  • PR title uses fix(client): …

🤖 Generated with Claude Code

#2303)

A freed lane stole from a busy lane only when its coverage held the
victim's whole range in flight. In a mistral-7b bundle pull, fra1 held
blocks 0-43 of a shard as one 2.95 GB leg. hel1 covered blocks 18-45, went
idle in seconds and could not steal, so the leg ran alone for 8 min on one
stream.

covered_suffix_start gives the start of the longest suffix of a range whose
blocks a source covers. steal_split ranks ranges by the missing bytes in that
suffix, after the MIN_SPLIT_SIZE / MIN_STOLEN floors, and moves a split that
lies before the suffix to its start, so the victim keeps every byte before
it. A fully covered range steals exactly as before.

Work::plan_steal is the read-only half of Work::steal. has_work_for runs it,
so a holder counts as having work, and starts, only when it would steal now:
a late partial holder starts and steals, and a holder whose only option is a
tail below the floors no longer takes a lane slot to park.

ADR 039 states the covered-part rule.

Refs #2303

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 3, 2026 01:59
@thiras thiras self-assigned this Oct 3, 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.

Copilot review overview

🟢 Approval recommended

The implementation matches the stated scheduling rules and includes focused unit, scheduler, and end-to-end coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Enables partial holders to steal covered tails from busy client fetch legs.

Changes:

  • Adds covered-suffix detection and tail-aware splitting.
  • Reuses steal planning to avoid starting unusable lanes.
  • Adds scheduler coverage plus ADR and changelog updates.
File Description
crates/​client/​src/​segment.rs Implements covered-tail split selection and tests.
crates/​client/​src/​scheduler.rs Integrates read-only steal planning and partial-holder scheduling.
crates/​client/​src/​coverage_plan.rs Finds the longest covered suffix.
CHANGELOG.md Documents the fix.
adr/​039-multi-source-parallel-fetch.md Specifies covered-tail stealing behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit cc9efd2 in the fix/steal-covered-ta... branch remains at 87%, unchanged from commit 418c552 in the main branch.

Show a line coverage summary of the most impacted files.
File main 418c552 fix/steal-covered-ta... cc9efd2 +/-
crates/cache/src/engine.rs 95% 94% -1%
crates/client/src/lib.rs 92% 92% 0%
crates/node/src...s/client/mod.rs 95% 95% 0%
crates/client/src/scheduler.rs 95% 95% 0%
crates/client/src/segment.rs 94% 94% 0%
crates/client/s...overage_plan.rs 100% 100% 0%

@thiras
thiras merged commit 7f938e6 into main Oct 3, 2026
31 checks passed
@thiras
thiras deleted the fix/steal-covered-tail-2303 branch October 3, 2026 02:18
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 lane cannot steal a victim's tail unless it covers the victim's whole range, so one partial-coverage leg runs alone

2 participants