Repository navigation
feat(node): window-paced pull-through for regional proxy warming (#856) - #893
Conversation
Implements the node-side serving behavior of ADR 037: a node serving a cdn/client/v1 request for a blob it does not hold fills it by a fused window-paced pull — forwarding each verified upstream chunk to the paying client and teeing it into the cache — pacing upstream spend by the client's vouchers so per-request speculative exposure is bounded to pull_ahead_bytes rather than the whole blob. Node-wide abuse is bounded by the LeechGovernor seed-leech caps (global unrecouped budget + per-peer share ratio), and a pre-flight deposit guard refuses pulls a channel provably cannot pay for. Includes review hardening: - Fix a runtime-starving busy-spin when a seed-leech cap denies mid-stream with no interval to recoup: the loop now abandons rather than spinning with no await point. - Charge pulled bytes to the governor the instant the upstream is paid, before the fallible tee/forward, so abandon paths cannot hide spend. - Close the deposit-guard fail-open when max_blob_size_bytes is unbounded (fall back to the per-request window cost). - Add tee-finalize-failed and upstream-verify-failed metrics on the two spend-bearing finalize arms. - Reject pull_ahead_bytes > max_unrecouped_leech_bytes at config load. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request implements the window-paced regional proxy warming and pull-through mechanism specified in ADR 037. It introduces a TeeSink to stream and incrementally verify chunks into the cache while forwarding them to clients, and adds a LeechGovernor to enforce global and per-peer speculative pull caps. Feedback on the changes highlights a potential Denial of Service (DoS) vulnerability in the LeechGovernor's eviction logic, where a linear scan of up to 65,536 peers to find the oldest entry runs in O(N) time and could lead to CPU exhaustion under high peer churn.
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
Implements node-side window-paced pull-through for cache-miss cdn/client/v1 requests (#856 / ADR 037), fusing progressive upstream pull with downstream delivery while bounding speculative exposure via a per-request window, a pre-flight deposit guard, and node-wide “seed-leech” caps.
Changes:
- Add progressive upstream pull plumbing (
open_progressive_pull/UpstreamPull) and a fused serve path that forwards verified chunks while teeing into the cache. - Introduce seed-leech governance (
LeechGovernor) and operator-configurable caps (pull_ahead_bytes,max_unrecouped_leech_bytes,pull_share_ratio_percent) with validation and CLI visibility. - Add new metrics plus extensive end-to-end tests covering drop/underpay, insufficient deposit refusal, leech stall regression (busy-spin), and corrupt upstream behavior.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/handlers/client.rs | Adds window-paced pull-through serve path, deposit guard, leech-governor integration, and related metrics wiring. |
| crates/node/src/node_origin.rs | Adds progressive pull open path and NodeProgressivePull wrapper for bookkeeping + persistence/scoring. |
| crates/node/src/client_requester.rs | Introduces progressive upstream pull (UpstreamPull) and open helper for header-first streaming. |
| crates/cache/src/engine.rs | Adds tee-based cache fill (open_tee_sink / TeeSink) and shared stream-import/verify path. |
| crates/cache/src/lib.rs | Re-exports tee-related types for node use. |
| crates/node/src/leech_governor.rs | New in-memory governor enforcing global unrecouped budget + per-peer share ratio caps. |
| crates/node/src/metrics.rs | Adds new counters for window pacing, leech caps, abandon paths, and finalize failures. |
| crates/node/src/runtime/mod.rs | Wires window pull-through + leech governor into runtime when origin is available. |
| crates/node/src/runtime/reload.rs | Updates resolved-config defaults for newly added cache cap fields. |
| crates/common/src/config/types.rs | Adds new cache config knobs and docs. |
| crates/common/src/config/resolved.rs | Adds resolved fields for new cache cap knobs. |
| crates/common/src/config/mod.rs | Adds defaults + config validation (window must not exceed enabled global budget). |
| crates/cli/src/commands/config.rs | Surfaces new cap values in config validation output and default config template. |
| crates/cli/tests/config_validate.rs | Updates resolved-config fixture for new cache cap fields. |
| crates/node/tests/node_origin_pull.rs | Adds end-to-end tests for window-paced pull-through behavior and regressions. |
| crates/node/tests/sighup_signal.rs | Updates resolved-config fixture for new cache cap fields. |
| crates/node/src/lib.rs | Exposes leech_governor module. |
| crates/node/Cargo.toml | Adds blake3 dependency for incremental verification in progressive pulls. |
| crates/incentive/src/rate.rs | Adds min_payment helper (ceil pricing) plus tests. |
| crates/incentive/src/lib.rs | Re-exports min_payment. |
| Cargo.lock | Locks new blake3 dependency. |
| adr/037-regional-proxy-warming.md | Documents that #856 implements the ADR’s node-side window-paced pull-through. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 85.74% (was 85.74%, ▼ 0.01%) — 36982/43135 lines
History
|
- leech_governor: replace the O(n) full-table eviction scan with an O(log n) BTreeMap LRU index (per gemini-code-assist) — preserves true LRU so an active peer is never the eviction victim, removing the CPU amplification surface under Sybil peer-churn once the table is full. - client_requester: correct the `expected()` doc — it returns the remaining bytes (`total_bytes - byte_offset`), not `total_bytes`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…urfacing, coverage) Follow-up review fixes for window-paced pull-through (#856): - ADR 037: correct the deposit-guard description — when max_blob_size_bytes is unbounded the guard falls back to the per-request window cost, it is NOT skipped (the code never fails open); clarify the look-ahead deferral wording. - client.rs: surface a coalesced-fill `has()` store fault instead of silently reclassifying it as a miss; split a tee HashMismatch (forwarded/teed stream divergence — error) from a routine store fault (warn); log a failed success-path finish(); add channel/byte context to the verify-failure and seed-leech-throttle teardown logs (no in-band frame: the protocol's frozen StreamError domain split forbids a mid-stream delivery-fault code). - leech_governor.rs: document that may_pull mutates LRU state despite its predicate-style name. - tests: add window_pull_through_resumed_offset_falls_back_not_fused (the byte_offset>0 fused-path guard was untested); assert the window pause/resume actually fires in the full-blob test; tighten the upstream-spend bound to +2 chunks to match the documented "window + one chunk". Deferred items tracked as #894 (Bytes/Percent newtypes), #895 (concurrent coalescing E2E), #896 (tee_finalize_failed coverage). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Resolve conflicts from #899 (#820 prefetch ledger) landing alongside the #856 window-paced pull-through work: - node_origin.rs: keep the PR's persist_buyer_progress() helper refactor for the buyer voucher-watermark write AND main's #820 acquisition-observer block that surfaces per-pull spend/bytes to the prefetch ledger. - handlers/client.rs: keep both additive sets of post-construction fields (window pull-through: pull_through_origin/pull_ahead_bytes/leech_governor; prefetch: prefetch_engine) and both serve-path credits (leech_governor record_served + prefetch note_served_if_prefetched). - tests/node_origin_pull.rs: drop the duplicate decdn_cache::Hash import (main folds it into {CacheEngine, Hash}) and the duplicate counter_value helper (keep main's absent-counter-as-0 variant; satisfies both branches' callers). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Apply the multi-agent review findings on the window-paced pull-through: - node_origin: wire the #820 prefetch acquisition observer into the window path's NodeProgressivePull::finish/abandon (was buffered-path only) via a shared feed_acquisition_observer helper, so per-pull spend can never silently escape the rolling budget if a prefetch pull is ever routed onto the fused path; add a node_pull_delta_overflow metric to the narrow_pull_delta clamp. - leech_governor: private LeechCaps fields behind a validated LeechCaps::new() -> Result<_, WindowExceedsBudget> (with an explicit new_unchecked for intentional edge-config tests); rename may_pull -> poll_admission and document it as a stateful, advisory (non-reserving) poll; correct the MAX_TRACKED_PEERS memory estimate and new() doc. - client_requester: add a Drop safety net on UpstreamPull to close the upstream connection if no terminal method ran; fix the deadline doc to describe what actually bounds a mid-stream stall. - client.rs: distinct node_pull_through_local_tee_failed metric for a local tee-write fault (vs client drop); fix the pull_chunk_bytes -> CHUNK_SIZE comment and scope the abandon_window_serve doc. - runtime: build LeechCaps via the validated constructor. - tests: LeechCaps::new validation; window BlobTooLarge abort arm (+ tee-not-stranded repeat request); per-peer share-ratio admission refusal. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Node-side window-paced pull-through (ADR 037 §Node serving, issue #856). A bonded node serves a cache-miss
cdn/client/v1request by fusing a progressive upstream pull with downstream delivery: each verified upstream chunk is forwarded to the paying client and tee'd into the local cache, and the pull pauses whenever the per-request unrecouped frontier (bytes_pulled − bytes_paid) reachespull_ahead_bytes, resuming as vouchers clear. The node thereby becomes the first regional copy of the blob with per-request speculative exposure bounded to one window instead of the whole blob.Three operator-configurable
[cache]caps ship from day one:pull_ahead_bytes— per-request pipeline windowmax_unrecouped_leech_bytes— node-wide unrecouped-leech budgetpull_share_ratio_percent— per-peer share ratioThe seed-leech caps live in the new
crate::leech_governor::LeechGovernor. A pre-flight deposit guard refuses a pull outright (signedNotFound) when the channel's remaining deposit cannot cover the worst-case cost.Review hardening (this branch)
window_forward_loopthat starved the tokio runtime when a seed-leech cap denied the speculative pull mid-stream with no interval to recoup — the loop now refuses (abandons the partial fill) rather than looping with no await point. Regression-guarded by a handler↔governor test that previously hung the runtime.max_blob_size_bytes == 0(falls back to the per-request window cost).node_pull_through_tee_finalize_failedandnode_pull_through_upstream_verify_failedmetrics on the two spend-bearing finalize arms.pull_ahead_bytes > max_unrecouped_leech_byteswhen the global cap is enabled.Testing
cargo clippy --workspace --all-targets— cleancargo fmt --check— cleancargo nextest run— 1159 passed, 0 failedNew behavioral tests: handler↔governor in-loop pause (busy-spin regression guard) and admission refuse, fused-path corrupt-upstream (not cached), and mid-window underpayment abandonment.
🤖 Generated with Claude Code