Skip to content

feat: credit slow-start — ramped credit window (start at floor, ramp with paid) (#1669) - #1691

Merged
alpergundogdu merged 14 commits into
mainfrom
claude/issue-1669-credit-window-1f8926
Aug 14, 2026
Merged

alpergundogdu merged 14 commits into
mainfrom
claude/issue-1669-credit-window-1f8926

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #1669.

What

Replaces the flat per-stream credit window (credit_window_bytes, default 8 MiB) and the ADR 037 seed-leech caps (LeechGovernor + the three [cache] knobs) with a single mechanism: a credit window that ramps linearly with each stream's own cumulative bytes paid.

window(paid) = if credit_ramp_divisor == 0 { max(floor, credit_max) }
               else { (paid / credit_ramp_divisor).clamp(floor, max(floor, credit_max)) }
  • floor = one voucher interval (keeps ADR 003's "always make progress" invariant, so a voucher can clear and drive the ramp).
  • credit_max — window ceiling, node config, default 64 MiB.
  • credit_ramp_divisor — paid-bytes-per-window divisor, node config, default 2 (0 = instant full credit_max).

A stream starts at the floor and grows its window to paid / credit_ramp_divisor, capped at credit_max. A non-paying stream stays pinned at the floor. Per-stream and stateless — window is a pure function of that stream's paid counter, which resets every stream. No client history, no graduation ledger.

Why linear in paid, not exponential in vouchers

Risk (unbilled egress the node may never collect) is linear in bytes; payments are linear in bytes. Tying the window linearly to cumulative paid bytes makes the node's exposure a fixed fraction of confirmed revenue:

exposure = delivered − paid ≤ window ≤ paid / credit_ramp_divisor

At the default divisor of 2, an attacker must pay for two bytes to extract one byte of free-ride, so the node nets positive on every stream — including a pure pay-a-little-then-abandon attack.

Retires the seed-leech caps (ADR 037)

On the fused serve-miss path the upstream pull and the downstream serve are one stream, so one ramped window governs both. The new RampPacer (in client-pull) recomputes the same window from the downstream served-paid frontier, keeping pull and serve in lockstep — a non-paying client fronts at most one interval of speculative upstream spend, never the ceiling. LeechGovernor, pull_ahead_bytes, max_unrecouped_leech_bytes, and pull_share_ratio_percent are deleted; the pre-flight deposit guard (now pricing the floor) plus pool solvency M are the retained bound, so aggregate node exposure is bounded by real capital (Σ pool deposits / credit_ramp_divisor in the ramped regime, per-stream one interval at the floor).

Changes

  • decdn-incentive: shared ramped_credit_window(divisor, floor, credit_max, paid) — one formula, used by both the serve loop and the pacer.
  • decdn-node: serve loop recomputes the window from live paid each iteration; deposit guards price the floor; LeechGovernor deleted; RampPacer replaces LeechPacer on the pull leg.
  • decdn-common: config surface — credit_max + credit_ramp_divisor replace credit_window_bytes; three [cache] knobs removed.
  • decdn-cli: client shortfall estimate bases on the floor; config template/dump updated.
  • ADR 003 §Credit Window and ADR 037 rewritten to present-tense canon.

Scope / sequencing

Verification

cargo build, cargo clippy (0 warnings), cargo fmt --check, cargo nextest run (2768 passed), cargo deny check, cargo test --no-run -p decdn-e2e --features anvil-e2e — all green. Grep for every retired identifier is empty outside adr/_history/.

🤖 Generated with Claude Code

alpergundogdu and others added 12 commits August 14, 2026 12:31
…1669)

Rewrite the two STALE(#1669) comment blocks in cli_fetch_topup.rs left by an
earlier pass: the pre-serve deposit gate now prices a cold request at the
ramp floor (one 4 MiB voucher interval, 8 USDC at the test rate), not the old
flat two-interval 8 MiB window (16 USDC). Both test deposits are still
comfortably over-provisioned against the corrected floor, so only the
explanatory comments change, not the numeric constants.

Full verification gate is green: build, clippy, fmt, nextest (2768/2768),
cargo deny, and the anvil-e2e compile check all pass, and the sweep grep for
retired credit-window/leech-governor identifiers is empty outside
adr/_history/.
Copilot AI lite review requested due to automatic review settings August 14, 2026 14:04

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 implements the “credit slow-start” design by replacing the fixed per-stream credit window and the ADR 037 seed-leech caps with a single, stateless mechanism: a per-stream credit window that ramps as a pure function of that stream’s cumulative paid bytes (plus a floor and ceiling). This aligns downstream delivery pacing and upstream pull-through pacing under the same ramp logic, while simplifying the configuration surface and deleting the leech governor layer.

Changes:

  • Introduces shared ramped_credit_window() logic in decdn-incentive and reuses it across node serve loops and node pull-leg pacing (RampPacer).
  • Removes ADR 037 seed-leech caps and their config/metrics (LeechGovernor, related cache knobs, and counters), updating runtime wiring and tests accordingly.
  • Updates CLI behavior/config templates plus multiple ADRs to reflect the ramped credit-window model and the new config knobs (credit_max, credit_ramp_divisor).

Reviewed changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
crates/protocol/src/client.rs Updates StreamError::NotFound documentation to reference the new pull-through policy framing.
crates/node/tests/sighup_signal.rs Updates resolved config fixture to new payment knobs and removes retired cache knobs.
crates/node/tests/node_origin_pull.rs Refactors test harness wiring for pull-through to remove leech governor and use ramp-based window assumptions.
crates/node/tests/client_loopback.rs Reworks loopback tests to cover ramp behavior (floor, ramp growth, divisor=0 instant ceiling) and updates handler wiring.
crates/node/tests/anvil_bringup_shutdown_e2e.rs Updates config fixture to new payment knobs and removes retired cache knobs.
crates/node/src/runtime/reload.rs Removes restart-required detection for deleted cache knobs and updates payment restart-required warning text.
crates/node/src/runtime/mod.rs Removes leech governor / pull-ahead wiring and sets handler deps to credit_max + credit_ramp_divisor.
crates/node/src/node_origin/pull_leg.rs Replaces LeechPacer with RampPacer and updates pull-leg pacing/scoring behavior accordingly.
crates/node/src/metrics.rs Removes seed-leech cap pause counters; updates window-paused documentation to ramped window terminology.
crates/node/src/lib.rs Removes leech_governor module export.
crates/node/src/leech_governor.rs Deletes the leech governor implementation (caps + accounting + tests).
crates/node/src/handlers/client/window.rs Updates pull-through reservation/pacing to use the ramp floor and passes ramp params to the pull leg.
crates/node/src/handlers/client/voucher.rs Removes leech governor “served” crediting from voucher path.
crates/node/src/handlers/client/mod.rs Replaces downstream credit_window_bytes with credit_max + credit_ramp_divisor and routes credit window computation through shared ramp function.
crates/node/src/handlers/client/fill.rs Removes leech_admit helper and associated leech-governor wiring.
crates/node/src/handlers/client/dispatch.rs Updates pre-serve deposit gate to price the ramp floor at paid = 0 and adjusts documentation accordingly.
crates/node/src/handlers/client/delivery.rs Recomputes effective window per loop iteration based on paid; updates batching cap to size against the ceiling.
crates/incentive/src/lib.rs Adds credit module and re-exports ramped_credit_window.
crates/incentive/src/credit.rs Adds the shared ramped credit window function with unit tests.
crates/e2e/tests/cli_fetch_topup.rs Updates E2E top-up test documentation/math to the new “floor-priced” gate behavior.
crates/common/src/config/types.rs Removes seed-leech cache knobs and replaces payment credit window config with credit_max + credit_ramp_divisor.
crates/common/src/config/resolved.rs Updates resolved config types to match new payment knobs and removes retired cache knobs.
crates/common/src/config/mod.rs Updates defaults and resolver logic for new payment knobs; removes seed-leech defaults and cross-field checks.
crates/client-pull/src/pacer.rs Adds RampPacer and unit tests; updates pacer docs to match new model.
crates/client-pull/src/lib.rs Re-exports RampPacer.
crates/cli/tests/config_validate.rs Updates resolved config fixture to new payment knobs and removes retired cache knobs.
crates/cli/src/commands/fetch.rs Updates shortfall estimation to use a voucher-interval floor estimate rather than the prior fixed credit window default.
crates/cli/src/commands/config.rs Updates config template, validation summary, and tests to reflect removed cache knobs and new payment knobs.
crates/cache/src/engine.rs Updates origin range-pull documentation to reflect new exposure framing and terminology.
adr/architecture.md Updates ADR 037 index entry to reflect ramped-window pacing instead of seed-leech caps.
adr/039-multi-source-parallel-fetch.md Updates ADR references from seed-leech caps to ramped credit window + deposit guard.
adr/038-bao-verified-range-streaming.md Updates ADR references from seed-leech caps to ramped credit window.
adr/037-regional-proxy-warming.md Rewrites ADR 037 to replace seed-leech caps with the ramped credit-window mechanism and updates commitments/risks accordingly.
adr/022-content-discovery.md Updates cache warming abuse-bound references to the ramped credit window.
adr/005-protocol.md Updates cdn/client/v1 narrative to refer to ramped credit window policy instead of seed-leech caps.
adr/003-payments.md Rewrites ADR 003 credit window section to document the ramped window mechanism and new configuration knobs.
Suppressed comments (1)

crates/cache/src/engine.rs:2362

  • The origin-egress metering here is correct, but the comment currently implies ADR 037’s ramped credit window “counts” these bytes directly. The ramp/window pacing is defined in content bytes; the metered value here includes outboard overhead. Rewording would prevent readers from assuming the pacing window includes outboard bytes 1:1.
        // Meter the actually-pulled bytes (span + outboard) as origin egress —
        // the bytes really did leave an origin. This is what ADR 037's ramped
        // credit window counts against: the pulled side, not the whole blob.
        if let Some(m) = &self.inner.metrics {

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

Comment thread crates/incentive/src/credit.rs Resolved
Comment thread crates/node/src/handlers/client/mod.rs Resolved
Comment thread crates/client-pull/src/pacer.rs Resolved
Comment thread crates/cache/src/engine.rs Resolved
Comment thread adr/003-payments.md Resolved
alpergundogdu and others added 2 commits August 14, 2026 16:22
…ed VOUCHER_INTERVAL_BYTES (#1669)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…x outboard-vs-window accounting wording (#1669)

Addresses PR #1691 review: the 'exposure at most paid/divisor' claim now
names the one-interval floor (and paid=0) and the divisor=0 instant-ceiling
case; the origin range-pull comments distinguish the content span the ramped
window paces from the outboard's additional origin egress.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 80.70% (was 80.76%, ▼ 0.05%) — 58897/72980 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 91.82% 3536/3851 ● 0.00%
crates/cli/src/commands/config.rs 85.62% 518/605 ▼ 0.14%
crates/cli/src/commands/fetch.rs 31.06% 323/1040 ▲ +0.06%
crates/client-pull/src/lib.rs 89.69% 1462/1630 ▼ 0.06%
crates/client-pull/src/pacer.rs 98.97% 192/194 ▲ +0.20%
crates/common/src/config/mod.rs 97.13% 6775/6975 ▲ +0.03%
crates/common/src/config/resolved.rs 100.00% 33/33 ● 0.00%
crates/incentive/src/credit.rs 100.00% 28/28 new
crates/node/src/handlers/client/delivery.rs 95.39% 207/217 ▲ +0.02%
crates/node/src/handlers/client/dispatch.rs 83.73% 350/418 ▲ +0.04%
crates/node/src/handlers/client/fill.rs 64.04% 73/114 ▼ 1.80%
crates/node/src/handlers/client/mod.rs 88.26% 684/775 ▼ 0.09%
crates/node/src/handlers/client/voucher.rs 88.56% 333/376 ▼ 0.35%
crates/node/src/handlers/client/window.rs 75.00% 294/392 ▼ 0.42%
crates/node/src/leech_governor.rs — — deleted
crates/node/src/metrics.rs 95.34% 1023/1073 ● 0.00%
crates/node/src/node_origin/pull_leg.rs 86.21% 569/660 ▼ 1.43%
crates/node/src/runtime/mod.rs 46.86% 1082/2309 ▲ +0.14%
crates/node/src/runtime/reload.rs 96.75% 1397/1444 ▼ 0.05%
crates/protocol/src/client.rs 99.04% 719/726 ● 0.00%
History
Commit Total Δ vs base
ea9754f (HEAD) 80.70% ▼ 0.05%

@alpergundogdu

Copy link
Copy Markdown
Contributor Author

Re: the coverage report (▼0.05% total) — this is expected and not a gap in new code. Every file that dropped is one this PR deletes code from: removing the fully-tested leech_governor.rs module and its call sites (fill.rs::leech_admit, the window.rs admission gate, voucher.rs::record_served) strips covered lines and shifts those files' ratios (fill.rs, window.rs, voucher.rs, mod.rs).

The new ramp logic is well exercised:

  • crates/incentive/src/credit.rs — 100% (new), 6 formula unit tests
  • crates/client-pull/src/pacer.rs — ▲+0.20% (RampPacer, floor-park + widen-on-advance cases)
  • crates/node/src/handlers/client/delivery.rs / dispatch.rs — ▲, plus three ramp integration tests in client_loopback.rs

No untested new logic, so no fix warranted — adding tests around the deleted paths would just game the metric.

🤖 Addressed by Claude Code

@alpergundogdu
alpergundogdu merged commit 314f3c3 into main Aug 14, 2026
26 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issue-1669-credit-window-1f8926 branch August 14, 2026 16:13
alpergundogdu added a commit that referenced this pull request Aug 14, 2026
Reconcile the node-origin pull port with main's credit-slow-start ramped
credit window (#1691) and fixed voucher cadence (#1676), and the
present-tense comment rewrite (#1687).

- Delete resume.rs (the buffered loop this branch already replaced); main
  only rewrote its comments.
- Keep the collapsed SettleOnDrop (no SettleDeps enum / lifetime), our
  driver delivered_frontier completion clamp, and the AlreadyAdmitted +
  typed-fault-recovery ingest changes, alongside main's RampPacer rework.
- Restore the AtomicBool import dropped with main's LeechPacer removal.
- Resize the concurrent-resume fixture to span several VOUCHER_INTERVAL_BYTES
  so it still exercises mid-pull exhaustion under the ramped credit window.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
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.

feat: credit-slow-start — fixed-ramp credit window (start slow, ramp quick)

2 participants