Skip to content

fix(client): size cap-0 planning by a finite ceiling, not the peer's raw size claim - #2864

Closed
yigitdot wants to merge 3 commits into
mainfrom
worktree-fix-2843-cap0-sizing-ceiling
Closed

yigitdot wants to merge 3 commits into
mainfrom
worktree-fix-2843-cap0-sizing-ceiling

Conversation

@yigitdot

@yigitdot yigitdot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

With max_blob_bytes = 0 (the SDK Downloader/Streamer default), claim_reach returned u64::MAX. Coverage and segment planning were therefore sized by the peer's raw size claim: the unsigned probe hint, or the signed but unbounded StreamResponse.total_bytes. Planning is linear in blocks, so a 2^50 claim cost about 2 GiB and 37 s before a byte was paid for or verified. num_blocks also truncated to u32. Its comment said the limit was about 256 EiB, but with a 64 MiB block the real limit is 256 PiB, so a 2^58 claim wrapped to zero blocks.

Cap-0 sizing now reaches at most a 1 TiB ceiling past the furthest requested range start. Growth has no limit: the store's bound grows geometrically as bytes verify, so a larger blob completes and RAM stays proportional to verified progress. The same rule applies to explicit ranges:

  • A range is a tail only when it reaches the caller's raw claim.
  • Every other range that ends past the bound grows the bound as its bytes verify, but never past its own end or the claim. A cap-0 range or window longer than the ceiling completes, and no byte past its end is fetched.
  • At cap 0, a store's bound past the reach stands as far as the bytes the store already holds, so a resumed record keeps its progress.

num_blocks now saturates instead of wrapping, with both doc comments corrected. Streamer::prove_size refuses, and logs, a claim past the cap or the cap-0 ceiling instead of opening a window at the claimed end.

Trade-off at cap 0: a blob or range more than 1 TiB past its start pays about 14–15 grow rounds per extra TiB, and each round waits for the lanes to drain. Before this change it planned in one pass, from the unverified claim.

Closes #2843
Closes #2865

🤖 Generated with Claude Code

…raw size claim

With max_blob_bytes = 0 (the SDK Downloader/Streamer default), claim_reach
returned u64::MAX, so coverage and segment planning were sized by the
peer's raw size claim — the unsigned probe hint or the signed but
unbounded StreamResponse.total_bytes. Planning is linear in blocks, so a
2^50 claim cost ~2 GiB and ~37 s before a byte was paid or verified.
num_blocks also truncated to u32 silently (a 2^58 claim wrapped to zero
blocks; its comment said ~256 EiB, but a 64 MiB block makes the real
limit 256 PiB).

Cap-0 sizing now reaches at most a 1 TiB ceiling past the furthest
requested range, while the growth limit stays unbounded: the store bound
still grows geometrically as bytes verify, so a genuinely larger blob
completes and RAM stays proportional to verified progress. num_blocks
saturates at u32::MAX instead of wrapping, with both doc comments
corrected, and Streamer::prove_size refuses a cap-0 claim beyond the
ceiling instead of opening a window at the claimed end.

Closes #2843

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 13:26

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 was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-code-quality

github-code-quality Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 5bd3d25 worktree-fix-2843-ca... d8b24cb +/-
77% 77% 0%
View coverage of the 4 most impacted files.
File main 5bd3d25 worktree-fix-2843-ca... d8b24cb +/-
crates/client/src/lib.rs 90% 89% -1%
crates/client/src/streamer.rs 88% 88% 0%
crates/protocol...src/coverage.rs 100% 100% 0%
crates/client/src/scheduler.rs 94% 95% +1%

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


Updated November 11, 2026 14:04 UTC

…step wiring

The cap-free ceiling doc counts planning state, not bit-packed coverage
bitmaps (16,384 blocks is ~2 MiB of planning state, 2 KiB of bitmap per
lane), num_blocks saturates just under 2^58 bytes (u32::MAX blocks is one
block short of it), claim_reach covers the no-cap arm of its whole-blob
sentence, and the streamer cap doc names what the window reaches under the
ceiling. The ceiling doc also states the explicit-range limit: a range is
served to at most the ceiling past its start; longer ranges need a real cap.

