Repository navigation
fix(node): stop a stream whose pool closes mid-stream - #2812
Conversation
The mid-stream pool re-check in both serve loops failed open when the pool view no longer held the pool, and never read the pool's lifecycle. A stream kept running on a closed pool, or on a Closing pool past its dispute deadline, where redeemMany reverts PoolClosed and the node is not paid. pool_recheck_stop now stops the stream in-band with PoolExhausted when the view holds no status for the pool, or when the pool is Closing and its deadline falls inside the capability expiry margin (one redeem interval plus the landing slack). The stop is ServeStop::PoolClosed and counts on decdn_serve_stream_midstream_pool_closed_total, which replaces decdn_serve_pool_recheck_skipped_total. With no pool view wired the check still fails open. The signer cap re-check runs only after the pool re-check passes, so it never reads a forgotten pool's zero spend. Closes #2805 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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. 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.
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. Updated |
Three comments still said a pool missing from the projection makes the serve gate fail open; a forgotten pool now refuses admission and stops any live stream as PoolClosed, so say that. The pool-closed counter docs claimed redeemMany reverts on a Closing pool inside the margin; it reverts only past the deadline — the margin stop runs early so the last sweep can land. Bind "redeem margin" to its definition, restore the repaid-pool remaining > M clause in the loop comments, note the reorg self-heal on pool_recheck_stop, and drop a dangling "Both". Tests: pin the close-over-drain precedence (a Closing pool at its deadline that is also drained stops as PoolClosed), drive the PoolExhausted branch of pool_recheck_stop directly, and assert the drained-pool loopback stops count zero on the pool-closed counter. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Ran the four-agent review (code, tests, comments, silent failures) on e7ec33a: no critical findings. 3a99069 addresses the rest — three stale fail-open comments, the redeemMany-reverts overstatement for a Closing pool inside the margin, a close-over-drain precedence unit test plus a direct PoolExhausted-branch test, counter-separation asserts in the drained-pool loopback tests, a reorg self-heal note, and wording nits. The one real out-of-scope finding (the redeemer has no close-deadline wake, so the margin's last sweep is a window, not a guarantee) is filed separately. |
…pool-termination-d7dadd # Conflicts: # adr/003-payments.md
A forgotten pool's signer reads spent = 0 in the production projection, so the signer re-check alone would keep serving. The new loopback test pins that the pool re-check stops the stream first, as a pool close. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| if let Some(stop) = self.pool_recheck_stop(&lane_key, &hash).await { | ||
| self.write_reject(send, VoucherRejectReason::PoolExhausted, None) | ||
| .await?; |
There was a problem hiding this comment.
Partly fixed in fd6c529; the rest is out of scope or by design.
- Check only after the batch. Fixed. Both loops now also run
pool_recheck_stopbetween proofs, once a batch outlasts one re-check interval (per-batch clock, so a fast batch never reads the pool there). Inserve_legthis also stops a slow batch from lifting the pull leg's paid frontier. New testsclosing_pool_stops_a_slow_payers_{cache_hit,serve_miss}_batch_between_proofs: the payer sends a sliver after the cutoff and holds the rest; the old loops park on the next proof, the new ones stop. - Claims past the deadline. No downstream bytes are at stake: a batch only collects proofs for chunks already sent (
pop_payable), and the re-check runs before the next delivery. Refusing a proof for bytes already sent does not recover them. - Missed last sweep when redeem hints drop. Real, but a redeemer defect: it has a capability-expiry cutoff wake (
lane_cutoff_wake) and no pool close-deadline wake. Tracked in redeemer: no close-deadline wake, so the pool-close margin's last sweep can miss #2813. - Clock/check delay in the margin. The close cutoff uses the same coarse clock and the same margin (redeem interval + landing slack) as the capability-expiry gate in both proof paths. Changing it is a design change for both gates, not this PR.
Both serve loops ran the mid-stream pool re-check only after a whole recoup batch. A slow payer could hold a batch open across many proof waits while the pool closed or crossed its redeem margin, and on a serve miss each credited proof lifted the pull leg's paid frontier. The re-check now also runs between proofs, once a batch outlasts one re-check interval. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The re-check between proofs can stop a stream after the epoch's root voucher and before the node reads the reveal the client already sent. The client keeps that reveal, so its ledger runs ahead of the node's claim. The new loopback test pins that a resumed fetch on the same ledger completes with no rebase and no rejection. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pool-termination-d7dadd # Conflicts: # adr/appendix-observability.md # crates/node/src/handlers/client/mod.rs # crates/node/src/handlers/client/tests.rs # crates/node/src/metrics.rs # crates/node/src/metrics/tests.rs # crates/node/src/pool_view.rs

Closes #2805.
Problem
The mid-stream pool re-check in both serve loops (
deliver,serve_leg) kept serving bytes the node cannot redeem:Closedpool, socached_statusreturnedNoneand the re-check failed open (fix(node): count a skipped mid-stream pool re-check and test the serve-miss PoolExhausted stop #2789 only counted it).redeemManyrevertsPoolClosed. On a serve miss the node also kept paying its upstream.signer_spent_cachedread0for a forgotten pool, so the signer cap re-check passed too.status.lifecycle.Change
ClientHandler::pool_recheck_stopreplacespool_view_status_cached. With a pool view wired it stops on:ServeStop::PoolClosed;Closing { deadline }inside the capability expiry margin (one redeem interval +REDEEM_LANDING_SLACK_SECS, viainside_expiry_margin) →ServeStop::PoolClosed. The margin leaves the redeemer one interval to sweep the last voucher;ServeStop::PoolExhausted, as before.With no view wired it still fails open.
pool_recheck_stopbetween the proofs of one batch, once that batch outlasts one re-check interval. The clock is per batch and the check waits for the first proof, so a batch that settles inside one interval never reads the pool there.PoolExhaustedfor both stops. No wire change: clients already treat it as a funding stop that keeps accepted proofs, and keep an unread proof that a later proof on the lane covers (refuses_proof). Recovery for a closed pool is a new pool (topUprevertsPoolNotOpen).spentis real.decdn_serve_stream_midstream_pool_closed_totalreplacesdecdn_serve_pool_recheck_skipped_totaland joinsINBOUND_FAILURE_REASONS. The skip-warn throttle is gone: each stream stops once.PoolExhaustedreject row. ADR 005, the observability appendix and thePoolExhausteddocstring are updated.Tests
PoolClosed; no view →None; open + funded →None;Closingat its deadline →PoolClosed; one second inside / outside the margin; drained open pool →PoolExhausted;Closingand drained →PoolClosedwins.Closingpool past its cutoff each stop in-band withPoolExhausted, finish with a FIN, and count aspool_closed, notpool_exhausted. A pool that turnsClosinga day before its deadline serves toStreamEnd.spent = 0, the production projection read): stops aspool_closed, never assigner_cap_exhausted.a_mid_stream_pool_exhausted_keeps_the_proofs_the_node_acceptednow drains after two paid intervals, so it still stops after a credited proof; the earlier drain point is the new root/reveal test.cargo nextest run -p decdn-node: 1905 passed at fd6c529; the root/reveal test passed 5 of 5 runs. Workspace clippy--all-targets -D warnings, fmt andcargo docwith warnings denied are clean.Follow-ups
INBOUND_FAILURE_REASONSby hand and need the new counter.🤖 Generated with Claude Code