Skip to content

fix(cli): clear the local row of a pool that is no longer Open - #2450

Merged
thiras merged 2 commits into
mainfrom
fix/2425-clear-row-not-open
Oct 13, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/2425-clear-row-not-open

Conversation

@thiras

@thiras thiras commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What

When a closePool or reclaim mined but its run could not clear the client-store row (the clear faulted, or the tx's outcome was unknown), every re-run stopped at a status refusal or skip before it touched the store. The row survived, and a later fetch reused a closing or closed pool whose vouchers redeemMany rejects.

Each close / reclaim that reads a pool as Closing or Closed now clears its row:

Site Before After
close --pool refusal bails, store untouched clears the row, then bails (same exit code)
close --all skip skips clears the row, then skips
reclaim --pool refusal (SkipInWindow / SkipClosed) bails before opening the store opens the store best-effort and clears the row with the on-chain owner (still no keystore unlock), then bails with the same refusal
reclaim --all skip (SkipInWindow / SkipClosed) skips clears the row, then skips
  • The refusal or skip line says whether it cleared a row.
  • Deployment scoping. Every row-clear in pool close / pool reclaim (forget_on) deletes only a row on the command's chain and PaymentPool. The landed-tx paths are included. A pool id repeats across deployments, so a command against an old --payment-pool-address must leave the live row for the same id alone.
  • The clear is compare-and-delete, so a row that points at a newer pool stays.
  • Daemon data dir. LocalBookkeeping::DaemonOwned keeps its "row untouched" report.
  • Repair fault. A skipped pool whose clear faults counts as row not cleared and fails the sweep, so a failed repair does not read as success.

From the #2430 review: close --all counted a landed close whose row-clear faulted as "failed to close". That error is now a CloseUnrecorded, which BatchTally::record_error counts as closed plus row not cleared. The sweep still exits nonzero, which keeps the existing policy ("exit non-zero when a landed on-chain effect cannot be recorded locally"). The message puts the store fault next to "failed" and names a re-run of close --pool, which now clears the row.

Closes #2425

Reviewer notes

  • Read first: LocalBookkeeping::forget_not_open, NotOpenClear and forget_on (crates/cli/src/commands/pool.rs).
    • forget_not_open owns the not-Open guard, so an Open pool or the hidden invalid sol! status never touches the store.
    • forget_on reads the row and deletes it in two transactions. That is safe because the client redb is held exclusively by this process.
  • LocalBookkeeping::Store shape. It now holds { store: &dyn BuyerPoolStore, deployment }, so the tests can use MemoryBuyerPoolStore and a faulting store. Its Debug derive was dropped because the trait object has no Debug.
  • Unchanged on purpose: every --pool exit code, pool list (still read-only), and the reclaim landed-path row-clear (still a warning).
  • Test gaps:
    • No test runs a landed close end to end over a mocked provider: alloy's heartbeat task races the Asserter queue during get_receipt and takes the receipt answer. The tally is tested on the real grade_local_forget error instead.
    • The reclaim() / close() wiring itself is not unit-tested. Its logic sits in tested helpers (refuse_reclaim, refuse_close, forget_not_open).
    • An e2e extension of crates/e2e/tests/cli_pool_reclaim_precheck.rs (close on-chain from the fixture, then assert that the CLI re-run clears the row) is a possible follow-up.

Verification

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run -p decdn-cli: 735 passed
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items
  • pre-commit run (all hooks pass)
  • User-visible change: CHANGELOG.md entry added. The older entry that said only the reclaim clears the row is updated.
  • PR title uses an allowed type with a lowercase subject

🤖 Generated with Claude Code

After a closePool or reclaim mined, only the first, fully successful run
cleared the client-store row. If that clear faulted, or the receipt was
unreadable but the tx mined, every re-run stopped at a status refusal or
skip before it touched the store, and a later fetch reused a closing or
closed pool whose vouchers redeemMany rejects.

Every close / reclaim that reads a pool as Closing or Closed now clears
its row: close --pool and reclaim --pool on their refusal (exit codes are
unchanged), close --all and reclaim --all on their skip. The clear is
compare-and-delete, and reclaim --pool uses the on-chain owner so its
refusal still needs no keystore unlock. A daemon data dir keeps its
"row untouched" report.

close --all now counts a landed close whose row-clear faulted as closed,
not "failed to close". The error carries a CloseUnrecorded marker, the
summary gains a "row not cleared" count, and the sweep still exits
nonzero, keeping the landed-but-unrecorded exit policy.

Closes #2425

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 13, 2026 11:58
@thiras thiras self-assigned this Oct 13, 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 implementation safely uses compare-and-delete, preserves intended exit behavior, and covers the affected paths.

0 open findings

What changed in this PR

Repairs stale client pool bookkeeping after pools become Closing or Closed.

Changes:

  • Clears stale rows on close/reclaim refusals and batch skips.
  • Separately tallies landed closes whose row cleanup failed.
  • Adds regression coverage and user-facing release notes.
File Description
crates/​cli/​src/​commands/​pool.rs Implements cleanup and batch classification.
crates/​cli/​src/​commands/​pool/​tests.rs Tests cleanup, fault handling, and tallies.
CHANGELOG.md Documents the corrected behavior.

🧠 Review effort: Balanced


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

@github-code-quality

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

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit b856787 in the fix/2425-clear-row-n... branch remains at 75%, unchanged from commit f532cea in the main branch.

Show a line coverage summary of the most impacted files.
File main f532cea fix/2425-clear-row-n... b856787 +/-
crates/client/src/lib.rs 88% 88% 0%
crates/client/src/scheduler.rs 94% 94% 0%
crates/node/src/dht/publish.rs 78% 80% +2%
crates/incentiv...c/buyer_pool.rs 95% 97% +2%
crates/cli/src/...ommands/pool.rs 64% 69% +5%

Updated October 13, 2026 12:17 UTC

Review follow-ups for #2425:

- Every pool close/reclaim row-clear now deletes only a row on the
  command's chain and PaymentPool. A pool id repeats across deployments,
  so a refusal against an old --payment-pool-address could delete the
  live row for the same id on the current deployment.
- reclaim --pool opens the client store best-effort on its refusal path:
  a store another process holds warns instead of replacing the refusal.
- A skipped Closing/Closed pool whose row-clear faults counts as "row not
  cleared" and fails the sweep, the same as a landed close; reclaim --all
  prints the count too.
- forget_not_open owns the not-Open guard and returns NotOpenClear, so no
  caller can clear an Open pool's row.
- CloseUnrecorded renders its store fault inline next to "failed";
  reclaim_all matches ErrorClass exhaustively; refusals keep their full
  chain; docs follow the new behavior.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 738214f into main Oct 13, 2026
31 checks passed
@thiras
thiras deleted the fix/2425-clear-row-not-open branch October 13, 2026 12:19
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.

fix: pool close/reclaim leave the local row on a pool that is no longer Open

2 participants