Skip to content

fix(node): heal a restarted client whose watermark fell behind - #1954

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/recovery-watermarkbundle-access-722eb2
Sep 8, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/recovery-watermarkbundle-access-722eb2

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Problem

A client killed mid-stream and restarted gets stuck: it downloads ~1 MiB, then times out. The client persists its voucher watermark to disk only once, at end of fetch (fetch.rs:1896), committing in memory as it goes. A crash before that write loses every voucher the node already accepted, so on restart the client re-seeds its ledger from the stale watermark and re-signs from a stale anchor.

Its first voucher then lands strictly below the node's last_amount. The node classifies that as a benign already-satisfied AmountRegression (voucher.rs): it credits zero, so the per-stream credit window stays pinned at its one-chunk floor, delivery wedges at ~1 MiB, and the stream dies on the 10s voucher-read timeout. The WatermarkBundle recovery path already existed end-to-end on the client, but was unreachable — the benign-swallow never emitted a bundle, and BytesRegression never fires because the amount check runs first.

Fix

Emit the node's authoritative watermark on the wedge, reusing the existing recovery machinery (no new wire message).

  • voucher.rs — In commit_one_proof, a new stale_resume_bundle helper fires when a voucher is strictly below our watermark on the lane's sole stream. It returns a gated AmountRegression rejection carrying the WatermarkBundle; the client reseeds and reopens, paying forward from the healed anchor. Both client paths already consume it — buffered fetch_inner and the progressive driver (lib.rs:2904 → driver.rs:807). The pure, unit-tested verify_voucher is untouched.
  • dispatch.rs — active_streams is now maintained whenever the lane is known, not only when on-chain pool_status is present; only the solvency surcharge still requires pool_status. This makes the sole-stream gate correct off-chain.
  • client_loopback.rs — client_restart_with_stale_watermark_heals_and_resumes reproduces the wedge (advance the lane, then fetch from a stale prior_*). Its 8s budget sits below the 10s timeout backstop, so it fails unless recovery fires fast.

Concurrency is preserved

The heal is gated on active_streams <= 1. A concurrent same-lane sibling (#1697) legitimately sends out-of-order sub-watermark vouchers whose bytes another stream's advance already covers; a terminal reject would tear down that honest stream. Those stay under the benign-swallow, and a genuinely wedged multi-stream lane still recovers via the 10s read-timeout backstop. lower_voucher_after_higher_sibling_is_already_satisfied still passes.

Verification

  • RED → GREEN: the repro wedged at 10.8s (early-eof) before; heals in 1.06s now.
  • decdn-node: 1113 passed / 0 failed. client-pull + incentive: 502 passed / 0 failed.
  • clippy --all-targets --all-features, fmt --check, and the doc-link gate (RUSTDOCFLAGS=-D warnings) all clean.

Reviewer notes

  • The progressive driver path is verified by code (it feeds the pre-existing reseed/re-anchor loop), but the new integration test exercises the buffered path. A driver-path anvil e2e could follow if wanted.
  • Worst-case healing re-delivers and re-pays a bounded span (the reopened leg re-anchors); the direction is always over-pay, never under-pay.

🤖 Generated with Claude Code

A client that crashes mid-stream persists its voucher watermark only once,
at end of fetch, so on restart it re-seeds from a stale watermark and
re-signs from a stale anchor. Its first voucher lands strictly below the
node's last_amount, so the node classifies it as a benign already-satisfied
AmountRegression: it credits zero, the credit window stays pinned at the
one-chunk floor, and the stream wedges at ~1 MiB until the 10s voucher-read
timeout drops it. The WatermarkBundle recovery path existed but was
unreachable, because the benign-swallow never emitted a bundle.

Emit the authoritative watermark on the wedge. In commit_one_proof, when a
voucher is strictly below our watermark on the lane's SOLE stream, hand back
a gated AmountRegression rejection carrying the WatermarkBundle so the payer
reseeds and resumes (both the buffered and progressive client paths already
consume it). The reject is terminal; the reopened leg pays forward from the
healed anchor.

Preserve out-of-order same-lane concurrency: the heal is gated on
active_streams <= 1. A concurrent sibling (#1697) legitimately sends
out-of-order sub-watermark vouchers whose bytes another stream's advance
already covers, and a terminal reject would tear down that honest stream. A
genuinely wedged multi-stream lane still recovers via the read-timeout
backstop. To make that gate correct off-chain, maintain active_streams
whenever the lane is known; only the solvency surcharge still requires a live
pool status.

Add a loopback repro: advance the node lane, then fetch again from a stale
prior_* watermark. Its budget sits below the 10s timeout, so it fails unless
recovery fires fast.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 8, 2026 15:04

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.

🟡 Changes recommended

The new stale-resume reject path currently stamps last_voucher_at before it may reject the voucher, making the “last accepted voucher” diagnostic inaccurate, and one doc comment in the new helper contradicts the actual call order.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes a restart wedge where a client resumes with a persisted voucher watermark that has fallen behind the node’s authoritative lane watermark. It does so by having the node emit a WatermarkBundle on a gated AmountRegression rejection (sole-stream only), enabling the client to reseed and reopen using existing recovery machinery; it also adjusts lane active-stream tracking so the sole-stream gate works even without pool_status, and adds an integration test that reproduces the crash-restart desync.

Changes:

  • Add a sole-stream “stale resume” path in voucher handling to return a WatermarkBundle when a voucher amount is strictly below the lane watermark.
  • Maintain active_streams whenever the lane is known (even without on-chain pool_status) so the wallet-less-resume gate can distinguish lone-stream vs concurrent-sibling cases off-chain.
  • Add an integration test reproducing the restarted-client stale-watermark wedge and asserting fast recovery.
File summaries
File Description
crates/node/src/handlers/client/voucher.rs Adds stale-resume detection and a watermark-bearing rejection to trigger client reseed/reopen.
crates/node/src/handlers/client/dispatch.rs Updates lane admission to maintain the active-stream counter without requiring pool_status.
crates/node/tests/client_loopback.rs Adds an integration regression test covering crash-restart stale-watermark recovery.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

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

Address Copilot review on #1954:
- Decide the wallet-less-resume heal before stamping `last_voucher_at`, so a
  voucher we reject no longer advances the admin "seconds since last voucher"
  diagnostic.
- Correct the `stale_resume_bundle` doc: the caller swaps in the verified
  state BEFORE this runs; a benign sub-watermark swap leaves the watermark
  unchanged, so the bundle still reports the true frontier.

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

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Coverage report

Total: 82.71% (was 82.70%, ▲ +0.01%) — 75522/91305 lines

File Coverage Lines Δ
crates/node/src/handlers/client/dispatch.rs 85.23% 502/589 ▲ +0.05%
crates/node/src/handlers/client/voucher.rs 93.59% 526/562 ▲ +0.29%
History
Commit Total Δ vs base
643842c (HEAD) 82.71% ▲ +0.01%

@alpergundogdu
alpergundogdu merged commit ca786d9 into main Sep 8, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/recovery-watermarkbundle-access-722eb2 branch September 8, 2026 15:52
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.

2 participants