Skip to content

fix(node,cache,client-pull): unstick the fused serve-miss past the ramp floor and size node top-ups correctly (#1893) - #2010

Merged
thiras merged 7 commits into
mainfrom
worktree-issue-1893-serve-demand
Sep 14, 2026
Merged

thiras merged 7 commits into
mainfrom
worktree-issue-1893-serve-demand

Conversation

@thiras

@thiras thiras commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1893

The issue text is stale: its clean-miss symptom was the warming allowance, fixed in #2003. Two further bugs kept node_pull_topup red. This PR fixes both and un-ignores the e2e.

1. Fused serve-miss deadlock past the credit-window floor

The serve leg ramps its window on paid wire bytes. The pull leg's RampPacer ramps on the paid content frontier, which is always smaller. Once both leave their floors (~2 MiB paid at the default divisor), the pull window closes while the serve window still has room. The serve encoder then parks on a proof node past the pulled frontier: the hash pair for the next right-edge subtree arrives only when the pull fetches into it. While parked, the serve leg collects no voucher, so served_paid never advances and the pull never wakes.

Instrumented loopback run at the stall: pull Wait at pulled=4685824, serve at delivered=4194304 room=524288 pending=1, and the reader's present-range watch fully up to date. The park was on the outboard, not on data.

Fix: a parked serve read records the content offset it waits on as the serve demand, on every live fill of the hash (FillSession::demand_up_to).

  • The data reader demands the leaf span it awaits.
  • The outboard reader demands the first byte of the node whose pair it awaits.
  • WindowPacer may always draw up to the demand.
  • ServedPaidWait wakes on a demand advance as well as a payment. PacingWait::wait / drive now carry a DownstreamFrontier pair, and client callers pass None.
  • ADR 037 states the added exposure: the encoder's bounded look-ahead past the serve credit window.

2. Reactive top-up added ~0.02 USDC instead of ~3.7 USDC

NodeFunder turned the driver's additional into a spendable target from the live pull ledger. BuyerPoolService::top_up_pool then re-derived the shortfall from the persisted lane progress, which is recorded when a pull ends. Mid-pull the service saw only the warm-up spend, so it topped up 23533 µUSDC. The single allowed top-up was spent and the next voucher was refused.

Fix: PoolOpener::top_up_pool takes the amount to add, and NodeFunder passes additional through unchanged.

Tests

  • New window_pull_through_completes_a_blob_past_the_ramp_floor (8 MiB fused loopback): stalled 3/3 on main; passes in ~1.5 s.
  • Unit tests:
    • pacer demand draw / wait
    • registry fan-out
    • outboard demand
    • ServedPaidWait demand race
    • funder passes additional through
  • node_pull_topup (anvil e2e) runs un-ignored and passes (~7.6 s).
  • cargo nextest run --workspace: 3464 passed.
  • cargo clippy --workspace --all-targets -D warnings, cargo fmt --check and cargo doc -D warnings are clean. The touched anvil targets are also lint-clean under --features anvil-e2e.

Heads-up: cargo deny fails on main

cargo deny is red because of a new advisory, RUSTSEC-2026-0285 (rustls 0.23.37). This PR does not touch Cargo.lock, and the commits skip only that hook. The rustls bump belongs in its own PR.

Review follow-up (4721c846)

A multi-agent review found an unbounded spend path in the first serve-demand commit. Demand fanned out to every live fill of a hash, and WindowPacer honoured it however far past the pull it sat. An unpaid request attached near the end of a cold blob could therefore drag its sibling pull across the whole gap.

The pacer now honours demand only within one chunk group past the pull's frontier, which is the only place a serve encoder parked on that pull can wait. It then draws one PULL_WINDOW_FLOOR.

  • Draw size: one-group draws re-opened the upstream often enough near exhaustion to hit the seeder's refundable-floor refusal. node_pull_topup failed 2 of 5 runs with them, and passes 11 of 11 with floor draws.
  • Bound: ramped credit window plus one pull-window floor. ADR 037 and the code docs now state it.

The follow-up commit also adds three tests:

  • far-past-the-pull demand is ignored
  • data-reader demand
  • a demand raise wakes a parked pull

It also fixes stale top_up_channel references and the top-up log text.

Seller-floor top-up and e2e stability (d819443b, cb1ade69, d1f5ecff)

node_pull_topup had three more intermittent failure causes. This PR fixes all of them.

  • Top-up before a serving peer's refundable floor. A seller refuses a new stream once remaining − M can't cover a window, and it reports that as NotFound. BudgetPacer now tops up while the remaining deposit still covers the peer's floor plus the next voucher (PaceState::seller_reserve).
    • The node estimates that floor from its own pool_min_remaining_deposit_micro_usdc; the CLI passes 0.
    • The reserve only starts a top-up and never refuses a draw.
    • ADR 003 states the rule.
  • Settle-wait past a landed leg. A peer can admit one stream on stale headroom, then refuse the next re-open before its watcher sees the top-up. The driver's settle allowance now stays armed across landed legs.
  • Nonce collision on topUp. The node signs redeemMany and topUp with one key. A topUp rejected nonce too low is re-sent up to three more times; nothing was broadcast, so re-sending is safe.
  • Serve demand only when the serve leg starves. Encoder read-ahead raised demand, which let an unpaid client drag the pull past its window, and window_pull_through_underpaid_voucher_abandons_bounded flaked. The readers now record the offset they park on, and the frame producer publishes it only when the frame channel is empty. ADR 037 states this.

Verification on the final code:

  • node_pull_topup passes 8 of 8.
  • Related anvil journeys pass 5 of 5 (node_to_node_coalesce, cli_fetch_topup, coalesce_two_clients).
  • The underpaid spend-bound test passes a 20× stress run, and the 8 MiB fused reproducer a 10× stress run.
  • cargo nextest run --workspace: 3473 passed, and clippy and rustdoc are clean.

Known follow-ups (not in this PR)

  • Reactive top-up joins a proactive refill: a top-up that joins an in-flight proactive refill gets that refill's (possibly smaller) amount and still spends the single reactive budget. This predates the PR; the doc now says so.
  • Buyer floor estimate: the node assumes an upstream's M equals its own. An upstream with a larger M can still refuse re-opens in the gap. A signed reason to the authenticated pool owner would remove the guess, but that is a wire and privacy decision.
  • Type-design suggestions:
    • a forward-only frontier handle instead of raw Arc<AtomicU64>
    • clamp demand to total_bytes in demand_up_to
    • rename top_up_pool → top_up_pool_by and ServedPaidWait → DownstreamWait
  • Test gaps: a spend-bound e2e for a client that stays connected but stops paying past the ramp; a driver convergence test for demand when the paid frontier trails delivery.

🤖 Generated with Claude Code

https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j

thiras and others added 2 commits September 14, 2026 21:00
…rve leg needs (#1893)

The fused serve-miss deadlocked on any blob large enough to leave the credit
window's floor. The serve leg ramps its window on paid wire bytes; the pull leg
ramps on the paid content frontier, which is always smaller. Past the floor the
pull window closed while the serve window still had room, so the serve encoder
parked on a proof node (or leaf) past the pulled frontier. While it waited it
collected no voucher, so the served-paid frontier the pull waited on never
advanced. An 8 MiB fused loopback delivery stalled every time.

A parked serve read now records the content offset it waits on as the serve
demand, on every live fill of the hash. The window pacer may always draw up to
that offset, and the pull's wait wakes on a demand advance as well as a payment.
The data reader demands the leaf span it awaits; the outboard reader demands the
first byte of the node whose hash pair it awaits. ADR 037 states the added
exposure: the encoder's bounded look-ahead past the serve credit window.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
…or (#1893)

A reactive mid-pull top-up added almost nothing. NodeFunder turned the driver's
`additional` into a spendable target from the pull's live ledger, and
BuyerPoolService::top_up_pool re-derived the shortfall from the persisted lane
progress. That progress is recorded when a pull ends, so mid-pull it omits the
asking pull's own spend: in node_pull_topup the pool was ~3.7 USDC spent, the
service saw ~0.02 USDC spent, and it topped up 0.02 USDC. The single allowed
top-up was spent and the next voucher was refused.

PoolOpener::top_up_pool now takes the amount to add, and NodeFunder passes the
driver's `additional` through unchanged. node_pull_topup runs un-ignored.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
@thiras thiras self-assigned this Sep 14, 2026
@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.73% (was 82.66%, ▲ +0.08%) — 78187/94503 lines

File Coverage Lines Δ
crates/cache/src/fill_session.rs 94.23% 948/1006 ▲ +0.41%
crates/client-pull/src/buyer_pool.rs 57.07% 210/368 ▼ 0.95%
crates/client-pull/src/driver.rs 93.76% 1247/1330 ▲ +0.46%
crates/client-pull/src/lib.rs 89.28% 1724/1931 ▲ +0.21%
crates/client-pull/src/pacer.rs 99.33% 297/299 ▲ +0.27%
crates/client-pull/src/scheduler.rs 94.10% 1947/2069 ▲ +0.07%
crates/incentive/src/tx.rs 62.28% 104/167 ▲ +8.60%
crates/node/src/buyer_channel.rs 34.39% 227/660 ▲ +0.26%
crates/node/src/handlers/client/serve_encoder.rs 91.17% 547/600 ▲ +0.54%
crates/node/src/handlers/client/serve_leg.rs 74.59% 138/185 ● 0.00%
crates/node/src/node_origin/funder.rs 93.23% 179/192 ▼ 1.22%
crates/node/src/node_origin/mod.rs 92.02% 1084/1178 ● 0.00%
crates/node/src/node_origin/pull_leg.rs 84.98% 741/872 ▲ +1.15%
crates/node/src/runtime/mod.rs 47.74% 1170/2451 ▼ 0.06%
History
Commit Total Δ vs base
c81e30e 82.68% ▲ +0.03%
4721c84 82.70% ▲ +0.05%
6b9a83e 82.69% ▲ +0.04%
d1f5ecf (HEAD) 82.73% ▲ +0.08%

…rontier (#1893)

Review of the serve-demand fix found an unbounded spend path. Demand fans out
to every live fill of a hash, and the window pacer honoured it however far past
the pull it sat. An unpaid request attached near the end of a cold blob could
drag its sibling pull across the whole remaining gap.

The pacer now honours a demand only within one chunk group past the pull's
frontier — the only place a serve encoder parked on this pull can wait — and
then draws one pull-window floor. A serve leg parks only while its own credit
window has room, so a client that stops paying stops raising demand. Drawing a
floor rather than one group keeps each unpark to one upstream open; one-group
draws re-opened the upstream often enough near exhaustion to hit the seller's
refundable-floor refusal, and node_pull_topup failed 2 of 5 runs.

ADR 037 and the pacer, fill-session, serve-leg and pull-leg docs state the
bound: the ramped credit window plus one pull-window floor. The top_up_pool
doc and log state that a joined in-flight topUp can add less than asked. New
tests pin the far-demand refusal, the data-reader demand, and a demand raise
waking a parked pull. Stale top_up_channel references are fixed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
@thiras
thiras marked this pull request as ready for review September 14, 2026 18:30
Copilot AI lite review requested due to automatic review settings September 14, 2026 18:30

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.

🟡 Changes recommended

Unresolved critical pacer-boundary and moderate demand-validation and ADR-bound issues remain.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes fused serve-miss stalls and reactive node top-up underfunding.

Changes:

  • Adds serve-demand propagation and bounded demand-aware pacing.
  • Uses additive top-up amounts.
  • Adds regression, settlement, and E2E coverage; updates ADR 037.
File summaries
File Reviewed changes
crates/node/tests/node_origin_pull.rs Adds fused-pull and top-up regressions.
crates/node/tests/anvil_settlement_e2e.rs Updates exact top-up settlement assertions.
crates/node/src/node_origin/pull_leg.rs Wakes pulls on payment or serve-demand advances.
crates/node/src/node_origin/mod.rs Updates funder construction.
crates/node/src/node_origin/funder.rs Passes additive top-up amounts unchanged.
crates/node/src/handlers/client/serve_leg.rs Documents demand coordination.
crates/node/src/handlers/client/serve_encoder.rs Records data and proof demand. Moderate (1 vote, line 145): verify live coverage before raising demand.
crates/node/src/buyer_channel.rs Implements additive pool top-ups.
crates/e2e/tests/node_pull_topup.rs Enables reactive top-up E2E coverage.
crates/client-pull/src/pacer.rs Implements bounded demand-aware pacing. Critical (1 vote, line 255): handle the end-exclusive sentinel boundary correctly.
crates/client-pull/src/lib.rs Exports frontier types.
crates/client-pull/src/driver.rs Carries downstream frontier state through pacing.
crates/cache/src/fill_session.rs Tracks and propagates serve demand.
adr/037-regional-proxy-warming.md Documents demand exposure. Moderate (2 votes, line 59, also line 148): qualify the bound for credit_ramp_divisor = 0; Nit (1 vote, line 114): update the implementation-status qualification.
Review details

Suppressed comments (3)

adr/037-regional-proxy-warming.md:114

  • The implementation-status paragraph repeats the same unqualified claim, but credit_ramp_divisor = 0 is supported and makes the ramp return credit_max at zero payment; the new serve-demand floor can then extend exposure beyond that ceiling. Apply the non-zero-divisor qualification and state the divisor-zero case here as well, so the ADR's stated bound matches the implementation.
The node-side serving behavior of this ADR — the window-paced pull-through handler — lives in the `crates/node/src/handlers/client/` module (`window.rs`: `serve_via_window_pull_through` / `window_forward_loop`). It fuses a progressive upstream pull (`crate::client_requester::open_progressive_pull`, driven via `crate::node_origin::NodeOrigin::open_progressive_pull`) with downstream delivery: each upstream chunk is forwarded to the paying client and tee'd into the cache (`decdn_cache::CacheEngine::open_tee_sink`), and the pull pauses whenever the per-request frontier `bytes_pulled − bytes_paid` reaches the ramped credit window, resuming as the client's vouchers clear. The pull leg's `decdn_client_pull::RampPacer` computes that same window from the stream's own paid frontier via `decdn_incentive::ramped_credit_window` ([ADR 003 § Credit window](003-payments.md#credit-window)), so the upstream pull and the downstream serve loop ramp in lockstep — a non-paying client fronts at most about two chunks of speculative upstream spend, never the fully-ramped ceiling. The two windows count different bytes: the serve loop meters wire bytes, and the pull paces on the paid content frontier. As a result, the pull window can close while the serve loop still has credit room. The serve encoder then waits on a leaf or a proof node that only the pull can fetch, and it collects no voucher while it waits. To keep both legs live, the encoder records the content offset it waits on as the **serve demand**. The encoder waits on the first byte that the pull has not fetched, so the demand is at most one chunk group past the pull frontier. The pull then fetches one more pull-window floor (one chunk plus three chunk groups) past its own window. The pull ignores a demand that is further ahead, because that demand comes from a serve leg that the pull does not block. A serve leg waits on the pull only while its own credit window has room, so a client that stops paying stops the demand. The serve demand therefore adds at most one pull-window floor to the speculative spend. A complementary **pre-flight deposit guard** composes in front of the window: a cache-miss pull is refused outright (signed `NotFound`, metered as `serve_stream_rejected_insufficient_deposit`, or as `serve_stream_rejected_signer_floor_at_cap` when the pool is solvent and the requesting signer has filled its share of the floor) when the requesting pool's remaining deposit cannot cover the worst-case blob cost. With a finite `max_blob_size_bytes` the ceiling is the whole-blob cost; when the size cap is unbounded (`0`) the guard falls back to the per-request window cost (the ramp floor, one chunk) rather than failing open — disabling the size cap must not silently disable deposit protection. The **direct-serve** path carries the same guard against a narrower ceiling — `min(credit window, chunk-group-aligned request span)`, which bounds what it can deliver before the first voucher clears to that window plus one chunk.

adr/037-regional-proxy-warming.md:148

  • The new demand override can add PULL_WINDOW_FLOOR after WindowPacer has already reached the ramped ceiling, so a stream at credit_max can temporarily exceed credit_max. This risk statement still says exposure never exceeds that ceiling; update the documented bound to include the extra floor or enforce a hard cap in code, otherwise operators are given an incorrect loss limit.
- **Manufactured-demand routing.** A client can route warming requests toward content it chooses, forcing nodes into speculative pulls. Bounded by the ramped credit window — a non-paying stream fronts at most about two chunks, and the exposure never exceeds `credit_max` regardless of how many peers or hashes the demand spreads across — and by the fact that the node is paid for bytes it serves. Not free; self-limiting.

crates/node/src/handlers/client/serve_encoder.rs:149

  • The liveness check for the requested range happens after demand_up_to, but demand_up_to fans the frontier out to every live fill for this hash. If this range has no live coverer while an unrelated same-hash fill is still running, that other pull can be woken and authorized to draw a PULL_WINDOW_FLOOR even though this reader immediately takes the terminal/error path below. Check that a live fill still covers the range before raising demand (while preserving the existing race handling).
            // The span is not here yet, so this read is about to wait on a pull.
            // Tell every pull that may produce it: a pull whose window has closed
            // would otherwise wait for a payment that this parked read blocks.
            self.session
                .demand_up_to(offset.saturating_add(need).min(self.total));
  • Files reviewed: 14/14 changed files
  • Comments generated: 2
  • Review effort level: Lite

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

Comment thread crates/client-pull/src/pacer.rs Resolved
Comment thread adr/037-regional-proxy-warming.md Resolved
thiras and others added 4 commits September 14, 2026 21:54
…and only on a covered read (#1893)

ADR 037 stated the non-paying exposure bound without its preconditions. With
`credit_ramp_divisor = 0` the window opens at `credit_max`, and the serve-demand
floor adds to any window, so the bound reads "about two chunks" only for a
nonzero divisor and "credit_max plus one pull-window floor" otherwise; the
manufactured-demand risk no longer claims exposure never exceeds `credit_max`.

The data reader raises serve demand only after it confirms a live fill still
covers the span, so a read that is about to fail wakes no pull and takes no
registry lock. The pacer comment records why the demand band is exactly one
group: the encoder walks the tree in pre-order, so a parked encoder never waits
on a node that starts a whole group past the pull.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
…r, and settle-wait past a landed leg (#1893)

A serving node refuses a new stream once the pool's remaining deposit, less its
refundable floor M, cannot cover a credit window, and it reports that refusal
as a plain miss. The buyer's pacer topped up only once the next voucher was
unaffordable, so a node pull that re-opened while its pool sat between one
voucher and M plus a window was refused, and the fetch failed as "held by no
reachable provider".

BudgetPacer now tops up while the remaining deposit still covers the serving
peer's floor plus the next voucher (PaceState::seller_reserve). The node's pull
legs estimate the floor from the node's own
`blockchain.pool_min_remaining_deposit_micro_usdc`; the CLI passes zero. The
reserve only starts a top-up and never refuses a draw, because a peer with a
smaller M still serves. ADR 003 states the rule.

After a top-up, the driver's settle allowance now stays armed across landed
legs: a peer can admit one stream on headroom it computed before its watcher
saw the top-up and then refuse the next re-open, which was terminal.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
… concurrent transaction (#1893)

A node signs its sellers' redeemMany transactions and its buyer topUp with one
operator key, through providers that each read the pending nonce per send. A
topUp sent while a redemption was in flight could take the same nonce and be
rejected "nonce too low", which spent the pull's single reactive top-up and
failed the fetch.

tx::is_nonce_collision recognises that JSON-RPC rejection (nothing was
broadcast, so re-sending is safe), and buyer_pool::top_up re-sends up to three
more times, a quarter second apart.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
…1893)

The encode reads ahead of the serve loop by up to its channel capacity, so its
data and outboard readers park at a pull's frontier while the serve loop still
has encoded bytes buffered, or is only doing its closed-window prefetch. The
readers raised serve demand on every such park, so a client that had stopped
paying could still drag the pull one floor past its window:
window_pull_through_underpaid_voucher_abandons_bounded pulled and cached the
whole 1.5 MiB blob under load.

The readers now record the offset they park on in a shared cell
(SessionOutboardReader::parked_on). CoherentFrameProducer publishes it as serve
demand only when the encode is parked and the frame channel is empty — the
stall the demand exists to break. ADR 037 states the rule.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

Copy link
Copy Markdown

Contracts coverage

Line coverage: 89.75% (2575/2869 lines)
▲ +0.00pp vs base (89.75% → 89.75%)
Run: 34889497031

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.

High-rate node-to-node pull fails deterministically; blocks un-ignoring node_pull_topup e2e (#1598)

2 participants