The grow step moves into next_bound(bound, c0, extra, limit), whose doc
names the hang a reach-clamped growth would cause at cap 0, with a unit
test pinning that a bound at the ceiling grows past it under an unbounded
limit. prove_size gains an inclusive-boundary test (a claim at the ceiling
still tries the proof; one byte past opens nothing), and the uncapped
acquire test asserts its progress samples are non-empty.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alpergundogdu

Copy link
Copy Markdown
Contributor

Review

Correctness

1. A cap-0 explicit range that ends at or past the ceiling becomes a whole-blob tail (crates/client/src/scheduler.rs, Want::new)

At cap 0, c0 is clamped to furthest_start + UNCAPPED_SIZING_CEILING, and Want::new decides tail from end = c0.min(bound). Any unbounded (Downloader) explicit range that ends at or past the ceiling therefore becomes a tail. A tail follows the bound as it grows and completes only on a proven size.

Scenario: Downloader, max_blob_bytes = 0, ranges [(0, 2 TiB)], honest 10 TiB blob with a 10 TiB claim. c0 becomes 1 TiB, 0 + 2 TiB >= 1 TiB sets tail = true, fit keeps appending [old, grown), and growth_limit is u64::MAX. The fetch downloads and pays for all 10 TiB instead of 2 TiB. Before this PR reach was u64::MAX, so the range was not a tail and was clipped to its own end.

Fix: size the cap-0 reach from the caller's own range ends, which are caller-chosen, not peer-controlled: reach = max(furthest_start + CEILING, max explicit start + len). Alternatively, decide tail from the raw, unclamped claim.

2. A bounded cap-0 range longer than the ceiling pays for 1 TiB, then fails with a generic error (claim_reach)

A bounded range (a Streamer window with end) longer than the ceiling is clipped to reach - start. Once that span is present, !want.tail returns Ok, and next_verified reports stream fetch finished with X of Y bytes readable only after 1 TiB has been paid for. The caller cannot tell this from a transient fault and may retry into the same wall.

Fix: the same change as item 1. Letting the cap-0 reach extend to the caller's requested range end removes the limit, and the follow-up issue becomes unnecessary.

3. A resumed, unproven bound past the ceiling is shrunk on every run (acquire_with_watchdog, if store.total_bytes() > reach { store.set_bound(reach) })

At cap 0 reach is now finite, so this fires for a resumed record whose bound already grew past the ceiling in an earlier run. That contradicts the next comment ("A resumed record's bound wins over the caller's hint"). present_byte_ranges clamps to the bound, and the shrunk bound is flushed back to the record.

Scenario: a 3 TiB cap-0 download is interrupted at bound 2.5 TiB with 2 TiB present. On resume the bound drops to 1 TiB, and the bytes past it leave missing and base_present, so the progress bar resets. The fetch then regrows round by round, and each round waits for every lane to drain.

Fix: clamp only under a real cap, if cap > 0 && store.total_bytes() > reach. A record's bound comes from verified growth, not from a fresh claim.

4. fetch --prove blames an honest claim over 1 TiB (crates/cli/src/commands/fetch.rs, Ok(None) arm)

prove_size now returns None for any cap-0 claim over the ceiling, but the CLI logs that the claim's last chunk group is not the blob's last. For an honest 2 TiB blob, that tells the user the node lied, although no proof was attempted.

Fix: have prove_size tell the caller why it refused (for example, a distinct outcome or a log before return Ok(None)), so the CLI can say the claim exceeds the uncapped sizing ceiling and a cap is needed to prove it.

Tests

5. No end-to-end test of a cap-0 blob past the ceiling

The only coverage of "a blob larger than the ceiling completes" is the unit check next_bound(CEILING, MIB, 0, u64::MAX) > CEILING. No acquire run crosses the ceiling, and no test covers an explicit range at or past it (items 1 and 2). Because the ceiling is a fixed 1 TiB, no test can reach it. A later change that clamps grown to reach would bring back the spin-forever hang the doc comment warns about, and no test would fail.

Fix: define the ceiling in blocks, 16_384 * discovery_block_bytes(), which also matches its doc. The test-support block-size override then shrinks it, so acquire_capped can run a cap-0 blob a few blocks past the ceiling, plus explicit ranges at and past it.

Cleanup

6. prove_size copies claim_reach's cap-or-ceiling choice (crates/client/src/streamer.rs)

