Skip to content

fix(dash-spv): sample the serving rate while backlogged - #1564

Merged
ZocoLini merged 6 commits into
devfrom
fix/serving-rate-backlogged
Dec 2, 2026
Merged

ZocoLini merged 6 commits into
devfrom
fix/serving-rate-backlogged

Conversation

@xdustinface

@xdustinface xdustinface commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

A peer's serving rate, which routing reads first and underserving_peer compares, was sampled only while the peer was bound to its cap. A burst lifts the cap far above what the peer sustains afterwards, so a peer working through a backlog below that cap went unsampled until the cap decayed to the backlog. Meanwhile its serving rate kept the value from before, or stayed unmeasured.

The serving rate is now sampled whenever the peer serves all it can, the condition that already moves its served rate and cap. A peer at its cap is sampled as before. The docs that said "while bandwidth bound" are updated.

Split out of #1375, which keeps the routing half. The two changes are independent.

PR Hygiene · 3672672

  • Bots — coderabbitai skipped after its own rate limit
  • Self-review — posted; again after any push
  • Build green
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

A peer's serving rate, which routing reads first and `underserving_peer` compares, was sampled only while the peer was bound to its cap. A burst lifts the cap far above what the peer sustains afterwards, so a peer working through a backlog below that cap went unsampled until the cap decayed to the backlog. In a mainnet run a peer serving 2 to 3 MB/s that stalled kept a serving rate near 2.5 MB/s for over a minute this way.

The serving rate is now sampled whenever the peer serves all it can, the condition that already moves its served rate and cap. A peer at its cap is still sampled as before.
@manki-review

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

This pull request is a draft, so Manki does not review it automatically. Marking it ready for review starts automatic reviews. Until then, someone with write access to this repository can tick a box below: Review this draft reviews the current commit once, Deeper review does so with more effort, and Review every push reviews it now and again after each push.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 9 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9fe5ac1 and 3672672.

Files selected for processing: 2

  • dash-spv/src/network/manager.rs
  • dash-spv/src/network/peer.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

CI does not run on this PR while it is a draft. Someone with write access can start it here:

  • Run CI once on the current commit
  • Run CI on every push, starting now

Marking the PR ready for review also starts CI.

CI started for 397fc26: Continuous integration, Pre-commit Checks, Sanitizer.

@manki-review

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Review complete in 7m 12s

Planner (5s)
    fix · 39 lines · 2 agents
    judge effort: medium

Review (behavior · full): 7 findings
    ✅ Claude Opus 5.5 · high: 2 findings (1m 33s)
    ✅ GPT 6.2 Sol · high: 3 findings (3m 36s)
    ✅ Comparisons, claim checks and fix checks: 7 of 7 done, 2 findings (1m 16s)
    ✅ Second reads: 1 of 1 done (39s)

Judge (2m 12s)
    graded 7 findings: 3 kept · 1 dropped · 3 merged
    dropped, as the finders filed them: 1 suggestion
    refuter: 1 checked · 1 unsettled
    verdict reader: read the diff (33s)

Posted: 2 findings
    2 suggestions
    not finished checking: 1 possible problem

Review metadata

Config:

  • Models: reviewer=claude-opus-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner)
  • Team: Claude Opus 5.5 · high, GPT 6.2 Sol · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 9% (resets 2026-12-04 01:00 UTC)
  • ChatGPT subscription: weekly 10% (resets 2026-12-02 01:49 UTC)

Judge decisions:

  • Kept: "PeerFlow::tick and ByteLimiter::tick judge serving_all against different rates" (suggestion): "note. The mismatch is real. PeerFlow::tick at manager.rs:592 calls serving_all before limiter.tick updates rate at manager.rs:548. The limiter checks again at manager.rs:554 with the new rate. The old bound read only cap, which is unchanged at that point, so the old code had no mismatch. The effect is at most one tick at each start or end of a backlog, inside a 120-tick average (SERVING_SAMPLE_TICKS, sampled with alpha = 1/120). That cost is too small for anyone to notice. Returning the limiter's own decision from tick removes the mismatch."
  • Not finished: "A fast peer that is never backlogged may get a serving rate taken only from idle-to-busy ticks, which reads low" (warning): "warning, unconfirmed. The new second clause of serving_all at manager.rs:539 reads in_flight > rate * TARGET_QUEUE_SECS. After an idle stretch, rate has decayed toward 0. A request of at least MIN_CAP_BYTES then makes serving_all true during the round trip, before any bytes arrive. Line 599 samples the low limiter.rate on those ticks. underserving_peer and broker.rs:618 read that rate, so a fast peer could look slow and be swapped out. The PR causes this, since the old code sampled only bound peers. Whether real request patterns produce mostly such samples, and whether the base cap decay already gave the same samples, is not settled by the code shown. The worst outcome is swapping out a good peer while sync still completes, so the row is degraded.
    Refutation unsettled: The mechanism is in the code. After an idle stretch, a request of at least MIN_CAP_BYTES (688,000 bytes) makes the second clause of serving_all true while the rate is still near 0, and line 599 then samples that low rate. But the router fills every open peer up to its cap (broker.rs:332-359), so whenever there is plenty of work a fast peer is bound and sampled at its real rate. Whether real sync gives a fast peer mostly round-trip ticks, enough to push it below 25% of a slow peer, cannot be se... Rule checked: An exponential average sampled only on ticks where a gating condition holds reflects only those ticks; with serving_all true during an idle peer's round trip, the samples taken there use the decayed limiter.rate.
  • Premise "In real filter or block sync, a fast peer below its cap gets requests of at least MIN_CAP_BYTES after idle stretches, often enough that most of its serving_all ticks are round-trip ticks with got near 0." unsettled. The router sends each peer work until its in-flight bytes reach its cap, so during bulk sync a fast peer is bound and sampled at its real rate. Requests of at least 688,000 bytes arriving after idle stretches often enough to make up most of 120 serving ticks are not shown by any request pattern in the code.
  • Premise "On dev, the cap of such a peer did not already decay to the backlog and bind it, so the old bound check did not sample those same ticks." unsettled. On the base, PeerFlow sampled only when bound held, while the cap's decay toward 2*served ran only on serving_all ticks, at 12.5% of the excess per tick. Whether that decay brought the cap down to a request's size, so that the base also sampled those ticks, depends on how many such ticks occur, which the code does not fix.
  • Premise "This trigger happens in realistic use: when a fast peer below its cap gets large requests after idle periods and its rate average has decayed" unsettled. Nothing in the code read shows a sync stage that leaves a fast peer below its cap and then sends it 688 KB or more after an idle stretch, again and again. In bulk phases the router fills every peer's cap.
    Pair refutation unsettled: The PR admits below-cap samples that the base code skips, but the sync paths do not establish that a fast peer accumulates enough low, nonzero samples to fall below one quarter of another measured peer's rate. An exactly zero rate is excluded from eviction and falls back to the shorter-term rate in routing. Rule checked: A throughput average can understate a peer's serving rate if its sample gate admits ticks spent waiting for replies but excludes ticks when those replies arrive.
  • Premise "In real filter or block sync, a fast peer below its cap gets requests of at least MIN_CAP_BYTES after idle stretches, often enough that most of its serving_all ticks are round-trip ticks with got near 0." unsettled. Filter sync submits batches that can collectively exceed the minimum cap, but one filter batch or block starts below that threshold, and the code does not establish that qualifying below-cap ticks are mostly reply waits.
  • Premise "On dev, the cap of such a peer did not already decay to the backlog and bind it, so the old bound check did not sample those same ticks." unsettled. The base limiter does not decay an idle peer's cap, but it can decay the cap while qualifying work is outstanding, so whether the old bound-only sampler catches later ticks depends on how long that backlog persists and how far below the cap it starts.
  • Premise "This trigger happens in realistic use: when a fast peer below its cap gets large requests after idle periods and its rate average has decayed" unsettled. Sync can submit multiple filter batches at once and the ledger keeps their estimated costs outstanding until settlement, but the checked paths do not show that a previously idle fast peer gets enough of that work to cross the minimum while staying below its cap on a flow tick."
  • Dropped: "Both renamed slow-peer cases bypass production rate publication" (ignore): "ignore. In this test the PR only renames the function and changes an assert message. It did not add set_serving_rate at manager.rs:1964, which predates the change. The new test a_backlogged_peer_is_measured_below_its_cap covers the below-cap backlog. By its own comment the cap binds only after about 35 ticks, so with the old bound guard fewer than 120 ticks would be sampled and serving_rate() would return 0, failing the test. The rule is a requirement, but this PR does not break it."
  • Kept: "The backlog test duplicates the rate-to-tick helper" (suggestion): "note. The new loop at manager.rs:1979-1981 repeats the conversion and loop of Served::bulk at manager.rs:1920. The only difference is the in-flight argument. That is the near copy the AGENTS.md reuse rule forbids. It does no runtime harm."

Timing:

  • Parse: 4.8s
  • Review agents: 295.1s
  • Judge: 131.8s
  • Total: 431.7s

@manki-review manki-review Bot 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.

Approval held: this PR is a draft. Mark it ready for review, and Manki approves it if nothing else holds the approval. If the latest commit has no review yet, Manki reviews it first when automatic review runs on this PR. If nothing happens, as for a PR from a fork or while automatic review is off or paused, comment /manki check, and Manki approves or says what holds the approval.

✅ Approved. 2 suggestions, none of which block.

  • Check approval

What this does: A peer's serving speed was only measured while it was at its full byte allowance. A peer that slowed down after a burst could go unmeasured and was never swapped out.


What to test

The review model wrote these steps. Check what a step runs before you follow it.

Setup: Run the tests with the dashd environment loaded, for example with just dash-spv::test.

  1. Run cargo test -p dash-spv --lib a_backlogged_peer_is_measured_below_its_cap. Expect it to pass, with a serving rate between 100 KB/s and 500 KB/s.
  2. Run cargo test -p dash-spv --lib only_a_peer_serving_all_it_can_is_condemned. Expect the tip case to return None and the slow-peer case to return Some(1).
  3. Run the a_slow_peer_is_swapped_out_again_after and no_slow_peer_is_swapped_out_while_our_link_stalls tests. Expect swaps at the same times as before.
  4. Sync testnet with cargo run -p dash-spv --features cli --bin dash-spv -- --network testnet --data-dir <dir> and RUST_LOG=peer_speed=debug. Expect a peer that slows down mid-sync to be logged as serving below the best and to be swapped out.
  5. Edge case: at the chain tip with only small replies, expect no peer to be swapped out for being far away.

Checked and left out: 1 finding

Not finished checking · 1 possible problem

  • A fast peer that is never backlogged may get a serving rate taken only from idle-to-busy ticks, which reads low · dash-spv/src/network/manager.rs:596
    The mechanism is in the code. After an idle stretch, a request of at least MIN_CAP_BYTES (688,000 bytes) makes the second clause of serving_all true while the rate is still near 0, and line 599 then samples that low rate.

The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.

About this review
  • Reviewed 397fc26, round 1
  • 39 changed lines read in 7m 12s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 2.0M in (1.6M from cache) · 62k out · about $3.19 at API prices
  • Runner: self-hosted · started after 7s · peak memory 2.7 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/manager.rs Resolved
Comment thread dash-spv/src/network/manager.rs Resolved
@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.79%. Comparing base (9fe5ac1) to head (3672672).
⚠️ Report is 4 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1564   +/-   ##
=======================================
  Coverage   87.79%   87.79%           
=======================================
  Files         270      270           
  Lines       72494    72514   +20     
=======================================
+ Hits        63645    63667   +22     
+ Misses       8849     8847    -2     
Flag Coverage Δ
core 83.43% <ø> (ø)
rpc 83.43% <ø> (ø)
spv 95.32% <100.00%> (+0.01%) ⬆️
wallet 83.43% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/network/manager.rs 97.53% <100.00%> (+0.07%) ⬆️
dash-spv/src/network/peer.rs 94.29% <ø> (ø)

... and 1 file with indirect coverage changes

The backlog test repeated the rate to bytes conversion and the tick loop of `Served::bulk` only to hold a fixed backlog in flight. `Served::bulk` now takes a function from the current cap to the bytes in flight, and the existing callers pass the cap through.
`PeerFlow::tick` judged whether the peer served all it can before `ByteLimiter::tick` updated the rate that judgement reads, and the limiter judged it again after. On the tick a backlog starts or ends the two disagreed, so the serving rate averaged one tick fewer or more than the served rate and the cap.

`ByteLimiter::tick` now returns its own judgement with the cap, and a stall of our link counts as not serving all. `PeerFlow::tick` samples on exactly that.
@manki-review

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Review complete in 13m 14s

Planner (5s)
    fix · 73 lines · 2 agents
    judge effort: medium

Review (behavior · full): 3 findings
    ✅ Claude Opus 5.5 · high: 1 finding (1m 36s)
    ✅ GPT 6.2 Sol · high: 2 findings (3m 58s)
    ✅ Comparisons, claim checks and fix checks: 7 of 7 done (1m 41s)
    ✅ Second reads: 1 of 1 done (35s)

Judge (6m 58s)
    graded 3 findings: 2 kept · 0 dropped · 1 merged
    refuter: 1 checked · 1 unsettled
    origin checks: 1 checked
    verdict reader: read the diff (21s)

Posted: 1 finding
    1 suggestion
    not posted: 1 no proof

Review metadata

Config:

  • Models: reviewer=claude-opus-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner)
  • Team: Claude Opus 5.5 · high, GPT 6.2 Sol · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 10% (resets 2026-12-04 01:00 UTC)
  • ChatGPT subscription: weekly 10% (resets 2026-12-02 01:49 UTC)

Judge decisions:

  • Not listed, a check of the code could not confirm it: "Backlog samples are taken only while the 1 s rate is low, so a far peer's serving rate is biased down" (warning): "warning. Below the cap, serving_all at manager.rs:539 holds only when in_flight > self.rate * TARGET_QUEUE_SECS. Line 599 samples that same self.limiter.rate. After an idle spell, charge (costs.rs:205-217) raises in_flight at send time while rate is still near 0. The round-trip ticks therefore enter serving_rate as near-zero samples, while a bound peer is sampled on every tick. rate() in broker.rs:617 and underserving_peer (manager.rs:861) consume this value. The code shows the bias. Whether it grows large enough to misrank or swap a peer is not shown, so the consequence is held at degraded routing.
    Refutation unsettled: The bias is in the code. Below its cap, a peer is sampled at manager.rs:596-599 only when its rate is below in_flight / 2 (line 539), while a bound peer is sampled on every tick. Whether this pushes a real peer under 25% of the best one depends on the workload, and the limiter partly corrects it. Each backlog tick lowers 'served' and shrinks the cap toward its target (lines 557-567), so the peer soon becomes bound and is then sampled at its full rate. No caller or test in the code shows a sustai... Rule checked: An exponential average fed only on ticks that pass a filter on the same signal (the 1 s rate is below in_flight / 2) records only values under that threshold. So a peer sampled only through the backlog branch reports a rate under half its backlog, not its bandwidth.
  • Premise "With SERVING_SAMPLE_TICKS averaging and the round-trip ticks after an idle spell sampled at a near-zero limiter.rate, a far peer's serving_rate falls below SLOW_RATE_FRACTION of a bound peer with the same bandwidth, so underserving_peer picks it" unsettled. If a peer never becomes bound, each of its samples is under in_flight / 2 (line 539), so backlogs under half the best peer's rate would put it below SLOW_RATE_FRACTION (line 1072). But backlog ticks shrink its served rate and cap (lines 557-567) until it becomes bound and is sampled at full rate (line 538), and no code path shows the far peer staying in low-sampled backlogs for the 120-tick average (lines 598, 606).
    Pair refutation unsettled: The PR feeds the updated rate into the serving average on below-cap ticks only when that rate is less than half the bytes in flight. The filter pipeline can queue multiple batches, and the broker consumes the published average, but the checked paths do not establish a sustained sampling bias large enough to produce a wrong routing or swap decision. Rule checked: Selecting samples only when the measured rate is below a cutoff biases the average toward lower values.
  • Premise "With SERVING_SAMPLE_TICKS averaging and the round-trip ticks after an idle spell sampled at a near-zero limiter.rate, a far peer's serving_rate falls below SLOW_RATE_FRACTION of a bound peer with the same bandwidth, so underserving_peer picks it" unsettled. Starting from an already measured rate equal to a steady reference peer, six qualifying zero-rate ticks lower the estimate by only 4.9%; it would take at least 166 such samples with no intervening higher samples to cross the 25% cutoff, and no checked equal-bandwidth workload establishes that drop."
  • Kept: "The backlog regression bypasses the public network path" (suggestion): "note. The new test feeds fabricated in-flight counts to the private PeerFlow::tick through Served (manager.rs:1916, 1980) and reads flow.serving_rate() directly. This does not follow the AGENTS.md rule to test through the public API. The finding itself says the test fails when the gate is reverted, so it still guards the change. The gap is in how the test is built, not in what it catches."

Timing:

  • Parse: 10.1s
  • Review agents: 366.2s
  • Judge: 417.5s
  • Total: 793.8s

@manki-review manki-review Bot 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.

Approval held: this PR is a draft. Mark it ready for review, and Manki approves it if nothing else holds the approval. If the latest commit has no review yet, Manki reviews it first when automatic review runs on this PR. If nothing happens, as for a PR from a fork or while automatic review is off or paused, comment /manki check, and Manki approves or says what holds the approval.

✅ Approved. 1 suggestion, which doesn't block.

  • Check approval

What this does: The client measures how fast each peer serves in order to replace slow ones. Peers with a backlog below an inflated byte limit were never measured.


What to test

The review model wrote these steps. Check what a step runs before you follow it.

Setup: Run the CLI against testnet with filters enabled and peer_speed debug logging on, for example RUST_LOG=peer_speed=debug,dash_spv::network=debug.

  1. Sync filters from several peers for over a minute. Expect peer_speed lines with non-zero served values for busy peers.
  2. Throttle one peer's link, for example with a firewall rate limit, after it has run fast. Expect a debug line naming it as serving below the best peer's rate, followed by a supervisor swap line.
  3. Let sync reach the chain tip with small header replies only. Expect no peer to be reported as slow just for being far away.
  4. Cut the client's network for about 20 seconds during bulk filter sync. Expect no slow-peer verdicts or swaps during the outage, and expect caps to resume after it.

Checked and left out: 1 finding

Not proven, so not listed · 1 warning

  • Backlog samples are taken only while the 1 s rate is low, so a far peer's serving rate is biased down · dash-spv/src/network/manager.rs:596
    A check of the code could not confirm it.

The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.

About this review
  • Reviewed 5f8fd30, round 2
  • 73 changed lines read in 13m 14s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 2.4M in (1.8M from cache) · 51k out · about $3.24 at API prices
  • Runner: self-hosted · started after 18s · peak memory 1.9 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/manager.rs Resolved
`feed` takes the bytes each peer should have in flight as a function of its cap, and `feeders` connects peers without measuring them, so a test can drive a peer through the real flow controller with work below its cap.
The backlog regression drove private `PeerFlow::tick` with a made-up in-flight count. It now feeds a loopback peer through the running flow controller: a 2 tick burst at 20 MB/s lifts its cap to 5 MB over 768 KB in flight, then it serves that backlog at 100 KB/s, and the test reads the serving rate the controller publishes. With the old gate the rate is first published 27 ticks later, so the test fails on it.

`Served::bulk` loses the in-flight function it only took for the old test.
@manki-review

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Review complete in 8m 16s

Planner (4s)
    fix · 96 lines · 2 agents
    judge effort: medium

Review (behavior · full): 4 findings
    ✅ Claude Opus 5.5 · high: 1 finding (1m 52s)
    ✅ GPT 6.2 Sol · high: 3 findings (4m 0s)
    ✅ Comparisons, claim checks and fix checks: 7 of 7 done (1m 38s)
    ✅ Second reads: 1 of 1 done (21s)

Judge (3m 12s)
    graded 4 findings: 3 kept · 0 dropped · 1 merged
    refuter: 1 checked · 1 confirmed
    origin checks: 1 checked
    verdict reader: read the diff (48s)

Posted: 2 findings
    2 suggestions
    not posted: 1 no proof

Review metadata

Config:

  • Models: reviewer=claude-opus-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner)
  • Team: Claude Opus 5.5 · high, GPT 6.2 Sol · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 20% (resets 2026-12-04 01:00 UTC)
  • ChatGPT subscription: weekly 11% (resets 2026-12-02 01:49 UTC)

Judge decisions:

  • Not listed, a check of the code could not confirm it: "Backlog ticks pull a fast peer's serving rate down to its round-trip and think time" (warning): "warning. The backlog branch at manager.rs:539 holds only while self.rate * TARGET_QUEUE_SECS < in_flight. self.rate is updated from the current tick at manager.rs:549 before that test, and line 596 now feeds every such tick into serving_rate at line 599. So the sampler keeps the ticks where the rate is low and drops the ones where it is high. A peer that answers in bursts ends up with a serving_rate biased below what it delivers. underserving_peer at manager.rs:1072 and broker rate() at broker.rs:618 then rank or evict it on that figure. Sync still completes, since an evicted peer's requests are requeued, so the cost is slower routing and needless swaps: the degraded row. One premise is open: the value of MIN_CAP_BYTES is not shown.
    Refutation confirmed: The mechanism is in the code. rate is updated before the backlog test, every serving_all tick now feeds serving_rate, and in-flight bytes drop only when the whole reply has arrived. So a lone request costed at or above 688,000 bytes adds low-rate samples while the peer is still thinking. But the cost of a QRInfo reply adapts to the real reply sizes (costs.rs:141-148), and only the 1 MiB starting cost is known. Whether replies at the tip stay above the floor, and come often enough to pull servi... Rule checked: An average fed only by ticks chosen by a test on the value being averaged (in_flight > rate * 2) is biased toward the low values that pass the test.
  • Premise "MIN_CAP_BYTES is no larger than the backlog a single getqrinfo (costed 1 << 20) or a 768 KiB filter batch puts in flight, so such a request alone passes the backlog branch at manager.rs:539" confirmed. MIN_CAP_BYTES is INITIAL_CAP_BYTES = 2 * 8000 * 43 = 688,000 bytes. A QRInfo reply is first costed at 1 << 20 = 1,048,576 bytes and charged to in-flight in full, so one getqrinfo alone meets the in_flight >= MIN_CAP_BYTES floor. This holds until the adaptive cost learns smaller sizes.
    Pair refutation confirmed: The new sampler has that bias, but reaching the backlog floor once does not establish a persistent misranking: qualifying ticks can also lower the cap, changing which later ticks qualify. The tests cover small bursty replies below the floor and sustained slow service above it, not repeated below-cap bursts that drive a fast peer's published rate low enough to misroute work or trigger a swap. Rule checked: When an average admits below-cap samples only if the sampled rate is below a threshold, it can count waiting ticks and omit faster delivery ticks.
  • Premise "MIN_CAP_BYTES is no larger than the backlog a single getqrinfo (costed 1 << 20) or a 768 KiB filter batch puts in flight, so such a request alone passes the backlog branch at manager.rs:539" confirmed. The floor is 688,000 bytes, so either one QRInfo request at its 1 MiB bootstrap charge or 768 KiB in flight clears it; the backlog branch still requires the current rate to be less than half the in-flight byte count per second."
  • Kept: "The backlog test reads the rate after the cap binds again" (suggestion): "note. The finding itself grants that the test fails when the sampling gate is reverted. Its point is that the test asserts only the final rate at manager.rs:1994, after 140 ticks of cap decay, and never checks the cap at the same moment. So the doc comment's claim that the rate is measured while the cap is far above the backlog is not shown. This concerns test precision and comment accuracy, not a defect."
  • Kept: "The peer comparison test injects the rates it compares" (suggestion): "note. peer.set_serving_rate(s.flow.serving_rate()) at manager.rs:1975 is an unchanged context line. The base version of the test already copied the standalone flow's rate in by hand, and this PR only renames the test and drops the work closure. P1 already named this part. It is a matter of how the test is built, with no runtime damage."

Timing:

  • Parse: 6.5s
  • Review agents: 297.1s
  • Judge: 192.0s
  • Total: 495.6s

@manki-review manki-review Bot 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.

Approval held: this PR is a draft. Mark it ready for review, and Manki approves it if nothing else holds the approval. If the latest commit has no review yet, Manki reviews it first when automatic review runs on this PR. If nothing happens, as for a PR from a fork or while automatic review is off or paused, comment /manki check, and Manki approves or says what holds the approval.

✅ Approved. 1 suggestion, which doesn't block.

  • Check approval

What this does: A peer's speed used to be measured only while it sat at its in-flight cap. A peer whose cap stayed high after a fast burst could keep a slow backlog and never be measured or judged slow.


What to test

The review model wrote these steps. Check what a step runs before you follow it.

Setup: Run the client against testnet with filters enabled and peer_speed debug logging on, so the per-peer served and cap lines are visible.

  1. Sync from scratch with several peers. Expect every peer's cap to grow from the initial value and sync to complete.
  2. Watch the logs for a peer whose delivery drops sharply after a fast start. Expect a serving at ... vs best ... debug line for it while its cap is still above its in-flight bytes.
  3. Keep syncing after that line. Expect swapped out slow for that peer no sooner than the 60 s swap cooldown allows.
  4. Cut the host's network for about 20 s mid-sync, then restore it. Expect no swapped out slow line caused by the outage, and sync to resume.
  5. Let sync reach the tip and stay idle for a few minutes. Expect no peer to be flagged slow from small tip replies.

Checked and left out: 1 finding

Not proven, so not listed · 1 warning

The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.

About this review
  • Reviewed bfeaadd, round 3
  • 96 changed lines read in 8m 16s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 2.7M in (2.1M from cache) · 59k out · about $3.51 at API prices
  • Runner: self-hosted · started after 9s · peak memory 2.6 GiB of 30.0 GiB
  • How Manki reviews

Comment thread dash-spv/src/network/manager.rs Resolved
The backlog test only read the rate after 120 qualifying ticks, when the cap had already decayed to the outstanding work. It now measures a peer first, lifts its cap with a burst and slows it down, then stops at the first tick its published rate moves and asserts the cap is still above its bytes in flight at that tick. With the fix that tick comes 9 ticks into the slowdown with a 6.7 MB cap over 2 MB in flight. With the old gate it comes only after the cap has fallen to 1.8 MB, so the test fails on it.

`measured_peers` takes back the connecting step, since no test connects peers without measuring them now.
@manki-review

manki-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

✅ Review complete in 6m 49s

Planner (5s)
    fix · 92 lines · 2 agents
    judge effort: high

Review (behavior · full): 2 findings
    ✅ Claude Opus 5.5 · high: 0 findings (1m 47s)
    ✅ GPT 6.2 Sol · high: 2 findings (2m 41s)
    ✅ Comparisons, claim checks and fix checks: 7 of 7 done (1m 9s)

Judge (3m 24s)
    graded 2 findings: 2 kept · 0 dropped
    refuter: 1 checked · 1 confirmed
    origin checks: 1 checked
    verdict reader: read the diff (36s)

Posted: 0 findings
    not posted: 1 on code an earlier round reviewed · 1 no proof

Review metadata

Config:

  • Models: reviewer=claude-opus-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner)
  • Team: Claude Opus 5.5 · high, GPT 6.2 Sol · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 24% (resets 2026-12-04 01:00 UTC)
  • ChatGPT subscription: weekly 12% (resets 2026-12-02 01:49 UTC)

Judge decisions:

  • Not listed, a check of the code could not confirm it: "Below-cap sampling counts reply waits but can skip the replies" (warning): "warning. The PR changes PeerFlow::tick at dash-spv/src/network/manager.rs:593-599 to sample whenever serving_all is true. That includes the backlog branch at manager.rs:539, which only needs in_flight >= MIN_CAP_BYTES and in_flight > rate * TARGET_QUEUE_SECS. After an idle period the rate EMA is near zero. A single GetQRInfo is charged 1 << 20 bytes (costs.rs:31, costs.rs:72), so the ticks spent waiting for the reply qualify, and each one pulls serving_rate toward the near-zero limiter.rate with weight 1/120. When the reply lands, release at costs.rs:255-256 clears the charge, so that tick and the ones after it have in_flight 0 and are not sampled. The wait gets counted but the bytes never do. link_silent (manager.rs:1051) needs two owing peers, so one waiting peer is not treated as a link stall. The published rate drifts down while real throughput is unchanged, and underserving_peer (manager.rs:1072) can then swap out a peer that serves well. The sync still completes, so the result is a needless peer swap and requeue: the degraded row. The doubt is whether MIN_CAP_BYTES lets a single 1 MiB charge pass the backlog check, since the constant is not shown.
    Refutation confirmed: The mechanism is real. After an idle period, one GetQRInfo charged at 1 MiB passes serving_all's backlog branch, because MIN_CAP_BYTES is 688,000 and the rate is near zero. Each wait tick then pulls serving_rate toward zero with weight 1/120. However, the claim that the reply is skipped is only partly true. CountingReader adds bytes as they are read from the socket, while the charge is released only when the whole message settles. So ticks during a multi-tick transfer are still sampled, and only... Rule checked: An EMA sampled only on ticks that pass a gate is biased when the gate opens on ticks where nothing arrives but closes before the arrival is fully averaged in.
  • Premise "ByteLimiter::serving_all at dash-spv/src/network/manager.rs:539 returns true on a tick where the only in-flight request is one GetQRInfo charged 1 << 20 bytes and limiter.rate * TARGET_QUEUE_SECS is below that charge, because MIN_CAP_BYTES is at most 1 << 20" confirmed. MIN_CAP_BYTES equals INITIAL_CAP_BYTES, which is 2 * 8000 * 43 = 688,000 and so below 1 << 20. The QrInfo estimate starts at 1 << 20 and one GetQRInfo charges exactly one QrInfo reply. With an idle rate below 512 KB/s, the condition in_flight >= MIN_CAP_BYTES && in_flight > rate * 2.0 holds.
  • Premise "This trigger happens in realistic use: when a peer that has been idle is asked for a GetQRInfo (or another reply estimated at MIN_CAP_BYTES or more) and takes several ticks to answer" confirmed. On its code part this holds. The masternode sync sends GetQRInfo at the tip on start and on each rotation cycle, re-firing on new blocks inside the mining window. The charge stays in flight until the full reply settles, so each tick the peer spends preparing it is sampled. How long a real peer takes to answer is network behaviour that no code here shows.
    Pair refutation confirmed: The PR makes the sampling asymmetry possible: a quiet tick can lower the published rate, while a tick that sees the reply after its charge clears does not update that rate. The example crosses the threshold mathematically, but the code does not establish that this small drop causes a false replacement in normal use. Rule checked: A throughput sampler that checks the current request balance can count ticks spent waiting but skip the tick that delivered the reply if the balance has already been cleared.
  • Premise "ByteLimiter::serving_all at dash-spv/src/network/manager.rs:539 returns true on a tick where the only in-flight request is one GetQRInfo charged 1 << 20 bytes and limiter.rate * TARGET_QUEUE_SECS is below that charge, because MIN_CAP_BYTES is at most 1 << 20" confirmed. The minimum is 688,000 bytes, so a single 1,048,576-byte charge satisfies the backlog branch when the tick's updated rate times two seconds is below that charge.
  • Premise "This trigger happens in realistic use: when a peer that has been idle is asked for a GetQRInfo (or another reply estimated at MIN_CAP_BYTES or more) and takes several ticks to answer" confirmed. Normal tip sync can dispatch a single GetQRInfo with no earlier masternode request pending, the router can select an idle peer, and the charge stays outstanding across flow ticks if the reply has not arrived."
  • Not listed, on code an earlier round reviewed: "The renamed slow-peer test does not exercise the new sampling path" (suggestion): "note. This PR only renames only_a_peer_serving_all_it_can_is_condemned and rewords its comments. The set_serving_rate injection at manager.rs:1969 and the cap-bound and latency phases are unchanged lines. That injection was already raised in the previous round and settled with the author. So this PR does not break the AGENTS.md rule, which applies to what the change adds. The new below-cap gate at manager.rs:596 is covered elsewhere: a_backlogged_peer_is_measured_below_its_cap (manager.rs:1980-1996) drives a loopback peer through the running flow controller. It asserts that the rate follows the slowdown while cap > in_flight, so reverting the gate to the cap-bound check fails that test. What is left is a missing case for a below-cap wait that should not lower the rate, which is missing coverage: improvement."

Timing:

  • Parse: 6.7s
  • Review agents: 198.2s
  • Judge: 203.7s
  • Total: 408.6s

Last reviewed 3672672 · head 3672672 · up to date

  • Pause automatic reviews
  • Review again
  • Deeper review
  • Review this draft
  • Review every push

@manki-review manki-review Bot 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.

Approval held: this PR is a draft. Mark it ready for review, and Manki approves it if nothing else holds the approval. If the latest commit has no review yet, Manki reviews it first when automatic review runs on this PR. If nothing happens, as for a PR from a fork or while automatic review is off or paused, comment /manki check, and Manki approves or says what holds the approval.

✅ Approved.

  • Check approval

What this does: The client measures how fast each peer serves so it can replace slow ones. A peer that slowed down after a burst kept its old measured speed for a while.


What to test

The review model wrote these steps. Check what a step runs before you follow it.

Setup: Run the CLI against testnet with filters enabled, and with peer_speed debug logging turned on.

  1. Sync from scratch with several peers. Expect peer_speed lines whose served and cap values settle per peer, and sync that completes.
  2. Throttle one peer's connection mid-sync, for example with tc on its address. Expect its measured rate to drop within seconds, and a log line saying a replacement is worth probing for.
  3. Let sync reach the chain tip and idle for several minutes. Expect no peer to be flagged as slow from small header or inventory replies alone.
  4. Cut the client's network for about 30 seconds during filter sync, then restore it. Expect no swap and no rate drop caused by the outage, and sync to resume.

Checked and left out: 1 finding

Not proven, so not listed · 1 warning

The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.

About this review
  • Reviewed 3672672, round 4
  • 92 changed lines read in 6m 49s
  • Found by claude-opus-5-5 and gpt-6.2-sol, judged by claude-opus-5-5
  • Tokens: 2.4M in (1.8M from cache) · 54k out · about $3.35 at API prices
  • Runner: self-hosted · started after 25s · peak memory 2.7 GiB of 30.0 GiB
  • How Manki reviews

@xdustinface
xdustinface marked this pull request as ready for review December 2, 2026 00:40
@xdustinface

Copy link
Copy Markdown
Collaborator Author

/self-reviewed

@manki-review manki-review Bot 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.

✅ Approved. All blocking threads are resolved.

@github-actions github-actions Bot added the bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Policy satisfied — this can merge.
Full checklist in the description.

@ZocoLini
ZocoLini merged commit f340b09 into dev Dec 2, 2026
53 checks passed
@ZocoLini
ZocoLini deleted the fix/serving-rate-backlogged branch December 2, 2026 17:55
manki-review Bot added a commit to manki-review/review-memory that referenced this pull request Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-review-skipped A required review bot did not report; it was skipped by the window or by a person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants