Skip to content

fix(client,cli)!: replacement reporting, drained-build lock waits, pool escrow tests (#2519, #2520, #2521) - #2524

Merged
thiras merged 4 commits into
mainfrom
fix/replacements-drain-pool-tests
Oct 18, 2026
Merged

thiras merged 4 commits into
mainfrom
fix/replacements-drain-pool-tests

Conversation

@thiras

@thiras thiras commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Follow-ups from the review of the #2508/#2513/#2515/#2517 batch (#2523). There is one commit per issue, then one commit of review follow-ups.

#2519: name every pool a replacement closed, on every exit

  • The RecoveryGate keeps a list of every replacement its steps make: RecoveryGate::replacements and BundlePuller::replacements. No pass or fetch clears it.
  • decdn get prints one reclaim note per closed pool from that list as the command ends, whatever the exit. That covers:
    • a blob replacement that a late lane build's escrow folded over (it survives only as text);
    • a second-pass replacement, for a blob or a bundle;
    • a Ctrl-C during a blob get;
    • a bundle get whose manifest fetch replaced the pool.
  • BundleOutcome::replaced is now a Vec<PoolReplaced>, the pull's slice of the gate's list. Breaking for library users; the snapshot is regenerated.
  • A replaced manifest fetch's error now says the new pool is current and the pull must be run again. Before, it claimed the remaining work runs again.
  • A fetch starts clear of a replacement carried over from an earlier fetch, through RecoveryGate::leave_carried. The blob and bundle paths share it.
    • In practice the carry comes from an entry URI's manifest fetch.
    • A gateway payer funds nothing, so it never carries one.
    • The doc says a gate that concurrent fetches share must not be cleared this way.

#2520: a drained lane build sends no topUp re-send and waits on no lock

  • lock_unless_ended races open_lock (in build_multi_lane) and top_up_serial (in escrow_top_up) against ended. A drained build queued behind a sibling's receipt wait now ends at once with FetchEnded, instead of at BUILD_DRAIN.
  • send_top_up checks ended before every send and ends its nonce-collision backoff when the fetch ends. The token goes through a crate-private top_up_unless_ended. The public top_up keeps its signature, so node, CLI and e2e callers are untouched.
  • A refill refused because its fetch ended logs at info that it was not sent, next to its "topping up" line.

#2521: pool open / pool top-up keep the escrow named during the record write

  • The escrow-and-record leg of each command is extracted into open_and_record / top_up_and_credit. The chain reads, the Interrupt select and the output stay where they were.
  • Tests use ScriptedRpc::mined with a WatchingStore, which notes whether the handle names the tx at each write. They cover:
    • the committed write: the tx is named during the write and released after it;
    • a failed record or credit: the escrow is held untracked on the handle.
  • test_rpc::mined_receipt lifts the client tests' receipt fixture so both crates share it.

Verification

  • cargo nextest run --workspace: 5175 passed.

  • cargo clippy --workspace --all-targets --all-features -- -D warnings, CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items, the public-api snapshot and cargo fmt --check: all clean.

  • Mutation-checked every new test. Each fails with its fix reverted:

    Mutation Test that fails
    open_lock as a plain wait a_build_queued_on_the_open_lock_ends_with_its_fetch
    top_up_serial as a plain wait a_refill_queued_on_the_top_up_lock_ends_with_its_fetch
    check-then-wait instead of a race a_lock_wait_ends_with_the_fetch
    plain backoff, no loop-top check a_collided_top_up_sends_no_re_send_after_the_fetch_ends
    gate keeps no history the gate and carried-replacement tests
    recorded() before the write, or a plain error on a failed record the pool tests
    no manifest-fetch context a_replaced_manifest_fetch_names_the_new_pool
  • The reclaim notes go to stderr from the CLI, so no unit test reads them. The gate tests pin the list they are printed from.

Closes #2519
Closes #2520
Closes #2521

🤖 Generated with Claude Code

thiras and others added 3 commits October 18, 2026 15:16
A blob `decdn get` read its pool replacement only from the pass error, so
a late lane build's escrow folded over a `PoolReplaced` hid it, and no
reclaim note named the closed pool. A second-pass replacement named only
the first closed pool, for a blob or a bundle.

`next_pass` now also reads `RecoveryGate::replaced` (pub, doc-hidden) and
runs the rest again only on a `PoolReplaced` stop. `BundleOutcome::replaced`
is a `Vec`, and the pull adds the gate's replacement after the second
pass. Every closed pool gets one reclaim note. A blob fetch starts clear
of a replacement the payer's gate carries from an earlier fetch, as a
bundle pull does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… no lock (#2520)

A `topUp` that lost its nonce was re-sent after its backoff even when the
fetch ended meanwhile. A drained build also waited for `open_lock` and the
run's `top_up_serial` before it checked `ended`, so a sibling holding
either through its receipt wait kept it for the whole `BUILD_DRAIN`.

`lock_unless_ended` races each lock against `ended`. `send_top_up` checks
`ended` before every send and ends its backoff with the fetch, through a
crate-private `top_up_unless_ended`; the public `top_up` keeps its
signature.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… record write (#2521)

Pull the escrow-and-record leg of `pool open` and `pool top-up` into
`open_and_record` and `top_up_and_credit`, generic over the provider and
taking a `&dyn BuyerPoolStore`, and drive each against
`ScriptedRpc::mined` with a store that notes whether the handle names the
tx during `record` / `add_deposit`. A change that calls `recorded()`
before the write now fails both tests.

`test_rpc::mined_receipt` lifts the client tests' receipt fixture so
both crates share it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 18, 2026 12:42
@thiras thiras self-assigned this Oct 18, 2026

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.

🟢 Approval recommended

No blocking issues were identified in the targeted fixes, API updates, or regression coverage.

No open issues 🎉

What changed in this PR

Improves payment-recovery reporting and cancellation in deCDN’s client and CLI, with regression coverage for escrow tracking.

Changes:

  • Reports every pool replacement, including second-pass replacements.
  • Cancels drained lane builds during lock waits and top-up retry backoff.
  • Tests that CLI escrow transactions remain tracked through local record writes.
File Description
crates/​incentive/​src/​test_rpc.rs Shares the mined-receipt fixture.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Records the replacement-list API change.
crates/​client/​src/​source_set.rs Documents build cancellation behavior.
crates/​client/​src/​recovery.rs Exposes replacement state for reporting.
crates/​client/​src/​lanes.rs Makes open-lock waits cancellable.
crates/​client/​src/​funding/​adoption_tests.rs Tests cancellation during lock waits.
crates/​client/​src/​funding.rs Adds cancellation-aware funding locks.
crates/​client/​src/​buyer_pool/​tests.rs Tests cancellation of top-up retries.
crates/​client/​src/​buyer_pool.rs Stops top-up retries after fetch completion.
crates/​client/​src/​bundle/​engine/​tests.rs Tests reporting multiple replacements.
crates/​client/​src/​bundle/​engine.rs Collects replacements from both passes.
crates/​client/​src/​bundle.rs Returns replacements as a vector.
crates/​cli/​src/​commands/​pool/​tests.rs Tests escrow tracking during writes.
crates/​cli/​src/​commands/​pool.rs Extracts escrow-and-record helpers.
crates/​cli/​src/​commands/​fetch/​tests.rs Tests replacement reporting and rerun limits.
crates/​cli/​src/​commands/​fetch.rs Reports replacements and shares reclaim notes.
crates/​cli/​src/​commands/​bundle_pull.rs Prints each replacement’s reclaim note.
CHANGELOG.md Documents fixes and the breaking API change.

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 397f93d fix/replacements-dra... 31d87f4 +/-
76% 76% 0%
View coverage of the 10 most impacted files.
File main 397f93d fix/replacements-dra... 31d87f4 +/-
crates/client/src/scheduler.rs 94% 94% 0%
crates/client/s...undle/engine.rs 65% 65% 0%
crates/cli/src/...mmands/fetch.rs 50% 50% 0%
crates/node/src...gin/pull_leg.rs 85% 85% 0%
crates/client/src/bundle.rs 28% 28% 0%
crates/cli/src/.../bundle_pull.rs 55% 56% +1%
crates/client/src/funding.rs 83% 84% +1%
crates/incentiv...src/test_rpc.rs 96% 97% +1%
crates/cli/src/...ommands/pool.rs 67% 70% +3%
crates/client/src/lanes.rs 58% 66% +8%

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


Updated October 18, 2026 13:30 UTC

…ups (#2519, #2520, #2521)

#2519: the recovery gate keeps the list of every replacement its steps
make (`RecoveryGate::replacements`, `BundlePuller::replacements`), which
no pass or fetch clears. `decdn get` prints one reclaim note per closed
pool from it as the command ends, however it ends: a Ctrl-C during a blob
get, and a bundle get whose manifest fetch replaced the pool, named the
closed pool nowhere. `BundleOutcome::replaced` is the pull's slice of the
list. A replaced manifest fetch now says the new pool is current and the
pull must run again, rather than that the remaining work runs again. A
fetch starts clear of a carried replacement through
`RecoveryGate::leave_carried`, shared by the blob and bundle paths. The
comment no longer claims a gateway payer can carry one: it funds nothing.

#2520: docs that still said a build inside its call runs to its receipt
name the lock-wait and re-send refusals; a refill refused because its
fetch ended logs that it was not sent. Tests cover the open-lock site in
`build_multi_lane`, a lock wait that starts on a live token, and that the
collision backoff ends with the fetch.

#2521: tests cover the record-failure path of `pool open` and
`pool top-up`: the escrow is held untracked on the handle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 1c425e4 into main Oct 18, 2026
31 checks passed
@thiras
thiras deleted the fix/replacements-drain-pool-tests branch October 18, 2026 13:32
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