Repository navigation
fix(client): bill the delivered tail a resumed leg leaves unpaid - #2728
Merged
Merged
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
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.
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 7 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. |
11 tasks done
The node streams up to one credit window ahead of the voucher that pays for it. Only a funding refusal kept the delivered-but-unpaid span on the lane. Any other early end (a lost connection, a stall, a cancel) re-queued the missing bytes alone, so the next leg opened at the delivered frontier and nothing billed the span. Under load a QUIC connection that closes mid-stream left about 2 MiB unpaid this way in cli_fetch_topup (#2718) and in the self-heal bundle journey (#2722). - fill_gap notes the owed span for every fault and prices it from the lane's settlement, which the next voucher builds on. The leg anchor lives in DriveCounters, so the acquire loop prices a leg it drops on a cancel or a watchdog trip the same way. - After a delivery fault or a cancel, the acquire loop re-queues the missing bytes from the paid frontier, and the lane that picks the range bills its owed span in the same leg, so the seam's proof path is paid once. A funding refusal keeps the span-first path the recovery gate's progress rule needs, and a leg that re-bills a span and pays nothing past it re-queues from the delivered frontier, so progress continues. - The self-heal journey never self-healed: equal sizes ordered b.bin first by hash, so a.bin's splice refused b's head and fetched it. a.bin is now smaller, and the journey asserts the self-heal witness. - Both journeys run the measured decdn get at CLIENT_DEBUG_LOG and print its stderr with every money assertion. ADR 003 § Funding recovery states the rule. Closes #2718 Closes #2722 Co-Authored-By: Claude Opus 5.5 <[email protected]>
thiras
force-pushed
the
fix/2718-client-resume-unbilled-tail
branch
from
October 28, 2026 21:54
41ead98 to
ab9f86b
Compare
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.
Root cause
Both failures are one client defect. A paid leg that ended early on anything other than a funding refusal lost the delivered-but-unpaid span the credit window had let the node stream ahead.
fill_gapnoted[paid_frontier, delivered_frontier)on the lane only forFault::Unaffordable. The acquire loop then re-queued only the store's missing bytes (requeue_missing), so the replacement leg opened at the delivered frontier and nothing ever billed the span. A cancelled or watchdog-droppedfill_gapnoted nothing at all. The comment on theCancelledarm called this a "client-favorable gap".The
CLIENT_DEBUG_LOGtrail this PR adds to both journeys shows it. Under load the first leg dies on a lost connection after the node streamed ahead, and the next leg resumes atlanded:cli_fetch_topup(#2718), settled 18095 against a floor of 20083:cli_bundle_pull_range_dedupself-heal (#2722), reproduced in isolation with the exact CI figure:landed=2080768is exactly 127 chunk groups. That matches the issue's arithmetic: head groups 0..127 delivered and unpaid, with a second leg resumed at group 127.What kills the connection
The connection loss itself matches the documented noq 1.4 gap-cap signature ("no terminal signal after the voucher write failed … connection lost"; see #2585 and #2655). noq-proto 1.4.0 closes a stream whose reader falls about 2.4 MB behind. e76ec3e (
chore(deps): update Cargo.lock, 2026-10-28 16:01) moved iroh 1.3.0 → 1.4.1 and noq 1.3.0 → 1.4.0. It landed before #2709 (19:28), so #2709 was not the trigger. iroh 1.4.1 requiresnoq ^1.4.0, and noq-proto 1.4.0 is still the newest release, so holding noq at 1.3 means holding the whole iroh family at 1.3 again. This PR does not touch the lockfile. Those connection kills still cost a cooldown and a re-delivered window per kill, so they need their own decision. The client must bill correctly whatever ends a stream, and that is what this PR fixes.Fix (client)
fill_gap(driver.rs): every leg that a fault ends notes its owed span, not only a funding refusal. The paid frontier is priced from the lane'ssettlement(), because the lane's next voucher builds on a voucher armed when the connection dropped. The leg anchor now lives inDriveCounters::leg_anchor, so a caller that dropsfill_gapmid-leg can price the span (ended_frontiers, nowpub(crate)).requeue_fromre-queues the first missing run from the paid frontier. The leg that takes it reopens there and merges the lane's owed spans inside the picked range into its gaps (PoolLedger::take_unpaid_within). One leg then bills the owed span and fetches the rest, so the proof path at the seam is paid once.Self-heal journey premise (#2722)
cli_bundle_pull_self_heals_a_lying_recipient_hintnever ran the self-heal. A bundle pull runs its groups smallest first and breaks a tie on the hash.a.binandb.binwere the same size, andwhole_b(1a4b…) sorts beforewhole_a(243a…), sob.binran first. Its lying hint registered b's own head ashash_donor. a's donor splice then refused it (chunk_verified: gotc782…, wante585…; the source's first bytes areprefix_b's seed) and re-fetched the head. That cost the same bytes, so the money figure still matched.a.bin's tail is now 4096 bytes shorter, so it runs first. The journey also asserts the self-heal witness ("failed its whole-file hash after range-dedup") on the measured run.Diagnostics kept
decdn_e2e::cli::CLIENT_DEBUG_LOG(info,decdn_client=debug) is set on the measureddecdn getof both journeys, and every money assertion prints that run's stderr.Tests
scheduler::tests::a_lost_connection_bills_the_delivered_tail_in_one_leg: one lane, a lost connection after 256 KiB of wire. Asserts the restart reopens(0, total)and the lane pays exactly the whole blob's wire, with nothing left owed.driver::tests::the_same_lane_bills_its_owed_tail_after_a_lost_connection: the driver-level twin of the funding-refusal test.scheduler::tests::only_a_delivery_end_requeues_from_the_paid_frontier: the requeue rule table.driver::tests::mid_gap_fault_resumes_at_the_checkpoint_not_the_whole_gapnow asserts the stall leaves the prefix owed. It then drops the span the way a new process does, which keeps no owed span.Mutation check (each mutation applied alone, restored from a copy, then
touched):a_lost_connection_…_in_one_leg…_after_a_lost_connectionUnaffordable(old driver)Verification
Before the fix, with the 12-binary journey batch below on a loaded 16-core host, the first run failed both journeys: settled 18095 against 20083, and the self-heal journey did not self-heal. In isolation, 3 of 5 self-heal runs had a leg killed at
landed=2080768. Both of those runs that reached the money assertion reported exactly 6734774.After the fix, the same batch was run 10 times at
DECDN_NODE_LOG='info,decdn_client=debug'. Other agents' e2e runs shared the host. Out of 230 test runs, 227 passed:fetch_of_blob_far_exceeding_deposit_settles_whole_wire_cost_oncepassed 10/10.cli_bundle_pull_self_heals_a_lying_recipient_hintpassed 10/10.Failed to bind sockets,Address already in use), and one e2e: bundle striping over-bills 448 wire bytes under parallel load #2663. e2e: bundle striping over-bills 448 wire bytes under parallel load #2663 over-bills 448 wire bytes, the same figure the pre-change CI job shows.Isolated self-heal ×10 after the fix: 10/10 passed with the self-heal witness. In 4 runs the first leg was killed at
landed=2080768. The restart then openedbyte_offset=0 byte_len=4390331and billed the blob exactly.cargo nextest run -p decdn-client: 1196/1196 passed.cargo clippy --workspace --all-targets --all-features -- -D warnings,cargo fmt -- --check,CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-itemsandmake -C adr check-refsare all clean, and every pre-commit hook passes. The public API is unchanged: every new item ispub(crate).Not in this PR
Closes #2718
Closes #2722
🤖 Generated with Claude Code