Repository navigation
feat(node): meter refused serve_stream paid-delivery requests (#876) - #884
Conversation
Every paid-delivery reject branch in `serve_stream` refused with a signed
`StreamResponse { ok: false }` and a `tracing::warn!` but incremented no
metric, so a refused stream was invisible to operator dashboards — there was
no way to alert on "rate of refused streams" or distinguish a misconfigured
client from an abuse campaign. This is the operator-side counterpart to the
#848/#875 silent-failure work.
Add six per-reason reject counters (the `iroh_metrics` backend has no runtime
labels, so one Counter per reason matches the existing `dispatch_rejected_*` /
`dht_rate_limit_rejected_*` convention):
decdn_serve_stream_rejected_{evicted_since_probe,cache_miss,internal_error,
blob_too_large,unknown_channel,owner_mismatch}_total
A private `ServeRejectReason` enum is threaded into the central `respond_error`
helper, which increments the matching counter at one site. The reason is the
single source of truth: `wire_error()` derives the signed `StreamError`, so the
three branches that deliberately share the wire `NotFound` (to avoid leaking
channel existence) stay wire-indistinguishable while remaining separately
countable server-side — and an inconsistent error/reason pairing is
unrepresentable at the call sites.
Tests: a metrics unit test asserts all six counters start at zero and each
method bumps exactly its own counter; five loopback tests assert the correct
counter advances on a real refusal (all reasons except InternalError, which
needs a faulting-cache double — deferred).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a server-side classification for serve_stream refusals using a new ServeRejectReason enum. This allows fine-grained tracking of rejection reasons (such as cache misses, unknown channels, or owner mismatches) via dedicated metrics, while still collapsing sensitive reasons into a generic NotFound error on the wire to prevent leaking channel existence. The changes also include corresponding updates to metrics tracking, unit tests, and integration tests to verify the counter increments. I have no feedback to provide as there are no review comments.
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
Adds per-reason observability for serve_stream paid-delivery refusals so operator dashboards can distinguish refusal causes (including wire-conflated NotFound cases) and alert on refusal rates.
Changes:
- Introduces six new
serve_stream_rejected_*counters in node metrics and exposes increment helpers. - Threads a private
ServeRejectReasonthroughserve_streamrefusal paths and increments the appropriate counter centrally inrespond_error. - Extends loopback integration tests to assert the correct counter increments for several real refusal scenarios; adds a test helper that returns the server
Arc<Metrics>.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/node/src/handlers/client.rs | Adds ServeRejectReason and centralizes per-reason refusal metric increments in respond_error. |
| crates/node/src/metrics.rs | Defines/export six new refusal counters plus unit tests verifying zero-exposure and per-counter increments. |
| crates/node/tests/client_loopback.rs | Adds metrics-aware server spawn helper and E2E assertions that specific refusal paths bump the correct counter. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 86.14% (was 86.12%, ▲ +0.02%) — 35061/40702 lines
History
|
Address PR review nits: name the three wire-conflated NotFound reasons explicitly instead of the ambiguous "reasons below", and scope the "finer-grained than the wire" claim to the three NotFound cases (the other three reasons map 1:1 to distinct wire errors). Comment-only; no behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Closes #876. Every paid-delivery reject branch in
serve_stream(crates/node/src/handlers/client.rs) refused with a signedStreamResponse { ok: false }and atracing::warn!but incremented no metric — so a refused stream was invisible to operator dashboards. An operator couldn't alert on "rate of refused streams" or distinguish a misconfigured client from an abuse campaign (e.g. a peer hammering with unknown-channel requests). This is the operator-side counterpart to the #848/#875 silent-failure work: #875 stopped serving free bytes on a bad channel, but the refusal itself still produced zero queryable signal.What changed
Added six per-reason reject counters. The
iroh_metricsbackend has no runtime labels, so oneCounterper reason matches the establisheddispatch_rejected_*/dht_rate_limit_rejected_*convention:A private
ServeRejectReasonenum is threaded into the centralrespond_errorhelper, which increments the matching counter at a single site (exhaustivematch, no wildcard — a new variant is compiler-forced to add a counter). The enum is the single source of truth:ServeRejectReason::wire_error()derives the signedStreamError, so the three branches that deliberately collapse to the wireNotFound(to avoid leaking channel existence) stay wire-indistinguishable while remaining separately countable server-side. Passing only the reason makes an inconsistent error/reason pairing unrepresentable at the call sites.The metric is bumped before the network write, so a refusal is counted even if the client has already disconnected and the write fails — the counter measures the refusal decision, not its successful delivery.
Tests
metrics.rs): all six counters start at zero on a fresh registry and each method bumps exactly its own counter.client_loopback.rs): five tests assert the correct counter advances on a real refusal —evicted_since_probe,cache_miss,blob_too_large,unknown_channel,owner_mismatch. This deliberately covers all three wire-conflatedNotFoundreasons, where a mis-wired call site would otherwise pass every existing test (identical wire behavior). Added aspawn_handler_server_with_metricshelper; the oldspawn_handler_serverdelegates to it, so no other call sites churned.Out of scope / follow-ups
InternalErrorhas unit coverage but no end-to-end wiring test — its three sites need a faulting-cache test double not in the loopback harness. Low risk given the compiler-enforcedwire_errormapping and 5/6 wiring coverage.client.rs:682) is a load-shed reset (not a signedok:falseresponse) with no counter — a different mechanism, pre-existing, outside this issue's signed-refusal scope. Candidate for its own issue.Verification
🤖 Generated with Claude Code