Skip to content

fix(client): refuse every escrow of a run after an untracked one - #2514

Merged
thiras merged 1 commit into
mainfrom
fix/2506-refuse-escrow-after-untracked
Oct 17, 2026
Merged

thiras merged 1 commit into
mainfrom
fix/2506-refuse-escrow-after-untracked

Conversation

@thiras

@thiras thiras commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

What

When a run's topUp mined and its local credit failed, the build failed as EscrowUntracked, but a sibling lane build of the same run could still escrow again. The sibling waited on open_lock, then ran in one of two places: in the acquire loop's now_or_never batch, before the loop handled the first error, or in drain_builds after it. It read the uncredited row, saw the pool low, and sent a second topUp. Nothing refused it, because the receipt read had already removed the first topUp from UnconfirmedEscrows. A failed record after a mined openPool let the next build open a second pool the same way.

  • The run holds the escrow. RunFunding holds the run's first untracked escrow (note_untracked, a OnceLock<String> of the sanitized error chain). Every site in funding.rs that builds EscrowUntracked notes it, with no .await after the failed write. The sites are the refill credit, the vanished credited row, the recovery-step credit, both pool records, and both open_pool calls.
  • Later escrows refuse. escrow_top_up (under top_up_serial), the fresh open in open_or_reuse_pool and PoolFunder::open_replacement refuse with the new pub(crate) UntrackedEscrowHeld. They refuse before their allowance read or send. classify makes the refusal Fatal(Command). It is deliberately not part of escrow_untracked(), so drain_builds does not report a refused build as a second escrow. The refusal text carries the held escrow, including its tx.
  • No wallet check on a refusal. refill_if_low and recover return the refusal without running the wallet-balance check (escrow_held). Without this, a refusal ran a balanceOf read and logged a WARN that blamed the top-up.
  • fix(client): a mined openPool with no PoolOpened event is an untyped error, not EscrowUntracked #2507: an openPool that mined with no PoolOpened event for the owner now fails as EscrowUntracked, not a plain bail!. The acquire loop treated the plain error as transient and retried, and the retry opened a second pool. The node and CLI do not downcast it, so their behavior is unchanged.

Closes #2506, Closes #2507

Reviewer notes

  • Read first: RunFunding::note_untracked / refuse_after_untracked and the RunFunding doc in crates/client/src/funding.rs. Every other change is a call site.

  • The hold is per RunFunding, not on the shared UnconfirmedEscrows handle. That follows the issue's first fix direction. An untracked escrow is fatal to the command, so no later pass runs. When a fetch or bundle group is dropped before it reports the escrow, nothing names the escrow at the end. That is fix(client): a bundle pull drops sibling entries mid-drain, losing a late escrow and allowing exit 75 #2509 for the bundle pull and fix(client,cli): an interrupted or dropped run does not name the untracked escrow it holds #2511 for Ctrl-C during the drain and the end-of-run read. fix(client,cli): an interrupted or dropped run does not name the untracked escrow it holds #2511 suggests moving the hold to the shared handle.

  • What the guarantee covers. A topUp checks under top_up_serial, which an earlier topUp holds until its outcome, so it always sees that topUp's note. An openPool that passed its check before a concurrent call's escrow went untracked still sends. The open and the refill use different locks. The note_untracked doc says so, and the review found no practical path to it.

  • Not done here: the issue's second direction, cancelling drained builds that have not submitted. It would also stop the unneeded refill after a completed fetch (fix(client): the build drain starts a refill after the fetch ended #2513). fix(client): a fatal lane build drops the rest of its batch, and an escrow in it goes unnamed #2508 (a fatal batch drops the rest of its batch) is unchanged too.

  • Tests are in funding/adoption_tests.rs, built on a new StoreFaults store wrapper that fails one write per test: credit, record, or the row after a credit.

    • A sibling refill and a recovery step after an untracked refill.
    • A refill after an untracked recovery step.
    • A topUp parked on top_up_serial while an earlier one goes untracked. The test holds the lock itself, so the order is fixed.
    • The vanished credited row.
    • An open after an unrecorded open.
    • An open with no PoolOpened event.
    • The replacement open after an untracked escrow.

    I removed each note and refusal site in turn, moved the check above top_up_serial, and narrowed escrow_held. Each mutation fails its own test. Not covered: the two notes inside open_replacement after its own open_pool and record. They have the same shape as the fresh-open notes, which are tested.

Verification

  • cargo fmt -- --check
  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features (run as -- -D warnings)
  • cargo nextest run --workspace: 5097 passed
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items
  • contracts/ changed: n/a
  • User-visible change: CHANGELOG.md entry added
  • Design change: n/a (no ADR describes the escrow refusals). Public API unchanged: the new items are pub(crate).
  • PR title uses an allowed type with a lowercase subject

🤖 Generated with Claude Code

When a run's topUp mined and its local credit failed, the build failed as
EscrowUntracked, but a sibling lane build of the same run could escrow
again. It waited on open_lock, then ran before the acquire loop handled the
first error (the now_or_never batch) or in the drain after it. It read the
uncredited row, saw the pool low, and sent a second topUp: the receipt read
had already cleared the first one from UnconfirmedEscrows. A failed record
after a mined openPool let the next build open a second pool the same way.

- RunFunding holds the run's first untracked escrow (note_untracked, a
  OnceLock). Every site in funding.rs that builds EscrowUntracked notes it,
  with no await after the failed write.
- escrow_top_up (under top_up_serial), the fresh open in open_or_reuse_pool
  and PoolFunder::open_replacement refuse with UntrackedEscrowHeld before
  their allowance read or send. classify makes it Fatal(Command); it is not
  escrow_untracked, so drain_builds does not report it as a second escrow.
- refill_if_low and recover return the refusal without the wallet-balance
  diagnosis (escrow_held).
- An openPool that mined with no PoolOpened event for the owner now fails as
  EscrowUntracked, not a plain error the acquire loop retried into a second
  open.

Follow-ups: #2508, #2509, #2511, #2513.

Closes #2506
Closes #2507

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras thiras added kind:bug Something does not behave as documented rust Dependabot: a Cargo update; use area: labels for Rust code otherwise area:payments Pools, vouchers, redeem, reclaim, staking (incentive crate and chain) labels Oct 17, 2026
Copilot AI balanced review requested due to automatic review settings October 17, 2026 19:35
@thiras thiras self-assigned this Oct 17, 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

The guards and error classification match the intended scope, with focused regression coverage and no identified blocking issues.

No open issues 🎉

What changed in this PR

Prevents repeat client funding after a run encounters a mined escrow that cannot be tracked locally, addressing #2506 and #2507.

Changes:

  • Records the run’s first untracked escrow and refuses subsequent funding attempts.
  • Classifies refusals and missing PoolOpened events as command-fatal errors.
  • Adds regression tests and a changelog entry.
File Description
crates/​client/​src/​funding/​adoption_tests.rs Tests escrow failures and subsequent funding refusals.
crates/​client/​src/​funding.rs Records untracked escrows and guards funding paths.
crates/​client/​src/​fault/​tests.rs Tests fatal classification and refusal reporting.
crates/​client/​src/​fault.rs Classifies escrow refusals as command-fatal.
crates/​client/​src/​buyer_pool.rs Returns EscrowUntracked for missing pool-open events.
CHANGELOG.md Documents the client funding fixes.

Review effort: Balanced

@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main c600cda fix/2506-refuse-escr... a198ac2 +/-
76% 76% 0%
View coverage of the 7 most impacted files.
File main c600cda fix/2506-refuse-escr... a198ac2 +/-
crates/client/src/lib.rs 89% 89% 0%
crates/client/s...undle/engine.rs 61% 61% 0%
crates/node/src...s/client/mod.rs 91% 91% 0%
crates/client/s...c/buyer_pool.rs 96% 96% 0%
crates/cache/src/engine.rs 91% 91% 0%
crates/client/src/fault.rs 96% 96% 0%
crates/client/src/funding.rs 78% 82% +4%

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

@thiras
thiras merged commit 41e5cd5 into main Oct 17, 2026
32 checks passed
@thiras
thiras deleted the fix/2506-refuse-escrow-after-untracked branch October 17, 2026 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:payments Pools, vouchers, redeem, reclaim, staking (incentive crate and chain) kind:bug Something does not behave as documented rust Dependabot: a Cargo update; use area: labels for Rust code otherwise

Projects

None yet

2 participants