Skip to content

fix(node): keep the post-top-up delivery leg in the delivery-speed score - #1604

Merged
alpergundogdu merged 1 commit into
mainfrom
claude/quizzical-davinci-fb0b4d
Aug 5, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
claude/quizzical-davinci-fb0b4d

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1602.

Problem

On the node-to-node buyer leg (crates/node/src/node_origin/resume.rs), pull_blob captured leg_started = state.budgets.awaiting_topup_settle.then(Instant::now) at the loop top, then unconditionally added started.elapsed() to paid_wait after stream_leg returned — before the success check.

But stream_leg clears awaiting_topup_settle via note_successful_open() internally: after the open, but before pull_to_sink streams the remainder of the blob. So on the completing (successful) leg, the whole pull_to_sink delivery time was folded into paid_wait, then subtracted from elapsed in pull_from_candidate, which feeds Outcome::Delivered { elapsed }.

The result: a slow upstream that served through a reactive top-up (#1530) scored as fast/instantaneous, corrupting the local per-peer delivery-speed EWMA (ADR 008) on any topped-up pull — and contradicting PulledBlob::paid_wait's own doc ("Blocking on a transaction says nothing about how fast the upstream serves").

Fix

Move the timing into stream_leg so it wraps only open_leg, not pull_to_sink:

  • The re-open round trip (dial, signed request, verified response) stays charged to paid_wait — success or failure — as pure funding cost. A failed one is a settle-wait probe; a successful one is the last probe before delivery resumes.
  • The pull_to_sink delivery stays in elapsed, where the delivery-speed score measures it.

The settle-sleep and topUp-receipt exclusions are unchanged — only the successful-delivery-leg misattribution is corrected.

Test

Adds a_slow_post_topup_delivery_scores_slow_not_instant, which pins the delivery speed for a topped-up pull instead of only asserting score(provider) > 0.5 (which an inflated score trivially passes). With alpha = 1.0 a single delivery reads straight off the score (score = 0.4·speed + 0.6); a throttled resume leg (served over 3s) caps an honest score at ~0.8, while the bug — excluding the transfer from elapsed — saturates speed and pins the score at ~1.0. The test fails on the pre-fix code and passes on the fix.

Verification

  • cargo build && cargo clippy -p decdn-node --tests — clean
  • cargo fmt -- --check — clean
  • cargo nextest run -p decdn-node resume unit tests (13) + top-up integration tests (14) — all pass
  • Confirmed the new test fails on the reverted (buggy) code and passes on the fix

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved timing accuracy for resumed transfers by excluding post-top-up content delivery from funding-wait measurements.
    • Ensured both successful and failed settlement checks are measured consistently.
  • Tests

    • Added coverage for slow resumed transfers after reactive top-ups.
    • Expanded top-up scenarios to support configurable delays and reputation settings.

`pull_blob` captured `leg_started` from `awaiting_topup_settle` at the loop
top, then charged the whole `stream_leg` to `paid_wait`. But `stream_leg`
clears the flag via `note_successful_open()` between the open and
`pull_to_sink`, so on the completing leg the entire remainder's transfer was
folded into `paid_wait` and subtracted out of `elapsed`. A slow upstream that
served through a reactive top-up (#1530) then scored as fast/instantaneous,
corrupting the local per-peer delivery-speed EWMA (ADR 008) — and
contradicting `PulledBlob::paid_wait`'s own doc.

Move the timing into `stream_leg` so it wraps only `open_leg`: the re-open
round trip (success or failure) stays charged to `paid_wait` as pure funding
cost, while the `pull_to_sink` delivery stays in `elapsed` where the score
measures it. Settle-sleep and topUp-receipt exclusions are unchanged.

Add an integration test that pins the delivery speed for a topped-up pull:
with `alpha = 1.0` a single delivery reads straight off the score, and a
throttled resume leg caps an honest score at ~0.8 — the bug pins it at ~1.0.
The existing tests only assert `score(provider) > 0.5`, which both pass.

Fixes #1602

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 5, 2026 09:39
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: f0b29984-699f-4b10-b4d7-7741236b88f8

📥 Commits

Reviewing files that changed from the base of the PR and between d3e13fc and 1cd6d3b.

📒 Files selected for processing (2)
  • crates/node/src/node_origin/resume.rs
  • crates/node/tests/node_origin_pull.rs

Walkthrough

The change moves settlement-wait timing into stream_leg, excluding resumed content transfer from paid_wait. Tests add configurable resumed-leg delays and verify that slow post-top-up delivery receives the correct provider score.

Changes

Resume timing correction

Layer / File(s) Summary
Separate settlement and streaming timing
crates/node/src/node_origin/resume.rs
pull_blob delegates timing to stream_leg. stream_leg records only open_leg settlement time before content transfer.
Cover delayed resumed delivery
crates/node/tests/node_origin_pull.rs
Deposit-capped fixtures accept resumed-leg delays and reputation settings. The regression test verifies successful slow delivery without corruption or reachability failures. Existing setups initialize the delay to zero.

Estimated code review effort: 3 (Moderate) | ~20 minutes


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 fixes node-to-node resume timing accounting so the post-top-up content delivery time contributes to the upstream’s delivery-speed reputation signal (ADR 008), instead of being mistakenly charged as local funding wait (paid_wait). This aligns PulledBlob::paid_wait with its documented intent and prevents topped-up pulls from artificially inflating per-peer delivery-speed EWMA.

Changes:

  • Move “paid-wait” timing from pull_blob into stream_leg, and scope it to only the open_leg round trip while awaiting_topup_settle is true.
  • Add a regression test that throttles the resumed delivery leg and asserts the provider score stays below an upper bound (catching the previous “instantaneous” mis-scoring).
  • Extend the deposit-capped upstream test server harness to optionally delay only the RESUME-leg chunk stream (not the open/response).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/node/src/node_origin/resume.rs Fixes timing attribution by charging only open_leg to paid_wait during settle-wait iterations, keeping resumed streaming in elapsed.
crates/node/tests/node_origin_pull.rs Adds a targeted regression test and harness support to slow the resumed chunk stream and validate delivery-speed scoring.

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

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Coverage report

Total: 80.48% (was 80.47%, ▲ +0.01%) — 57980/72044 lines

File Coverage Lines Δ
crates/node/src/node_origin/resume.rs 93.19% 520/558 ▲ +0.01%
History
Commit Total Δ vs base
1cd6d3b (HEAD) 80.48% ▲ +0.01%

@alpergundogdu
alpergundogdu merged commit d62c523 into main Aug 5, 2026
26 checks passed
@alpergundogdu
alpergundogdu deleted the claude/quizzical-davinci-fb0b4d branch August 5, 2026 10:00
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.

fix(node): reactive top-up delivery leg wrongly excluded from peer delivery-speed reputation

2 participants