Skip to content

fix(client,cli)!: escrow and drain follow-ups (#2508, #2513, #2515, #2517) - #2523

Merged
thiras merged 6 commits into
mainfrom
fix/client-escrow-drain-followups
Oct 18, 2026
Merged

thiras merged 6 commits into
mainfrom
fix/client-escrow-drain-followups

Conversation

@thiras

@thiras thiras commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR closes the four open follow-ups from the #2500–#2518 escrow and drain series, one commit each, plus a commit with the review fixes.

  • fix(client): a fatal lane build drops the rest of its batch, and an escrow in it goes unnamed #2508: a fatal lane build names every escrow in its batch.
    • The acquire loop returned on the first fatal result in a batch of ready builds and dropped the rest. A second build in that batch that may have escrowed USDC was named nowhere.
    • Now each such escrow is folded into the error the fetch ends with, with the escrow as the root. The [disk fault, EscrowUntracked] case from the issue comment is covered.
    • The "first escrow, or context on the first" step now lives in fault::fold_escrow, shared with run_groups.
  • fix(client): the build drain starts a refill after the fetch ended #2513: a lane build sends no openPool or topUp after its fetch ended.
    • SourceProvider::connect takes an ended: &CancellationToken. acquire and first_open create one token per acquire and cancel it as their drain starts.
    • escrow_top_up and the fresh-open path check the token before the allowance leg and again before the call. A build that has ended fails with FetchEnded, which is logged at debug and makes no wallet read.
    • A build already inside its openPool or topUp call runs to its receipt.
    • The token is per acquire, not per LaneSources, because one LaneSources serves the first open, the acquire, and a re-fetch after a hash mismatch.
  • fix(client,cli): a second Ctrl-C between a receipt read and its record names no escrow #2515: an escrow stays named until its record commits (BREAKING for decdn-client).
    • open_pool and top_up now return an UnrecordedEscrow beside the outcome. The handle keeps the transaction pending until the caller calls recorded() or untracked(err).
    • untracked(err) holds the escrow as untracked before it releases the pending entry, so a second Ctrl-C during the record fsync still names the tx. An error that is not an EscrowUntracked keeps the entry pending.
    • RunFunding::note_untracked is gone. decdn pool open and decdn pool top-up hold their failures on the handle too.
    • A pending line now reads "was broadcast and no local record credits it". That is true both before and after the receipt read.
  • fix(client): a halted bundle pull can leave a pool replacement, unrun entries and a pending escrow unreported #2517: a halted bundle pull reports its replacement, the entries it did not run, and its pending escrows.
    • The pull reads the replacement from the recovery gate (RecoveryGate::replaced, PassReplacement). Only a replacement that ended the first pass runs the rest again.
    • A pull clears a replacement left on the gate from before it, so a later pull on the same puller runs no extra pass.
    • Every group starts as not run, so the new BundleReport::not_run makes the counts add up. The CLI summary and --json show it.
    • pull_end folds pending escrows into the end of a pull that was not interrupted. The CLI no longer names a pending escrow twice when the error already names it in its text.

The review commit also adds ScriptedRpc::after_calls (decdn-incentive test util). It is a hook that runs as the last scripted eth_call is answered, so a test can end the fetch between the allowance read and the send.

Closes #2508
Closes #2513
Closes #2515
Closes #2517

Follow-ups filed

Test plan

  • cargo nextest run -p decdn-client -p decdn-cli -p decdn-node -p decdn-incentive: 3873 passed
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items
  • Public API snapshot regenerated. The only diffs are UnrecordedEscrow, the open_pool/top_up return types and BundleReport::not_run.
  • The new fix(client): a fatal lane build drops the rest of its batch, and an escrow in it goes unnamed #2508 tests fail on the base commit.
  • Mutation checks catch the faults they target:
    • dropping the drain's ended.cancel()
    • removing each fetch-end check, the second checks included
    • removing the FetchEnded short-circuit in refill_if_low
    • releasing the entry at the receipt read
  • anvil e2e cli_fetch_topup and pool_floor_ceiling_aggregate: 4 passed (these drive the open_pool/top_up callers that changed). They ran on the four fix commits, before the review commit.
  • Five review agents: code, silent failures, tests, comments, types. Their findings are fixed in the last commit or filed above.

🤖 Generated with Claude Code

thiras and others added 5 commits October 18, 2026 13:04
The acquire loop returned on the first fatal result in a batch of
ready lane builds and dropped the rest. Those builds were already out of
`connecting`, so the drain never saw an escrow among them. Each one is
now folded into the error the fetch ends with, as the drain folds a late
build's, with the escrow as the root.

Closes #2508

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ch ended

A lane build still in flight as a fetch ended could reach its refill in
the drain and send a recorded topUp, or open a pool, for a lane that
never runs. Each acquire (and first open) now hands its builds a token
it cancels as its drain starts. A build that reaches its openPool or
topUp afterwards refuses with FetchEnded, which the drain logs at debug;
a build already past its send runs to its receipt. The token is per
acquire, since one LaneSources serves the first open, the acquire, and a
hash-mismatch refetch.

Closes #2513

Co-Authored-By: Claude Opus 5.5 <[email protected]>
open_pool and top_up released a mined transaction from the
UnconfirmedEscrows handle as soon as they read its receipt, before the
caller's synchronous record write. A second Ctrl-C (process::exit)
during that write named no escrow, and a re-run escrowed again.

Both now return an UnrecordedEscrow beside the outcome. The handle keeps
the transaction pending until the caller resolves it: recorded() once
the write commits, or untracked(err) once it fails, which holds the
escrow as untracked before it releases the pending entry, so the handle
names the tx at every moment. open_pool holds an open with no PoolOpened
event itself. RunFunding::note_untracked is gone; every site resolves
through the guard. decdn pool open / top-up hold their failures on the
handle too.

BREAKING CHANGE: buyer_pool::open_pool and buyer_pool::top_up return
(OpenedPool, UnrecordedEscrow) and (ToppedUpPool, UnrecordedEscrow).

Closes #2515

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…entries and pending escrows

Three gaps at the end of a pull one entry ended:

- The replacement came only from the pull's stop, so a sibling's
  replacement during the drain, or one a late escrow folded over, went
  unreported and the CLI printed no reclaim note. The pull now reports
  the replacement the recovery gate holds (RecoveryGate::replaced),
  ignoring one carried from before the pull. Only a replacement that
  ended the first pass runs the rest again or calls
  observer.pool_replaced.
- BundleReport::not_run counts the entries the pull did not run,
  including groups it never settled, so the counts add up; the CLI
  summary and --json show it.
- pull_end folds the handle's pending escrows into a non-interrupted
  end, as it folds untracked ones, so a BundlePuller caller hears of an
  entry dropped mid receipt read. The CLI dedupes pending escrows the
  error already names as text.

Closes #2517

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- UnrecordedEscrow::untracked keeps the transaction pending unless the
  handle holds the error's escrow, so a non-EscrowUntracked error cannot
  leave a tx named nowhere. A private release() covers a reverted
  receipt in open_pool and top_up.
- A bundle pull clears a replacement the gate holds from before it, so
  a later pull on the same puller runs no extra pass and reports it
  again. pass_replacement returns a PassReplacement enum, and every
  group starts not run, which drops fill_not_run.
- Pending escrows read "was broadcast and no local record credits it",
  true before and after the receipt read; the docs that said "receipt
  not read" now say what the pending list holds since #2515. The fetch
  end docs say a build already inside its openPool or topUp call runs
  to its receipt.
- Tests: the second fetch-end check (after the allowance leg) for a
  refill and an open, via a new ScriptedRpc::after_calls hook; first
  open's fetch end; an unheld record error keeps the escrow pending.
- CHANGELOG: name `decdn get` (there is no `decdn bundle pull`), reflow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 18, 2026 11:34
@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.

🟡 Changes recommended

Reusing a puller after a replacement retains stale funding state and can unnecessarily fund another pool.

1 open issue
What changed in this PR

Improves escrow tracking and shutdown handling in the shared client and CLI, addressing four follow-ups from the escrow and drain series.

Changes:

  • Preserves escrow reporting across fatal build batches and local record writes.
  • Prevents ended fetches from starting new funding calls.
  • Reports pending escrows, pool replacements, and unrun bundle entries.
File Description
crates/​node/​src/​buyer_pool.rs Adapts funding callers to tuple returns.
crates/​incentive/​src/​test_rpc.rs Adds a scripted-call completion hook.
crates/​e2e/​tests/​pool_floor_ceiling_aggregate.rs Updates pool-open return handling.
crates/​e2e/​tests/​cli_fetch_topup.rs Updates funding return handling.
crates/​e2e/​src/​client.rs Adapts fixture pool opening.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Records public API changes.
crates/​client/​src/​streamer/​tests.rs Forwards fetch cancellation tokens.
crates/​client/​src/​source_set/​tests.rs Updates the mock provider signature.
crates/​client/​src/​source_set.rs Adds cancellation tokens to lane builds.
crates/​client/​src/​scheduler/​tests.rs Tests batch escrow reporting and cancellation.
crates/​client/​src/​scheduler.rs Cancels ended builds and preserves batch escrows.
crates/​client/​src/​recovery/​tests.rs Tests replacement visibility.
crates/​client/​src/​recovery.rs Exposes the current replacement internally.
crates/​client/​src/​lib.rs Documents escrow guard handling.
crates/​client/​src/​lanes.rs Passes cancellation into funding setup.
crates/​client/​src/​lane_sources.rs Propagates fetch cancellation tokens.
crates/​client/​src/​funding/​adoption_tests.rs Tests cancellation and record-write escrow visibility.
crates/​client/​src/​funding.rs Guards funding calls and resolves recorded escrows.
crates/​client/​src/​first_open/​tests.rs Tests cancellation during build draining.
crates/​client/​src/​first_open.rs Cancels builds before draining.
crates/​client/​src/​fault/​tests.rs Updates untracked-escrow setup.
crates/​client/​src/​fault.rs Shares escrow error folding.
crates/​client/​src/​buyer_pool/​tests.rs Tests escrow guard lifecycle.
crates/​client/​src/​buyer_pool.rs Keeps escrows pending until records resolve.
crates/​client/​src/​bundle/​engine/​tests.rs Tests replacements, pending escrows, and unrun counts.
crates/​client/​src/​bundle/​engine.rs Updates replacement handling and final reporting.
crates/​client/​src/​bundle.rs Adds unrun counts and documents outcomes.
crates/​client/​examples/​common/​mod.rs Updates example pool opening.
crates/​cli/​src/​commands/​pool.rs Resolves escrow guards after store writes.
crates/​cli/​src/​commands/​interrupt/​tests.rs Tests duplicate escrow suppression.
crates/​cli/​src/​commands/​interrupt.rs Recognizes escrows already named in errors.
crates/​cli/​src/​commands/​fetch.rs Updates escrow lifecycle comments.
crates/​cli/​src/​commands/​bundle_pull/​tests.rs Tests unrun summary and JSON output.
crates/​cli/​src/​commands/​bundle_pull.rs Includes unrun entries in reports.
CHANGELOG.md Documents fixes and breaking API changes.

Review effort: Balanced

Comment thread crates/client/src/bundle/engine.rs Resolved
@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 36c8239 fix/client-escrow-dr... 68e918f +/-
76% 76% 0%
View coverage of the 10 most impacted files.
File main 36c8239 fix/client-escrow-dr... 68e918f +/-
crates/incentiv...src/test_rpc.rs 98% 96% -2%
crates/cli/src/...ommands/pool.rs 67% 67% 0%
crates/client/s...c/buyer_pool.rs 97% 97% 0%
crates/client/src/scheduler.rs 94% 94% 0%
crates/node/src...s/client/mod.rs 91% 91% 0%
crates/client/s...lane_sources.rs 40% 40% 0%
crates/cli/src/.../bundle_pull.rs 55% 55% 0%
crates/client/s...undle/engine.rs 64% 65% +1%
crates/client/src/funding.rs 82% 83% +1%
crates/node/src/dht/publish.rs 78% 80% +2%

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


Updated October 18, 2026 11:58 UTC

Clearing a replacement the gate held from before a pull kept the pull's
RunFunding, whose pool (a OnceLock, set by the first lane) was the
closed one. The next recovery step topped that pool up, hit
PoolNotOpen, and opened yet another pool instead of funding the one the
lanes reuse. The pull now starts as a pass against the new pool: fresh
ledgers and funding facts on the same escrow handle, as the rerun branch
does, through one start_pass_on_new_pool helper; paid_before is read
after the reset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 397f93d into main Oct 18, 2026
31 checks passed
@thiras
thiras deleted the fix/client-escrow-drain-followups branch October 18, 2026 11:59
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