Fix: if claim == 0 || claim > crate::scheduler::claim_reach(&[], self.max_blob_bytes) { return Ok(None); }. With the furthest start at 0, the result is the same, and the cap-0 policy lives in one place.

7. growth_limit and next_bound are one-line wrappers with one caller each

Fix: inline let limit = if cap > 0 { reach } else { u64::MAX }; next to reach, and use grown_bound(bound, c0, extra).min(limit) at the grow step. Cover the behavior with the block-scaled end-to-end test from item 5 instead of the arithmetic unit tests.

8. The same rationale appears three times, framed around the alternative the code does not take

The growth_limit doc, the next_bound doc and the call-site comment each explain what would happen if growth were clamped to the reach. Keep one present-tense clause on UNCAPPED_SIZING_CEILING (for example, "with no cap, the bound grows without limit as bytes verify"), and reduce the others to the positive statement.

Decision for the author

  • Fix for items 1 and 2: size the cap-0 reach from the caller's range ends, which removes the explicit-range limit and the follow-up issue. Or keep that limit and fix only the tail over-fetch in item 1.

🤖 Generated with Claude Code

…gress

An explicit range is a tail only when it reaches the caller's raw claim, so
the cap-0 sizing clamp no longer turns a range short of the claim into a
whole-blob fetch. Every range that ends past the store's bound grows it as
bytes verify, never past its own end or the claim, so a cap-0 range or
window longer than the sizing ceiling completes in full.

With no cap, a store's bound past the reach stands as far as the bytes it
holds, so a resumed record keeps its verified progress. prove_size takes
its ceiling from claim_reach and logs why it refuses a claim past it.
The growth-limit wrappers are inlined, and a test-only override of the
ceiling lets end-to-end tests cross it with small blobs.

Closes #2865

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yigitdot

Copy link
Copy Markdown
Contributor Author

Addressed in ee89b63. Item by item:

1 and 2 (cap-0 explicit ranges past the ceiling): fixed with a different mechanism. I did not size the reach from the range ends, for two reasons:

  • Range ends are not always chosen by the caller. Bundle drive ranges end at the manifest entry size (complement_runs), and acquire treats manifest sizes as untrusted.
  • The fix does not cure item 1. With reach = max_end, the clamped c0 equals the range's end, so the range is still a tail.

Instead, Want now keeps each range's requested end:

  • A range is a tail only when it reaches the caller's raw claim.
  • Every other range that ends past the bound grows the bound as bytes verify, using the same geometric step as tails. It never grows past its own end or the claim.

Planning stays proportional to verified bytes. The 2 TiB range in a 10 TiB blob fetches exactly 2 TiB, a long window completes, and #2865 is closed.

3 (resumed bound shrunk): fixed, with one guard. acquire is public, so trusting any store bound at cap 0 would let a store sized directly by a claim size the planning again. At cap 0, a bound past the reach now stands as far as the bytes the store already holds. A resumed record keeps its progress, and a bare size does not size the work.

4: fixed. prove_size logs that the claim is past the cap or the sizing ceiling, and that a cap at least as large as the claim is needed to prove it. The CLI Ok(None) log now covers both causes.

5: tests added, with a different mechanism. Scaling the ceiling by discovery_block_bytes() gives 16,384 × 16 KiB = 256 MiB with the block size existing overrides use, which is too large for a unit-test blob. I added a cfg(test) override of the ceiling instead, modeled on the block-size guard. New end-to-end tests at a 64 KiB ceiling cover:

  • a whole blob past the ceiling;
  • an unbounded range past it, with no leg opened past the range end;
  • a bounded window longer than it;
  • a resumed bound past it, which is kept and not refetched.

I checked each test against the bug it guards: put that bug back and the test fails. Clamping the grow step to the reach makes the whole-blob test hang until nextest times it out.

6, 7, 8: done. prove_size uses claim_reach(&[], cap). growth_limit and next_bound are inlined and their arithmetic tests removed. The ceiling doc keeps one present-tense clause.

The remaining --max-blob-mb help nit from #2865 is in #2875.

🤖 Generated with Claude Code

@alpergundogdu

Copy link
Copy Markdown
Contributor

Superseded by #2885: every size is proven before anything is planned, so the cap-0 claim sizing this bounds (claim_reach) is deleted there, and num_blocks saturates.

@yigitdot
yigitdot deleted the worktree-fix-2843-cap0-sizing-ceiling branch November 12, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants