Repository navigation
fix(node): top up reused buyer channels + drop redundant progressive-open timeout (#1146, #1147) - #1211
Conversation
…open timeout (#1146, #1147) Two contained correctness fixes in the node's node-to-node pull path. #1146: a buyer channel opened for a provider was reused verbatim on every cache-miss pull and never topped up, so once its deposit spent down, pull-through to that provider silently degraded forever. On reuse below a 20% low-water mark, the node now fires a detached, per-provider-singleflighted `topUp` (via `plan_refill`/`spawn_refill_if_low` + `RefillSlot`) and hands the current pull its channel immediately — the refill never blocks the non-serializing reuse fast path. `refill_amount`/`LOW_WATER_DIVISOR` are promoted into `decdn-client-pull` as the single source of truth shared with the CLI auto-refill. Adds `decdn_buyer_topup_ok_total` / `_failure_total`; the escrowed- but-untracked `top_up` outcomes are metered as failures so stranded deposits are visible. #1147: the progressive-pull open stage was bounded twice — a redundant outer `tokio::time::timeout(pull_timeout, …)` wrap plus the inner `deadlines.open` bound inside `open_stream`. Both were sourced from `pull_timeout`, so the double-bound only risked drift (an open-specific knob could make one candidate cost up to 2x while `outer_pull_deadline` budgets 1x, starving the fallback loop). Dropped the outer wrap; the open is now bounded solely by `deadlines.open`, matching the buffered path. Classification/metering (`PullTimeout` → `node_pull_timeout`, peer exonerated) is preserved by the inner sentinel. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Warning Review limit reached
Next review available in: 46 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)
WalkthroughThe change centralizes buyer-channel refill policy, returns persisted deposit outcomes, and adds non-blocking deduplicated low-water refills with metrics and tests. CLI integrations consume the shared policy. Progressive OPEN now uses its typed deadline without an outer timeout wrapper. ChangesBuyer channel low-water refill
Progressive OPEN timeout
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Reuse as Channel reuse
participant Service as BuyerChannelService
participant Store as BuyerChannelStore
participant TopUp as top_up
participant Metrics
Reuse->>Service: reuse live buyer channel
Service->>Store: read deposit state
Service->>Service: plan and claim low-water refill
Service->>TopUp: ensure allowance and submit refill
TopUp-->>Service: DepositOutcome
Service->>Metrics: record success or failure
Service-->>Reuse: return channel context without waiting
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 |
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 88.97% (2500/2810 lines) |
There was a problem hiding this comment.
Code Review
This pull request centralizes the channel auto-refill logic (the refill_amount function and LOW_WATER_DIVISOR constant) into the shared decdn-client-pull crate, allowing it to be reused by both the CLI and the node. It introduces a background, non-blocking low-water top-up mechanism for reused buyer channels in the node's fast-path reuse flow, complete with per-provider task deduplication, RAII-based slot management, and dedicated metrics tracking. Additionally, it removes a redundant timeout wrapper around progressive upstream opens in node_origin.rs. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Fixes two correctness issues in the node-to-node cache-miss pull path: (1) reused buyer channels now get best-effort low-water refills so pull-through doesn’t silently degrade once deposits are spent down, and (2) removes a redundant progressive-open timeout so per-candidate budgeting can’t drift/double-bound.
Changes:
- Add detached, per-provider-deduped low-water buyer-channel top-ups on reuse, plus success/failure metrics.
- Promote the refill policy (low-water divisor + refill decision kernel) into
decdn-client-pullas shared source of truth, and adapt CLI/e2e call sites totop_upreturningDepositOutcome. - Drop the outer progressive-open
tokio::time::timeout, relying ondeadlines.openinside the sharedopen_streampath.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/node_origin.rs | Removes redundant progressive-open timeout wrapper; relies on deadlines.open internal bound. |
| crates/node/src/metrics.rs | Adds buyer top-up ok/failure counters and increment helpers for the new background refill path. |
| crates/node/src/buyer_channel.rs | Implements low-water refill planning + per-provider singleflighted detached top-ups on channel reuse. |
| crates/e2e/tests/cli_fetch_topup.rs | Updates test call site to ignore top_up’s returned DepositOutcome. |
| crates/client-pull/src/buyer_channel.rs | Changes top_up to return DepositOutcome; adds shared low-water refill constants/kernel + tests. |
| crates/cli/src/commands/fetch.rs | Removes local refill policy duplication; imports shared refill kernel and adapts to top_up return type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 80.69% (was 80.71%, ▼ 0.02%) — 47244/58548 lines
History
|
…en failure-metric doc Copilot review follow-ups on #1211: - Reuse fast path no longer does a second `store.get_by_provider`: the low-water decision reads `deposit`/`prior_amount` off the `ChannelContext` the reuse read already built. `plan_refill` now takes those values (and `refill_decision` is value-based), dropping its store-read + expiry branches — expiry / no-channel are already enforced upstream by the reuse gate (`try_reuse_live`), so `spawn_refill_if_low` is only reached for a live channel. Tests updated to drive the decision by value (removes the now-unreachable expired / no-channel cases). - `buyer_topup_failure` method doc now notes it also covers the escrowed-but- untracked `DepositOutcome` outcomes, matching the field doc. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Batch fix for two contained correctness bugs in the node's node-to-node cache-miss pull path (same
NodeOriginflow), following the repo's "fix batch" pattern. No contract changes. Clear of in-flight PRs #1204 (PaymentChannel contract) and #1209 (origin-replay/zero-address).#1146 — reused buyer channels are never topped up
A buyer channel opened for a provider was reused verbatim on every miss pull and never re-funded, so once its deposit spent down, pull-through to that provider silently degraded forever.
topUp(plan_refill→spawn_refill_if_low, deduped viaRefillSlot/topups_in_flight) and hands the current pull its channel immediately — the refill never blocks the non-serializing reuse fast path. A fully-drained channel heals on the next pull.refill_amount/LOW_WATER_DIVISORpromoted intodecdn-client-pullas the single source of truth shared with the CLI fetch auto-refill.decdn_buyer_topup_ok_total/_failure_total.top_upnow returnsDepositOutcome; the escrowed-but-untracked outcomes (UnknownProvider/ChannelMismatch) are metered as failures, so stranded deposits are visible to an operator alert.#1147 — progressive-open stage was bounded twice
The open was wrapped in a redundant outer
tokio::time::timeout(pull_timeout, …)and bounded internally bydeadlines.openinsideopen_stream. Both sourced frompull_timeout, so the double-bound only risked drift — a future open-specific knob could make one candidate cost up to 2×pull_timeoutwhileouter_pull_deadlinebudgets 1×, starving theMAX_PROVIDER_ATTEMPTSfallback loop.deadlines.open, matching the buffered path (stream_fetch_shared).PullTimeout { after: deadlines.open }sentinel →classify_pull_failureexonerates the peer and metersnode_pull_timeout.Tests / verification
cargo clippy --workspace --all-targets→ clean (-D warnings)cargo nextest(node + client-pull + cli) → 1126 passedplan_refillbranch tests (trigger / headroom / already-expired / no-channel / dedup),refill_decisiontarget-clamping incl.min_deposit-wins,claim_refill_slotdedup + free-on-drop.#1147single-bound behavior remains covered bynode_origin_pull.rs.Applied fixes from a multi-agent PR review (metric misclassification, poisoned-lock self-heal, branch-test coverage, comment accuracy). The full on-chain success path is exercised by the existing
anvil_settlement_e2eharness.Closes #1146
Closes #1147
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes