Skip to content

fix: buyer-side rate integrity & slash evidence on the paid-pull path (#1375, #1377, #1382) - #1420

Merged
thiras merged 1 commit into
mainfrom
fix/buyer-rate-integrity-1375-1377-1382
Jul 23, 2026
Merged

thiras merged 1 commit into
mainfrom
fix/buyer-rate-integrity-1375-1377-1382

Conversation

@thiras

@thiras thiras commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Batch of three tightly-coupled fixes on the paid-pull buyer path, all surfaced in the G-GOV e2e review series and reviewed by the multi-agent PR toolkit before opening.

#1377 — express UpstreamRefused's evidence invariants in the type

UpstreamRefused becomes a newtype over a private inner enum (Open{error,response} / MidStream{error}). Enum variant fields can't be private in Rust, so the newtype is what makes "present response ⇒ open-stage, verified" unforgeable rather than doc-comment convention. Crate-private open() derives error from the response (and rejects ok == true); pub mid_stream() is provably evidence-free; error()/evidence() accessors; a slash_sig-eliding Debug. All consumers migrated (.error→.error(), .response→.evidence()) — including the e2e on-chain-challenge feeder, which can no longer be handed an unverified response.

#1375 — buyer-side rate ceiling + retained slash evidence

The buyer refuses a stream quote above effective_rate_ceiling(candidate probe rate, config max_rate_per_mb) before paying any voucher, via a typed RateAboveCeiling that carries the operator's own signed over-quote as replayable rate-manipulation evidence (a single crate-private constructor derives the quoted rate from the response, so it can't desync). Classified as reputation-neutral PullVerdict::RateCeiling: metered (node_pull_rate_above_ceiling) and suppressed, never tarring the peer. New cache.max_rate_per_mb knob wired through every surfacing site and both the node-to-node and CLI buyer paths.

#1382 — graceful re-quote signal on a live-floor voucher rejection

Emits the new VoucherRejectReason::RateFloorRaised (appended wire variant) instead of an opaque anyhow::bail! when a governance floor raise strands an honest buyer's quote; the buyer classifies it retry-with-re-quote (channel kept). Scope per merged #1388, which correctly kept the live-floor read as the node's on-chain-mirrored self-protection.

Notes

  • ADR 005 (SoT) updated with the new reason plus the two handler-direct variants its listing had drifted from.
  • RateAboveCeiling evidence is retained on the error for a caller; the daemon does not yet auto-submit a challenge (auto-slashing deferred, same footing as UpstreamRefused evidence today).
  • Buyer-side success-path retention was intentionally not added: the always-applied probe-relative ceiling makes a completed delivery priced ≤ probe rate by construction, so it can never be rate-manipulation — the evidence is captured at the ceiling-abort instead.

Tests

Unit (effective_rate_ceiling, UpstreamRefused encapsulation, open() ok==true rejection, wire-order freeze incl. RateFloorRaised), loopback (over-ceiling refusal with evidence signature recovery, exact-ceiling accept), and a node-origin integration test pinning the probe-relative bound + RateCeiling verdict + metric + reputation neutrality.

Verified: fmt --check, clippy --workspace --all-targets, protocol/client-pull/node suites, public-api snapshot, and the anvil-e2e build.

Closes #1375
Closes #1377
Closes #1382

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added an optional buyer-side per-MB rate ceiling for paid downloads, configurable through CLI, environment variables, or configuration files.
    • Downloads now stop before payment when a provider’s quoted rate exceeds the configured ceiling.
    • Added visibility for rate-ceiling refusals through metrics and configuration validation output.
  • Bug Fixes

    • Improved handling of mid-stream voucher rejections, including expiry, cooperative close, and raised delivery-floor scenarios.
    • Clients now retry, re-quote, or open a fresh stream according to the rejection reason.

Copilot AI review requested due to automatic review settings July 23, 2026 21:39
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 32 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: 3c733965-c7af-4747-bf5b-28a0d6b8ec9b

📥 Commits

Reviewing files that changed from the base of the PR and between 3d7cde7 and ce52c9b.

⛔ Files ignored due to path filters (1)
  • crates/protocol/tests/snapshots/public_api__public_api.snap is excluded by !**/*.snap, !**/*.snap
📒 Files selected for processing (23)
  • adr/005-protocol.md
  • crates/cli/src/commands/bundle_pull.rs
  • crates/cli/src/commands/config.rs
  • crates/cli/src/commands/fetch.rs
  • crates/cli/tests/config_validate.rs
  • crates/client-pull/src/lib.rs
  • crates/common/src/cli/fetch.rs
  • crates/common/src/cli/run.rs
  • crates/common/src/config/mod.rs
  • crates/common/src/config/resolved.rs
  • crates/common/src/config/types.rs
  • crates/e2e/src/client.rs
  • crates/e2e/tests/g_node_08_authorized_origin.rs
  • crates/e2e/tests/g_node_08_revocation.rs
  • crates/node/src/handlers/client/voucher.rs
  • crates/node/src/metrics.rs
  • crates/node/src/node_origin.rs
  • crates/node/src/runtime/mod.rs
  • crates/node/src/runtime/reload.rs
  • crates/node/tests/client_loopback.rs
  • crates/node/tests/node_origin_pull.rs
  • crates/node/tests/sighup_signal.rs
  • crates/protocol/src/client.rs

Walkthrough

The change adds buyer-side per-MB rate ceilings, threads them through configuration and pull APIs, rejects over-ceiling quotes before payment, refactors upstream refusal access, and adds typed rate-floor voucher rejection handling with node-origin classification and tests.

Changes

Rate Ceiling and Refusal Handling

Layer / File(s) Summary
Protocol and voucher rejection contracts
adr/005-protocol.md, crates/protocol/src/client.rs, crates/node/src/handlers/client/voucher.rs
Adds voucher rejection semantics for expiry, cooperative close, and raised delivery floors; live-floor failures now emit RateFloorRaised instead of a generic error.
Rate ceiling configuration and CLI wiring
crates/common/src/cli/*, crates/common/src/config/*, crates/cli/src/commands/*, crates/node/src/runtime/*
Adds max_rate_per_mb, resolves CLI/file/default precedence, exposes it in templates and summaries, and passes it through fetch and runtime configuration.
Client pull enforcement and refusal model
crates/client-pull/src/lib.rs
Adds RateAboveCeiling, effective ceiling calculation, pre-payment quote rejection, and typed UpstreamRefused constructors/accessors across buffered and progressive pulls.
Node-origin enforcement and classification
crates/node/src/node_origin.rs, crates/node/src/metrics.rs
Applies probe-relative and configured ceilings, meters and suppresses over-ceiling refusals without reputation scoring, and treats RateFloorRaised as retryable.
Call-site migration and behavioral validation
crates/cli/tests/*, crates/e2e/*, crates/node/tests/*
Updates refusal and pull call sites and tests pre-payment rejection, exact-ceiling success, evidence preservation, and neutral node-origin classification.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant NodeOrigin
  participant Upstream
  participant VoucherHandler
  Client->>NodeOrigin: request paid pull with max_rate_per_mb
  NodeOrigin->>Upstream: probe candidate and open stream
  Upstream-->>NodeOrigin: signed StreamResponse quote
  NodeOrigin->>NodeOrigin: compute effective rate ceiling
  alt quote exceeds ceiling
    NodeOrigin-->>Client: RateAboveCeiling with signed evidence
  else quote accepted
    NodeOrigin->>VoucherHandler: submit voucher
    VoucherHandler-->>NodeOrigin: VoucherAck or RateFloorRaised
    NodeOrigin-->>Client: pull result or retryable re-quote outcome
  end
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.

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 hardens the paid-pull buyer path by (1) making slash-evidence invariants unforgeable in types, (2) enforcing a buyer-side rate ceiling with retained signed over-quote evidence, and (3) adding an explicit wire-level re-quote signal when the live delivery floor rises mid-stream.

Changes:

  • Introduce UpstreamRefused encapsulation so “signed evidence present ⇒ open-stage, verified” is enforced by construction, and adjust all call sites to use accessors.
  • Add buyer-side rate ceiling enforcement (RateAboveCeiling + effective_rate_ceiling) and plumb a new cache.max_rate_per_mb knob through node + CLI paths, including metrics and tests.
  • Append VoucherRejectReason::RateFloorRaised to the protocol and use it server-side to signal a floor-raise-induced re-quote instead of an opaque transport error.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/protocol/tests/snapshots/public_api__public_api.snap Public API snapshot update for the appended RateFloorRaised variant.
crates/protocol/src/client.rs Adds VoucherRejectReason::RateFloorRaised with ordering freeze + documentation.
crates/node/tests/sighup_signal.rs Extends resolved cache config seed with max_rate_per_mb.
crates/node/tests/node_origin_pull.rs Plumbs max_rate_per_mb into origin configs and adds an integration test for probe-relative rate ceiling behavior + metric + reputation neutrality.
crates/node/tests/client_loopback.rs Adds loopback tests for buyer rate ceiling refusal/accept boundary and evidence retention; updates call signatures.
crates/node/src/runtime/reload.rs Seeds + restart-required detection includes cache.max_rate_per_mb.
crates/node/src/runtime/mod.rs Threads resolved cache.max_rate_per_mb into NodeOriginConfig.
crates/node/src/node_origin.rs Applies effective_rate_ceiling, classifies RateAboveCeiling as PullVerdict::RateCeiling, adds metric + suppression behavior, and handles RateFloorRaised as retryable-with-channel-kept.
crates/node/src/metrics.rs Adds node_pull_rate_above_ceiling counter and recorder hook.
crates/node/src/handlers/client/voucher.rs Emits RateFloorRaised on live-floor rejection instead of bail!, aiming for a graceful re-quote signal.
crates/e2e/tests/g_node_08_revocation.rs Migrates UpstreamRefused usage to accessor-based API.
crates/e2e/tests/g_node_08_authorized_origin.rs Migrates UpstreamRefused usage to accessor-based API.
crates/e2e/src/client.rs Migrates to UpstreamRefused::{error(), evidence()} and updates buyer call signatures for the new ceiling parameter.
crates/common/src/config/types.rs Adds cache.max_rate_per_mb to config types with documentation.
crates/common/src/config/resolved.rs Adds resolved max_rate_per_mb with documented semantics (0 = unlimited).
crates/common/src/config/mod.rs Resolves max_rate_per_mb from CLI/env/file and wires env var name.
crates/common/src/cli/run.rs Adds --max-rate-per-mb to node run CLI args (and env support).
crates/common/src/cli/fetch.rs Adds --max-rate-per-mb to CLI fetch args, documented as an opt-in ceiling on the client path.
crates/client-pull/src/lib.rs Adds RateAboveCeiling, effective_rate_ceiling, rate ceiling checks in open stage, and encapsulates UpstreamRefused evidence invariants.
crates/cli/tests/config_validate.rs Updates sample resolved config with max_rate_per_mb.
crates/cli/src/commands/fetch.rs Threads max_rate_per_mb through CLI fetch/bundle pull plumbing; updates UpstreamRefused handling.
crates/cli/src/commands/config.rs Prints max_rate_per_mb in validate summary and documents it in the default config template.
crates/cli/src/commands/bundle_pull.rs Threads max_rate_per_mb into per-entry pulls and updates UpstreamRefused usage in tests/logic.
adr/005-protocol.md Updates ADR protocol documentation to include RateFloorRaised semantics and retry behavior table.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…#1375, #1377, #1382)

Batch of three tightly-coupled fixes on the paid-pull buyer path, all
surfaced in the G-GOV e2e review series.

#1377 — express UpstreamRefused's evidence invariants in the type.
Convert the two-pub-field struct to a newtype over a private inner enum
(Open{error,response} / MidStream{error}). Enum variant fields cannot be
private in Rust, so the newtype is what makes "present response ⇒
open-stage, verified" unforgeable. Crate-private open() derives error from
the response (and now also rejects ok==true); pub mid_stream() is provably
evidence-free; error()/evidence() accessors; slash_sig-eliding Debug. All
consumers migrated (.error→.error(), .response→.evidence()), incl. the e2e
on-chain-challenge feeder which can no longer receive an unverified response.

#1375 — buyer-side rate ceiling + retained slash evidence.
Refuse a stream quote above effective_rate_ceiling(candidate probe rate,
config max_rate_per_mb) BEFORE paying, via a typed RateAboveCeiling that
carries the operator's own signed over-quote as replayable evidence (single
crate-private constructor derives the quoted rate from the response).
Classified as reputation-neutral PullVerdict::RateCeiling: metered
(node_pull_rate_above_ceiling) and suppressed, never tarring the peer. New
cache.max_rate_per_mb knob wired through all surfacing sites and both the
node-to-node and CLI buyer paths.

#1382 — graceful re-quote signal on a live-floor voucher rejection.
Emit the new VoucherRejectReason::RateFloorRaised (appended wire variant)
instead of an opaque anyhow::bail! when a governance floor raise strands an
honest buyer's quote; the buyer classifies it retry-with-re-quote (channel
kept). Scope per merged #1388, which correctly kept the live-floor read.

ADR 005 updated (SoT) with the new reason plus the two handler-direct
variants its listing had drifted from. Adds unit, loopback, and node-origin
integration coverage (probe-relative bound, exact-ceiling accept, evidence
signature recovery, RateCeiling verdict) and extends the wire-order freeze
test. Verified: fmt, clippy --all-targets, protocol/client-pull/node
suites, public-api snapshot, and e2e (anvil-e2e) build.

Closes #1375
Closes #1377
Closes #1382

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras force-pushed the fix/buyer-rate-integrity-1375-1377-1382 branch from 3d7cde7 to ce52c9b Compare July 23, 2026 22:06
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 81.00% (was 81.01%, ▼ 0.01%) — 51929/64109 lines

File Coverage Lines Δ
crates/cli/src/commands/bundle_pull.rs 56.54% 553/978 ▲ +0.12%
crates/cli/src/commands/config.rs 69.85% 183/262 ▼ 0.04%
crates/cli/src/commands/fetch.rs 35.15% 290/825 ▼ 0.37%
crates/client-pull/src/lib.rs 88.29% 1078/1221 ▼ 0.82%
crates/common/src/cli/fetch.rs 100.00% 117/117 ● 0.00%
crates/common/src/config/mod.rs 96.97% 6759/6970 ● 0.00%
crates/common/src/config/resolved.rs 100.00% 35/35 ● 0.00%
crates/e2e/src/client.rs 0.00% 0/364 ● 0.00%
crates/node/src/handlers/client/voucher.rs 76.97% 127/165 ▼ 2.28%
crates/node/src/metrics.rs 95.27% 966/1014 ● 0.00%
crates/node/src/node_origin.rs 91.32% 926/1014 ▲ +0.07%
crates/node/src/runtime/mod.rs 46.91% 1085/2313 ● 0.00%
crates/node/src/runtime/reload.rs 96.63% 1663/1721 ▲ +0.01%
crates/protocol/src/client.rs 97.35% 697/716 ● 0.00%
History
Commit Total Δ vs base
ce52c9b (HEAD) 81.00% ▼ 0.01%

@thiras
thiras merged commit 4251f77 into main Jul 23, 2026
24 checks passed
@thiras
thiras deleted the fix/buyer-rate-integrity-1375-1377-1382 branch July 23, 2026 22:17
thiras added a commit that referenced this pull request Jul 26, 2026
…rot again (#1473)

`crates/node/tests/anvil_bringup_shutdown_e2e.rs` has not compiled since
2026-07-23. `ResolvedConfig` gained a `content` field in #1380 and
`ResolvedCache` gained `max_rate_per_mb` in #1420; neither threaded the new
field into this builder. Adding the two initializers is the whole fix — the
test then passes on the first run, so nothing about the behaviour it asserts had
actually regressed.

The interesting part is why nobody noticed for three days. The `anvil e2e
(settlement)` job ran `--test anvil_settlement_e2e`, a single-target filter, so
this file was never built by any job in CI. It was even edited in its broken
state by #1465 the day before this fix, because touching a file that no job
compiles produces no signal. `cargo build --workspace --all-targets` does not
catch it either: the target is behind the off-by-default `anvil-e2e` feature.

So the job now names both anvil targets explicitly rather than filtering to one.
A bare `-p decdn-node --features anvil-e2e` would have been shorter but drags
the full unit suite in behind the feature flag and duplicates the `test` job;
the explicit list keeps the job scoped while making a missing target a build
failure instead of silence. The added target needs only `anvil` + `forge`, both
already on PATH in that job, and drives `runtime::run` in-process, so it fits
the "no daemon binary on disk" property the split relies on. Adds ~25s.

Both targets pass together locally: 5 tests across 2 binaries.

Incidental, found while auditing the metric registry for #1443:
`decdn_probe_holds_disabled_total` was documented twice in
`adr/appendix-observability.md` — once under § Slash-Safety Metrics and again
under § Probe Metrics — and the two copies had already drifted in wording. The
§ Slash-Safety Metrics row is canonical (that section's preamble states the
probe-hold capacity metrics are grouped there deliberately), so the § Probe
Metrics copy is removed and replaced with a pointer naming all five probe-hold
metrics and why they live elsewhere.

Co-Authored-By: Claude Opus 5 (1M context) <[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

2 participants