Repository navigation
fix(cli): auto-reclaim replaced expired buyer channel on fetch (#1553) - #1588
Conversation
`decdn fetch` replaces a tracked-but-expired buyer channel by opening a fresh one (`topUp` cannot extend expiry) and left the expired channel's residual USDC deposit escrowed on-chain until a manual `channel clean`. Nothing told the user this, and the doc comment deferred reclaim to a "node service (#940) follow-up" that is closed and only ever covered the daemon's own channels — never the CLI keystore's. - open_or_reuse now kicks off the expired channel's wind-down before opening the replacement: an expired-and-open channel reclaims its deposit in one `reclaimExpired` (no dispute window), so the USDC returns without operator memory. Best-effort — it never blocks or fails the fetch. Reuses `channel clean`'s `clean_one` state machine via a new `reclaim_replaced_expired` helper. - The replacement warning now names `decdn channel clean` as the backstop for anything the inline sweep can't finalize in one shot. - Dropped the stale "#940 follow-up / node service handles reclaim" doc clause. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Warning Review limit reached
Next review available in: 52 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (2)
WalkthroughExpired tracked channels now receive best-effort cleanup before replacement. Cleanup reports terminal, incomplete, and transient outcomes without blocking the replacement flow. ChangesExpired channel replacement
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant FetchCommand
participant reclaim_replaced_expired
participant clean_one
participant ReplacementFlow
FetchCommand->>reclaim_replaced_expired: pass expired channel state and current time
reclaim_replaced_expired->>clean_one: attempt wind-down and reclamation
clean_one-->>reclaim_replaced_expired: report cleanup outcome
reclaim_replaced_expired-->>FetchCommand: return without blocking fetch
FetchCommand->>ReplacementFlow: open replacement channel
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Coverage reportTotal: 80.27% (was 80.30%, ▼ 0.03%) — 56560/70462 lines
History
|
There was a problem hiding this comment.
Pull request overview
This PR improves decdn fetch’s handling of tracked-but-expired buyer channels by triggering a best-effort reclaim/wind-down of the replaced channel before opening a replacement, and by updating the documentation/user messaging to point operators at decdn channel clean as the fallback.
Changes:
- Update
open_or_reuserustdoc and the expired-channel replacement path infetchto kick off best-effort wind-down before opening a replacement channel. - Add
reclaim_replaced_expiredto reuse the existingdecdn channel cleanstate machine for the pre-replacement reclaim attempt. - Improve operator-facing stderr output for outcomes that require a later
decdn channel clean.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/cli/src/commands/fetch.rs | Updates open_or_reuse docs and wires in best-effort reclaim before opening a replacement for an expired tracked channel. |
| crates/cli/src/commands/channel.rs | Adds reclaim_replaced_expired helper that drives the existing clean_one state machine and prints operator guidance. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
) Address review feedback on the expired-channel auto-reclaim: - reclaim_replaced_expired treated CleanStatus::Reverted as "winding down — re-run after its dispute window", but a revert (e.g. clock skew making reclaimExpired look not-yet-expired) is not a dispute window. Split it into its own arm that points at a `decdn channel clean` retry instead. - Reworded the doc + inline comments in fetch.rs: the reclaim never *fails* the fetch, but it is awaited (a getChannel read plus, on the common path, a reclaimExpired tx + receipt wait) and so can add latency before the replacement opens. "Never blocks" was misleading. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Problem
decdn fetchreplaces a tracked-but-expired buyer channel by opening a fresh one (topUpcannot extend expiry), leaving the expired channel's residual USDC deposit escrowed on-chain. Nothing told the user how to get it back:open_or_reusedoc comment deferred reclaim to a "node service (Client-side buyer channel management: auto-open, track, reuse PaymentChannels for decdn fetch #940) follow-up" — but Client-side buyer channel management: auto-open, track, reuse PaymentChannels for decdn fetch #940 is closed, and the node-side reclaim sweep (crates/node/src/buyer_channel.rs) only covers the daemon's own channels, never the CLI keystore's.The deposit was never actually lost — the store keys rows by channel id with a provider index on top, so the expired row survives a replacement and
decdn channel cleancan reach it — but the user had no way to know that.Fixes #1553.
Changes
All three acceptance items from the issue:
crates/cli/src/commands/fetch.rsnow points the operator atdecdn channel cleanas the backstop.open_or_reusedoc comment drops the "Client-side buyer channel management: auto-open, track, reuse PaymentChannels for decdn fetch #940 follow-up / node service handles reclaim" text and describes the inline sweep +channel cleanbackstop instead.open_or_reusekicks off the expired channel's wind-down. An expired-and-open channel reclaims its deposit in a singlereclaimExpired(no dispute window), so the residual USDC returns without the operator remembering to run anything.Design notes for reviewers
channel clean's state machine. A newpub(crate) reclaim_replaced_expiredhelper incrates/cli/src/commands/channel.rsdrives the sameclean_onesweep rather than reimplementing reclaim logic — so already-closing channels, transient errors, and expired-Open channels are all handled the same waychannel cleanhandles them.channel clean; nothing propagates as an error.forget_if_channelclears the old row while the provider index still points to it — no stale-row leak. Anything not finalized in one shot survives in the store keyed by channel id, exactly aschannel cleanexpects.reclaimExpiredtx (a few seconds on Arbitrum Sepolia) to the fetch path, but only when a previously-used provider's tracked channel has actually expired. Strictly best-effort, so it never blocks delivery on failure.Verification
cargo clippy -p decdn-cli— clean (anti-panic policy respected: no unwrap/expect/panic/indexing)cargo nextest run -p decdn-cli— 406 passed, 0 failedcargo fmt --check— cleancargo docwith-D rustdoc::broken_intra_doc_links— clean🤖 Generated with Claude Code
Summary by CodeRabbit