Skip to content

fix(client,cli): rank peer-store latency by probe RTT only (#2196) - #2202

Merged
thiras merged 2 commits into
mainfrom
fix/2196-peer-store-probe-rtt-only
Sep 28, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/2196-peer-store-probe-rtt-only

Conversation

@thiras

@thiras thiras commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

What

The client peer store's latency_ms EWMA folded each stream open's time to first byte alongside the probe RTT. On a cache miss that time includes the serving node's own upstream work, so it measures the content's cache state, not the node's distance. After a bundle pull the EU nodes read 1–1.8 s against a 57–78 ms RTT, and the sole origin (bcl) ranked first on store_fast_path for the next 10 minutes (LATENCY_TTL_SECS).

  • Only probes feed latency_ms (issue option 1).
  • New PeerStore::record_open(node_id, rate_per_mb): sets the quoted rate and clears the failure stamp; folds no latency, stamps no freshness; no-op for an unknown peer.
  • record_first_open in decdn fetch is now the single path for the prelude scored closure and both multi-source lane sites; a failed peer-store write logs node_id and outcome at debug.
  • UpstreamPullHeader::ttfb_ms had no other reader and is removed from decdn-client (public API snapshot regenerated).
  • ADRs 037, 012 and 039 now state that only probe round trips feed the RTT map; CHANGELOG entry under Fixed.

Closes #2196

Reviewer notes

  • Why not QUIC path RTT from the stream's connection: probe RTT is measured dial → response (probe.rs), so it includes the handshake; the transport rtt() is one round trip. Mixing both in one EWMA reintroduces a unit bias.
  • Intended consequence: during continuous use the fast path expires LATENCY_TTL_SECS after the last probe, not the last stream, so the next fetch takes the identity-fresh re-probe tier (no registry read). That re-probe is what lets warm nearby caches win again.
  • Out of scope, worth a follow-up: spawn_harvest still drops its peer-store write results with let _ =; ADR 039:90 says per-lane outcomes are not persisted, but settle_drive persists a failure stamp; ADRs 037/012 cite a rtt_map.staleness_secs knob that does not exist (the TTL is the LATENCY_TTL_SECS constant).

Verification

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run -p decdn-client -p decdn-cli -p decdn-node: 2693 passed (origin_range_pull::mid_blob_open_behind_a_paying_owners_frontier_attaches flaked once, passed on retry; unrelated path)
  • cargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(peer_store_probeless)': passed
  • INSTA_UPDATE=always cargo nextest run -p decdn-client --features public-api-test: snapshot regenerated
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items
  • pre-commit run --all-files
  • User-visible change: CHANGELOG.md entry added
  • Design change: ADR 037, 012 and 039 updated
  • PR title uses an allowed type with a lowercase subject
  • New tests: record_open_files_rate_and_clears_failure_without_touching_latency, record_open_on_unknown_peer_is_a_noop, successive_samples_fold_by_ewma, stream_opens_do_not_rank_near_nodes_behind_the_origin, failed_first_open_suppresses_the_peer
  • Not run: live testnet check (bundle pull, then inspect ~/.decdn/client/peers/*.json)

🤖 Generated with Claude Code

The peer store's `latency_ms` EWMA folded every stream open's time to
first byte alongside the probe RTT. On a cache miss that time includes
the serving node's own upstream work, so after a bundle pull the nearby
EU nodes read 1-1.8 s against a 57-78 ms RTT and the sole origin ranked
first on the probe-less fast path for the next 10 minutes.

Only probes now feed `latency_ms`. A stream open goes through
`PeerStore::record_open`: it files the quoted rate and clears the
failure stamp, but folds no latency and stamps no freshness. Both
first-open sites in `decdn fetch` share `record_first_open`, which now
logs a failed peer-store write with the peer and outcome.
`UpstreamPullHeader::ttfb_ms` had no other reader and is removed.

ADRs 037, 012 and 039 state that only probe round trips feed the RTT
map.

Closes #2196

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 28, 2026 05:05
@thiras thiras self-assigned this Sep 28, 2026

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.

Copilot review overview

🟡 Changes recommended

Serialize or merge record_open updates to prevent stale writes, and correct the ADR TTL references.

Review effort: Lite
Findings: 1 High severity · 2 Low severity

Open (3)
What changed in this PR

Updates peer-store latency ranking to use probe RTT only, avoiding cold-cache stream latency from skewing peer selection.

Changes:

  • Adds record_open for stream price and failure bookkeeping.
  • Removes UpstreamPullHeader::ttfb_ms.
  • Updates fetch logic, tests, snapshots, changelog, and ADRs.
File Summary Review status
crates/​node/​src/​node_origin/​backend_source.rs Updates header construction. No final comment.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Regenerates the public API snapshot. No final comment.
crates/​client/​src/​streamer.rs Updates test headers. No final comment.
crates/​client/​src/​source.rs Updates scripted source headers. No final comment.
crates/​client/​src/​peer_store.rs Adds stream-open bookkeeping. Critical concurrency issue requires changes.
crates/​client/​src/​lib.rs Removes ttfb_ms. No final comment.
crates/​client/​src/​driver.rs Updates driver test headers. No final comment.
crates/​cli/​src/​commands/​fetch.rs Records stream-open outcomes. No final comment.
CHANGELOG.md Documents the ranking fix. No final comment.
adr/​039-multi-source-parallel-fetch.md Documents stream-open behavior. No final comment.
adr/​037-regional-proxy-warming.md Documents probe-only RTT ranking. Nit: references a nonexistent setting.
adr/​012-client.md Updates peer-store behavior. Nit: references a nonexistent setting.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/client/src/peer_store.rs Resolved
Comment thread adr/012-client.md Resolved
Comment thread adr/037-regional-proxy-warming.md Resolved
@github-code-quality

github-code-quality Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

The overall line coverage in commit e3ad1b1 in the fix/2196-peer-store-... branch remains at 86%, unchanged from commit 0cf9688 in the main branch.

Show a line coverage summary of the most impacted files.
File main 0cf9688 fix/2196-peer-store-... e3ad1b1 +/-
crates/incentiv...eth_identity.rs 99% 98% -1%
crates/protocol/src/framing.rs 97% 97% 0%
crates/client/src/scheduler.rs 95% 95% 0%
crates/cache/src/engine.rs 94% 94% 0%
crates/client/src/lib.rs 92% 92% 0%
crates/client/src/streamer.rs 91% 91% 0%
crates/node/src...ckend_source.rs 92% 92% 0%
crates/client/src/source.rs 93% 93% 0%
crates/cli/src/...mmands/fetch.rs 52% 53% +1%
crates/client/s...c/peer_store.rs 95% 96% +1%

Updated September 28, 2026 05:30 UTC

… ADRs

Each peer-store mutation reads a whole record and writes it back, so a
stream open racing the off-path probe harvest could write back a record
read before the probe sample landed, dropping the only latency input.
A process-wide lock now serializes upsert_identity, record_sample,
record_open, record_failure and prune_and_cap. A new test runs
concurrent samples and opens and checks no sample is lost (12/100
survived without the lock).

ADRs 037 and 012 named a `rtt_map.staleness_secs` knob that does not
exist; they now name the fixed `LATENCY_TTL_SECS` (600 s) and say a
stale entry is skipped by the fast path until a probe re-samples it,
not evicted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 2153388 into main Sep 28, 2026
30 checks passed
@thiras
thiras deleted the fix/2196-peer-store-probe-rtt-only branch September 28, 2026 05:33
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.

client: peer-store latency folds cold-miss TTFB, so the fast path ranks nearby nodes behind the origin

2 participants