Skip to content

feat(client-pull,node): byte-progress throughput-floor stall detection (#1797) - #1889

Merged
thiras merged 3 commits into
mainfrom
claude/byte-progress-stall-detection-97b2f9
Sep 1, 2026
Merged

thiras merged 3 commits into
mainfrom
claude/byte-progress-stall-detection-97b2f9

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #1797.

What

Replaces whole-frame inactivity stall detection with a byte-level windowed throughput floor across both client-pull requester paths (node-to-node miss pull and CLI fetch). After #1796 made ChunkData frames sender's-choice, the old detector's resolution was one frame — too coarse: it false-tripped honest slow links on large frames and missed a slow-drip wedge.

How

  • crates/client-pull/src/progress.rs (new): ProgressReader wraps the QUIC RecvStream as an AsyncRead, counting bytes sub-frame into an atomic (frame-size-independent). ThroughputFloor aborts when bytes over a trailing window W fall below F·W (≥1 byte when F=0 ⇒ idle detection). pause/resume exclude a self-inflicted credit-window payment pause.
  • Three composed stages: open (time), first-byte (time budget = W), steady-state (throughput floor). The cumulative == 0 split selects PullTimeout (our own blob-size-dependent budget) vs PullStalled.
  • Non-attributable: classify_pull_failure's Stalled arm no longer records Outcome::Unreachable; it routes like OurDeadline (meter + suppress (peer, hash), no EWMA). PullStalled/PullTimeout stay distinct metrics.
  • Config: node_pull_stall_timeout_sec → node_pull_stall_window_sec (default 20) + new node_pull_min_throughput_bps (default 4096); CLI gains --min-throughput-bps. PullDeadlines::{new,capped} take a floor_bps arg; cap invariant is now hard_cap > open + window.
  • ADRs: ADR 005 §Retry behavior (items 4–5) and §Non-empty chunk, and ADR 008, rewritten to the byte-progress primitive and the non-attribution rule.

Notes

  • Two corrections to the issue's premises: frames are effectively capped at 1 MiB (payment-boundary rule), not 16 MiB; the probe measures RTT only (no bandwidth estimate), so the floor is a fixed configurable constant rather than probe-derived.
  • The read future is pinned and polled across sampler ticks rather than recreated — read_client_message is not cancellation-safe (read_frame uses read_exact), so dropping it mid-frame would desynchronise framing. This was a real bug caught by the node integration suite.
  • No wire change.

Testing

  • New unit tests: ProgressReader sub-frame counting; ThroughputFloor (healthy / slow-drip / full-wedge / payment-pause / F=0).
  • Updated node integration tests: mid-stream silence is classified as a stall but not scored (non-attributable); first-byte silence is PullTimeout.
  • Full suite: 3068 passed, 0 failed. cargo fmt --check, cargo clippy --all-targets, and the anvil-e2e compile gate all clean.

🤖 Generated with Claude Code

alpergundogdu and others added 2 commits August 31, 2026 17:47
#1797)

Replace whole-frame inactivity stall detection with a byte-level windowed
throughput floor across both requester paths. Bytes are counted off the QUIC
stream sub-frame via a ProgressReader; a ThroughputFloor aborts a pull when the
bytes across a trailing window fall below floor_bps * window (one byte when
floor_bps == 0). Frame-size-independent, so a large frame arriving slowly is not
mistaken for a stall, and a slow drip below the floor is caught.

The abort is requester-local policy and non-attributable: the node path routes a
stall like OurDeadline (suppress the (peer, hash) pair, no EWMA), removing the
Stalled -> Outcome::Unreachable scoring. PullStalled and PullTimeout stay distinct
metrics. Config gains node_pull_stall_window_sec (20) and
node_pull_min_throughput_bps (4096); the CLI gains --min-throughput-bps.

The read future is pinned and polled across sampler ticks rather than recreated:
read_client_message is not cancellation-safe, so dropping it mid-frame would lose
read bytes and desynchronise the stream.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…DR 005/008, #1797)

ADR 005 §Retry behavior states the byte-progress primitive: a time budget to
first byte, then a minimum-throughput floor over a trailing window for steady
state, both requester-local and non-attributable, with a credit-window payment
pause excluded. §Non-empty chunk rebases its rationale on byte throughput. ADR 008
states that a throughput-floor / inactivity abort produces no outcome and never
updates the EWMA.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 31, 2026 17: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 updates requester-side stall detection for paid pulls (both node-to-node cache-miss pulls and CLI fetch) from whole-frame inactivity to a byte-level, windowed throughput-floor model, and adjusts reputation handling so throughput-floor aborts remain non-attributable.

Changes:

  • Introduces sub-frame byte counting (ProgressReader) and a windowed throughput floor (ThroughputFloor) to classify stalls vs timeouts without frame-size coupling.
  • Renames node pull stall config from an inactivity timeout to a throughput window (node_pull_stall_window_sec) and adds a minimum throughput floor (node_pull_min_throughput_bps), with CLI support (--min-throughput-bps).
  • Updates node classification/metrics and ADRs to reflect the new “non-attributable stall” rule (no EWMA update / no Outcome::Unreachable).

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/protocol/src/client.rs Updates protocol docs around the non-empty ChunkData invariant in light of byte-progress tracking.
crates/node/tests/sighup_signal.rs Updates resolved-config fixtures for renamed stall window + new throughput floor field.
crates/node/tests/node_origin_pull.rs Updates integration tests/fixtures and renames tests to reflect non-attributable mid-stream stalls.
crates/node/tests/anvil_bringup_shutdown_e2e.rs Updates resolved-config fixtures for renamed stall window + new throughput floor field.
crates/node/src/selection.rs Updates outer deadline derivation docs to refer to throughput-floor window.
crates/node/src/runtime/reload.rs Threads new cache config fields through reload/default config and restart-required detection.
crates/node/src/runtime/mod.rs Wires new stall_window + min_throughput_bps into NodeOriginConfig and deadline derivation.
crates/node/src/node_origin/mod.rs Switches node-origin stall logic to throughput-floor semantics and makes stalls non-attributable (suppression only).
crates/node/src/metrics.rs Updates metric docs for stall vs timeout semantics and the non-attribution rule.
crates/e2e/src/client.rs Updates PullDeadlines::new call sites to include floor_bps.
crates/common/src/config/types.rs Renames config knob and documents new throughput floor configuration.
crates/common/src/config/resolved.rs Adds resolved fields for stall window + minimum throughput floor.
crates/common/src/config/mod.rs Adds defaults and resolver validation for stall window + throughput floor; updates docs/tests.
crates/common/src/cli/fetch.rs Extends CLI args with --min-throughput-bps and updates validation/docs for window+floor behavior.
crates/client-pull/src/scheduler.rs Adjusts module docs (minor refactor of intra-doc links).
crates/client-pull/src/progress.rs New: implements ProgressReader and ThroughputFloor with unit tests.
crates/client-pull/src/lib.rs Integrates byte-progress throughput-floor detection into buffered + progressive pull receive loops and updates deadline APIs.
crates/cli/tests/config_validate.rs Updates config summary expectations for new window + throughput floor reporting.
crates/cli/src/commands/fetch.rs Threads CLI throughput floor into PullDeadlines::capped construction.
crates/cli/src/commands/config.rs Updates config summary output and default config template for new stall window + throughput floor.
crates/cli/src/commands/bundle_pull.rs Threads CLI throughput floor into bundle pull’s PullDeadlines::capped construction.
adr/008-reputation.md Documents non-attributable handling for throughput-floor/inactivity aborts.
adr/005-protocol.md Updates retry behavior + non-empty chunk rationale for byte-progress throughput-floor stall detection.
Suppressed comments (1)

crates/client-pull/src/lib.rs:2639

  • Same starvation issue as the buffered path: biased; makes the read arm always win when both arms are ready, so sampler.tick() may never be consumed and the throughput floor may never be evaluated.
            tokio::select! {
                biased;
                r = &mut read => return r,
                _ = sampler.tick() => {

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

Comment on lines +2143 to +2146
tokio::select! {
biased;
r = &mut read => break r?,
_ = sampler.tick() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not reachable, I think — the two arms are not independent here.

The read arm becomes ready only when a whole frame has come off the wire, and those bytes are already in the counter by then (ProgressReader tallies inside poll_read, sub-frame). So a tick lost to biased is always a tick where byte progress just happened.

Sustained starvation would need every poll of the read arm to complete immediately, i.e. a complete frame already buffered each time we look. On frame completion the loop breaks out, processes the chunk, and re-enters with a fresh read future that is polled first — it returns Pending unless the sender has yet another whole frame queued. Keeping that up means the sender is outrunning this loop; with frames carrying >= 1 byte (#1088) and the per-chunk work being a memcpy plus interval-boundary metering, that rate is orders of magnitude above the 4096 B/s default floor. The sub-floor case Copilot describes (slow drip) is exactly the case where the read arm is Pending and the tick wins.

The reverse hazard is the one that bit: dropping the read future per tick desynchronises framing, since read_frame uses read_exact. That is why the future is pinned.

I have recorded the argument in the comment at both select sites rather than changing the code.

Comment on lines 2074 to 2079
/// the decoder, not here). Enforces `ChunkData`'s non-empty FLOOR (#1088) — an
/// oversized frame is refused earlier still, by the framing layer's
/// `MAX_MESSAGE_SIZE`, before it allocates — plus the `cumulative <= expected_wire_bytes` overrun guard
/// (ADR 005 §`cdn/client/v1`). The floor is the load-bearing one: it is what lets the
/// inactivity deadline below rest on frame arrival, since an empty frame would refresh
/// the clock while advancing nothing.
/// (ADR 005 §`cdn/client/v1`). The non-empty floor keeps every frame a unit of progress,
/// so a run of empty frames cannot drive this loop without advancing the byte counter.
///

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct that it was imprecise. The ProgressReader counter tallies raw stream bytes including frame envelopes, so an empty ChunkData would move it. Reworded to the accurate invariant: the non-empty floor ties every frame to payload, so a run of empty frames cannot drive the loop while cumulative and the voucher accounting stand still.

Comment thread crates/client-pull/src/lib.rs Outdated
Comment on lines +47 to +50
/// Client-only multi-source fetch scheduler (spec §5.3): fan a request across
/// several paid sources over one shared store, with bao-aligned segmentation
/// and tail-stealing. Drives [`driver::fill_gap`] per range.
mod progress;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — that doc was a copy of the scheduler's. It now describes ProgressReader and ThroughputFloor.

Comment thread crates/protocol/src/client.rs Outdated
Comment on lines +606 to +609
/// which invariant they had just removed — while the requester's byte-progress stall
/// detector depends on it (#1797): an empty frame advances neither the byte counter nor the
/// voucher accounting, so a run of them would drive the receive loop without making progress.
/// That is too much weight for a convention, so the type carries the floor instead: the field

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same imprecision, same fix. The doc now says an empty frame advances neither the cumulative delivered bytes nor the voucher accounting, and states explicitly that the throughput floor counts wire bytes (envelopes included) — so it is this non-empty floor, not that counter, that keeps wire progress equal to content progress. The bytes field doc is reworded the same way.

@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.60% (was 82.56%, ▲ +0.04%) — 70754/85662 lines

File Coverage Lines Δ
crates/cli/src/commands/bundle_pull.rs 52.12% 553/1061 ▼ 0.05%
crates/cli/src/commands/config.rs 87.08% 795/913 ▲ +0.07%
crates/cli/src/commands/fetch.rs 32.65% 522/1599 ▲ +0.02%
crates/client-pull/src/lib.rs 89.85% 1744/1941 ▲ +0.34%
crates/client-pull/src/progress.rs 98.71% 153/155 new
crates/client-pull/src/scheduler.rs 92.66% 1325/1430 ● 0.00%
crates/common/src/cli/fetch.rs 96.22% 178/185 ▼ 1.59%
crates/common/src/config/mod.rs 97.10% 6986/7195 ● 0.00%
crates/common/src/config/resolved.rs 100.00% 42/42 ● 0.00%
crates/e2e/src/client.rs 0.00% 0/455 ● 0.00%
crates/node/src/metrics.rs 94.64% 882/932 ● 0.00%
crates/node/src/node_origin/mod.rs 92.93% 972/1046 ▲ +0.03%
crates/node/src/runtime/mod.rs 47.43% 1162/2450 ▲ +0.02%
crates/node/src/runtime/reload.rs 96.58% 1553/1608 ▲ +0.01%
crates/node/src/selection.rs 97.07% 397/409 ● 0.00%
crates/protocol/src/client.rs 97.52% 1063/1090 ● 0.00%
History
Commit Total Δ vs base
f337798 82.45% ▲ +0.05%
21910bc (HEAD) 82.60% ▲ +0.04%

…recisely (#1797)

The throughput floor counts raw stream bytes, envelopes included, so an
empty ChunkData would move that counter. Describe what the non-empty
floor actually guarantees: every frame carries payload, so cumulative
delivered bytes and voucher accounting advance with the wire. Also
replace the progress module doc, which was a copy of the scheduler's,
and record why `biased` cannot starve the sampler tick.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_014Chu2v9AUcfr36pUVRLwwx
@thiras
thiras merged commit 2ccd03a into main Sep 1, 2026
25 checks passed
@thiras
thiras deleted the claude/byte-progress-stall-detection-97b2f9 branch September 1, 2026 00:49
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.

design: byte-progress stall detection — whole-frame inactivity deadlines are too coarse

3 participants