Skip to content

fix(cli): auto-reclaim replaced expired buyer channel on fetch (#1553) - #1588

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/peaceful-khorana-cc0416
Aug 4, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/peaceful-khorana-cc0416

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

decdn fetch replaces a tracked-but-expired buyer channel by opening a fresh one (topUp cannot extend expiry), leaving the expired channel's residual USDC deposit escrowed on-chain. Nothing told the user how to get it back:

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 clean can reach it — but the user had no way to know that.

Fixes #1553.

Changes

All three acceptance items from the issue:

  1. Warning names the command. The replacement path in crates/cli/src/commands/fetch.rs now points the operator at decdn channel clean as the backstop.
  2. Stale doc clause removed. The open_or_reuse doc 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 clean backstop instead.
  3. Inline reclaim (the "better" stretch). Before opening the replacement, open_or_reuse kicks off the expired channel's wind-down. An expired-and-open channel reclaims its deposit in a single reclaimExpired (no dispute window), so the residual USDC returns without the operator remembering to run anything.

Design notes for reviewers

  • Reuses channel clean's state machine. A new pub(crate) reclaim_replaced_expired helper in crates/cli/src/commands/channel.rs drives the same clean_one sweep rather than reimplementing reclaim logic — so already-closing channels, transient errors, and expired-Open channels are all handled the same way channel clean handles them.
  • Best-effort, never fails the fetch. Terminal outcomes (reclaimed / settled / already gone) just report; a channel still winding down or a transient RPC error is reported with a pointer to channel clean; nothing propagates as an error.
  • Runs before the replacement is recorded, so forget_if_channel clears 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 as channel clean expects.
  • Hot-path cost: adds one on-chain reclaimExpired tx (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 failed
  • cargo fmt --check — clean
  • cargo doc with -D rustdoc::broken_intra_doc_links — clean
  • All pre-commit hooks passed on commit

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Expired tracked channels are automatically cleaned up before replacement channels are opened.
    • Replacement continues even if cleanup encounters a temporary failure.
  • Bug Fixes
    • Improved handling of expired channels, including clear reporting when cleanup is complete or a channel remains in a dispute window.
    • Existing channel-cleaning commands remain available as a fallback.

`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]>
Copilot AI lite review requested due to automatic review settings August 4, 2026 12:10
@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@alpergundogdu, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 91573f28-3a99-4cc3-8c94-cdcb4f053697

📥 Commits

Reviewing files that changed from the base of the PR and between 25dfe1a and f633bd5.

📒 Files selected for processing (2)
  • crates/cli/src/commands/channel.rs
  • crates/cli/src/commands/fetch.rs

Walkthrough

Expired tracked channels now receive best-effort cleanup before replacement. Cleanup reports terminal, incomplete, and transient outcomes without blocking the replacement flow.

Changes

Expired channel replacement

Layer / File(s) Summary
Reclaim expired channel state
crates/cli/src/commands/channel.rs
Adds reclaim_replaced_expired, which runs the existing cleanup state machine and reports cleanup outcomes.
Integrate cleanup into replacement
crates/cli/src/commands/fetch.rs
The fetch command invokes cleanup for expired channels and continues replacement when cleanup fails. The existing decdn channel clean fallback remains available.

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
Loading

Note

🎁 Summarized by CodeRabbit Free

Your 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 @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.27% (was 80.30%, ▼ 0.03%) — 56560/70462 lines

File Coverage Lines Δ
crates/cli/src/commands/channel.rs 52.68% 471/894 ▼ 1.02%
crates/cli/src/commands/fetch.rs 39.73% 598/1505 ▼ 0.24%
History
Commit Total Δ vs base
25dfe1a 80.27% ▼ 0.03%
f633bd5 (HEAD) 80.27% ▼ 0.03%

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.

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_reuse rustdoc and the expired-channel replacement path in fetch to kick off best-effort wind-down before opening a replacement channel.
  • Add reclaim_replaced_expired to reuse the existing decdn channel clean state 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.

Comment thread crates/cli/src/commands/channel.rs Resolved
Comment thread crates/cli/src/commands/fetch.rs Resolved
Comment thread crates/cli/src/commands/fetch.rs Resolved
)

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]>
@alpergundogdu
alpergundogdu merged commit 0639ce2 into main Aug 4, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/peaceful-khorana-cc0416 branch August 4, 2026 14:23
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.

cli fetch: replacing an expired buyer channel silently parks its residual deposit until a manual channel clean

2 participants