Skip to content

fix(client): bill the delivered tail a resumed leg leaves unpaid - #2728

Merged
thiras merged 1 commit into
mainfrom
fix/2718-client-resume-unbilled-tail
Oct 28, 2026
Merged

thiras merged 1 commit into
mainfrom
fix/2718-client-resume-unbilled-tail

Conversation

@thiras

@thiras thiras commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

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_gap noted [paid_frontier, delivered_frontier) on the lane only for Fault::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-dropped fill_gap noted nothing at all. The comment on the Cancelled arm called this a "client-favorable gap".

The CLIENT_DEBUG_LOG trail 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 at landed:

cli_fetch_topup (#2718), settled 18095 against a floor of 20083:

WARN decdn_client::source_set: a lane faulted; its remainder goes to the other lanes offset=0 len=20975633 landed=17743872 fault=Source error=no terminal signal after the voucher write failed; recovery read failed: frame read failed: frame I/O error: connection lost: write failed: frame I/O error: connection lost
DEBUG decdn_client::source: opening a paid leg byte_offset=17743872 byte_len=3231761

cli_bundle_pull_range_dedup self-heal (#2722), reproduced in isolation with the exact CI figure:

WARN decdn_client::source_set: a lane faulted; ... offset=0 len=4394427 landed=2080768 fault=Source error=no terminal signal after the voucher write failed; recovery read failed: frame read failed: frame I/O error: connection lost: voucher for cumulative amount 86 did not confirm: write failed: frame I/O error: connection lost
DEBUG decdn_client::source: opening a paid leg byte_offset=2080768 byte_len=2313659
Error: self-heal must pay exactly a's whole file plus b's complement plus b's re-driven head = 8823222, got 6734774

landed=2080768 is 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 requires noq ^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's settlement(), because the lane's next voucher builds on a voucher armed when the connection dropped. The leg anchor now lives in DriveCounters::leg_anchor, so a caller that drops fill_gap mid-leg can price the span (ended_frontiers, now pub(crate)).
  • Acquire loop (scheduler.rs):
    • A unit that a cancel or the watchdog drops mid-leg notes its owed span the same way.
    • After a delivery fault or a cancel, requeue_from re-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.
    • The worker's start-of-run owed-span loop leaves spans a queued range covers to that range.
    • Funding refusals keep the established path (span billed alone first, remainder from the missing bytes). The next recovery step needs bytes verified since the last one, and a leg that first re-delivers the owed span can hit the same refusal with none.
    • A leg that re-billed an owed span and paid nothing past its start re-queues from the delivered frontier. So a source that keeps failing at one point cannot stop progress.
  • ADR 003 § Funding recovery states the rule. There is a CHANGELOG entry.

Self-heal journey premise (#2722)

cli_bundle_pull_self_heals_a_lying_recipient_hint never ran the self-heal. A bundle pull runs its groups smallest first and breaks a tie on the hash. a.bin and b.bin were the same size, and whole_b (1a4b…) sorts before whole_a (243a…), so b.bin ran first. Its lying hint registered b's own head as hash_donor. a's donor splice then refused it (chunk_verified: got c782…, want e585…; the source's first bytes are prefix_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 measured decdn get of 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_gap now 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):

Mutation a_lost_connection_…_in_one_leg …_after_a_lost_connection
note only on Unaffordable (old driver) FAIL FAIL
requeue the missing bytes alone FAIL pass
no owed-span merge at pick FAIL pass

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:

    -E 'binary(cli_bundle_pull_pool_id) | binary(cli_bundle_pull_range_dedup) | binary(cli_fetch_delegated) | binary(cli_fetch_recovers_one_holder) | binary(cli_fetch_resume) | binary(cli_fetch_topup) | binary(cli_fetch_two_data_dirs) | binary(cli_quote) | binary(cli_receipt) | binary(gateway_concurrent_pulls) | binary(gateway_pointer) | binary(gateway_public)'
    
  • 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 opened byte_offset=0 byte_len=4390331 and 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-items and make -C adr check-refs are all clean, and every pre-commit hook passes. The public API is unchanged: every new item is pub(crate).

Not in this PR

  • The iroh/noq lockfile hold (see above).
  • A fetch that completes without the owing lane running again still leaves its span unpaid. An example is a funding stop whose credit window already reached the blob's end. Owed spans are also in memory only, so a new process does not know them. ADR 003 records both as the node's bounded credit-window loss.

Closes #2718
Closes #2722

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings October 28, 2026 20:38

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.

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

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main f2bc01c fix/2718-client-resu... 41ead98 +/-
77% 77% 0%
View coverage of the 7 most impacted files.
File main f2bc01c fix/2718-client-resu... 41ead98 +/-
crates/protocol/src/framing.rs 93% 92% -1%
crates/client/src/lib.rs 89% 89% 0%
crates/client/src/scheduler.rs 94% 94% 0%
crates/client/src/driver.rs 96% 96% 0%
crates/node/src...gin/pull_leg.rs 84% 84% 0%
crates/client/src/ledger.rs 98% 98% 0%
crates/node/src/dht/publish.rs 78% 80% +2%

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

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
thiras force-pushed the fix/2718-client-resume-unbilled-tail branch from 41ead98 to ab9f86b Compare October 28, 2026 21:54
@thiras
thiras merged commit 9c66bef into main Oct 28, 2026
1 check passed
@thiras
thiras deleted the fix/2718-client-resume-unbilled-tail branch October 28, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants