Skip to content

fix(client-pull): confirm the armed voucher on a StreamEnd read after its write failed - #1999

Merged
thiras merged 2 commits into
mainfrom
claude/voucher-write-recovery-gap-path-33edcd
Sep 14, 2026
Merged

thiras merged 2 commits into
mainfrom
claude/voucher-write-recovery-gap-path-33edcd

Conversation

@yigitdot

Copy link
Copy Markdown
Contributor

Closes #1995.

Problem

UpstreamPull::next_chunk recovers a failed voucher write by reading one terminal message: a StreamEnd marks the stream ended and the chunk is still delivered. The two loopback tests that covered it drove it through the test-util stream_fetch wrapper, whose completion is decoder-based and never consults the ledger.

On the production driver::drive / PeerSource path completion is payment-based: fill_gap derives the paid frontier from ledger.committed(). A write that fails inside PoolLedger::issue leaves that voucher armed, not committed — settlement() reports it (settle high) but committed() does not move. Traced on main with the new tests:

  • Sub-chunk blob (only a closing voucher): paid_wire_this_leg == 0, so paid_frontier == gap_start, BudgetPacer returns Draw again, and the driver re-opens the whole gap. Against a node that keeps accepting and stop-sending, each leg re-pulls the blob and arms a higher voucher (issue builds on the armed frontier) — an unbounded re-pull loop with settlement() growing every round. The RED run: three re-legs, then the fourth open timed out against the capped fixture.
  • Multi-chunk blob: the reveals commit via accrued, the residual's closing voucher stays armed, and the tail is re-pulled and re-billed.

Change

A node writes StreamEnd only once every interval — the closing voucher included — is paid (handlers/client/delivery.rs, serve_leg.rs). So the StreamEnd the recovery reads proves the node holds the voucher whose write failed.

  • PoolLedger::confirm_armed: commits the armed voucher exactly as a successful issue would (the epoch already rolled when it was armed); None when nothing is armed (a sibling on the shared lane issued past it).
  • terminal_after_write_failure calls it on StreamEnd and anchors the stream's last_proof / anchored_root to the confirmed voucher; next_chunk clears unproved once the recovery returns Ok.
  • Nothing the client persists as owed changes — settlement() already reported the armed amount; committed() now catches up to it.

Tests

All RED before the fix, GREEN after.

  • ledger::a_terminal_stream_end_confirms_the_armed_voucher — failed issue → confirm_armed commits it once, committed == settlement, the next voucher builds on it.
  • drive_completes_in_one_leg_when_its_send_is_stopped_before_the_closing_voucher (256 KiB) and …_after_reveals_… (1.5 MiB; the stop lands after the first reveal's proofs are read, via a new StopPoint::AfterFirstReveal) — run the production drive + PeerSource + ClientRangedStore wiring against a connection-counting stop-send upstream capped at three accepts (a re-leg loop fails fast instead of hanging). Assert: one connection, the blob promoted, committed == settlement == wire(blob).
  • drive_surfaces_typed_rejection_when_… — the VoucherRejected twin errors with UpstreamVoucherRejected on one connection, promotes nothing, confirms nothing.

Fixture: serve_stop_send_then_signal now honours [byte_offset, byte_len); honest_bao_wire_range moves into tests/support so both node suites share it.

Verification

cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --check, RUSTDOCFLAGS=-D warnings cargo doc --workspace --no-deps --document-private-items, cargo nextest run --workspace --no-fail-fast (3422 passed; one unrelated probe-cache test flaked and passed on retry).

Out of scope

A failed reveal write followed by StreamEnd (wire an exact multiple of 1 MiB) has no armed state to confirm — meter does not consume the index on a failed send — so the driver would still re-leg that one chunk. Rare and not this issue's case; worth its own follow-up.

🤖 Generated with Claude Code

… its write failed

A node writes StreamEnd only once every interval, the closing voucher included,
is paid. So the StreamEnd the voucher-write recovery reads proves the node holds
the voucher whose write its STOP_SENDING failed. The ledger kept that voucher
armed, not committed: settlement() reported it (settle high) but committed() did
not move, and driver::fill_gap decides completion from committed(). A sub-chunk
leg therefore cleared nothing and the driver re-opened the whole gap; against a
node that keeps accepting and stop-sending that was an unbounded re-pull loop
arming a higher voucher every round, and a multi-chunk leg re-pulled its tail.

PoolLedger::confirm_armed commits the armed voucher exactly as a successful issue
would; the recovery calls it on StreamEnd and anchors the stream's last proof to
it. Pinned on the production drive + PeerSource + ClientRangedStore path against
a connection-counting stop-send upstream: one connection, the blob finalized,
committed == settlement == one honest wire, for both the sub-chunk and the
reveals-then-residual shapes; the typed-rejection twin confirms nothing and does
not re-leg.

honest_bao_wire_range moves into the shared test support so both node suites
serve honest range encodings for a re-opened gap.

Closes #1995.

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.73% (was 82.71%, ▲ +0.03%) — 76870/92914 lines

File Coverage Lines Δ
crates/client-pull/src/ledger.rs 96.96% 925/954 ▼ 0.10%
crates/client-pull/src/lib.rs 89.07% 1720/1931 ▼ 0.44%
crates/node/src/handlers/client/delivery.rs 92.73% 319/344 ● 0.00%
crates/node/src/handlers/client/mod.rs 94.95% 2068/2178 ● 0.00%
crates/node/src/handlers/client/serve_leg.rs 74.59% 138/185 ● 0.00%
History
Commit Total Δ vs base
6c05be5 82.72% ▲ +0.02%
06d8180 (HEAD) 82.73% ▲ +0.03%

…ater accrual

`confirm_armed` runs after the failed send released the issuance lock, so
the lane can move between the arming and the confirm:

- A sibling's reveal on the rolled chain accrues in that window. The
  confirm now subtracts only the accrual the voucher folded (recorded
  when it is armed) instead of zeroing `accrued`.
- A sibling's failed voucher can be armed on top of this stream's. The
  failed `send_voucher` tags its error with the amount it tried to send
  (`UnconfirmedVoucher`), and `confirm_armed(amount)` commits only a
  matching voucher. A failed reveal or re-anchor write confirms nothing.

The recovery logs whether a `StreamEnd` confirmed a voucher, and clears
`unproved` only when it did. A missing voucher provider is marked
`LocalPullFault`, so the recovery never masks it.

The stop-send drive tests capture the recovery's event and assert it
fired, so a voucher write that wins the race cannot pass them silently.
The node drain docs no longer describe the closing voucher as in flight
after `StreamEnd`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01EGFxSuztfWaNLHZyQ8irTW
@thiras
thiras merged commit c233632 into main Sep 14, 2026
25 checks passed
@thiras
thiras deleted the claude/voucher-write-recovery-gap-path-33edcd branch September 14, 2026 07:22
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-pull: pin the voucher-write terminal recovery on the gap-driven drive path

2 participants