Skip to content

fix(client): take a pinned pull's size from a probe, not a dropped stream - #2634

Merged
thiras merged 1 commit into
mainfrom
fix/2619-pinned-size-probe
Oct 26, 2026
Merged

thiras merged 1 commit into
mainfrom
fix/2619-pinned-size-probe

Conversation

@thiras

@thiras thiras commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

What

A fetch pinned with --node-id and no known size read its first size claim from the header of a whole-blob paid open (LaneSources::open_for_header), then dropped the stream. Before the client's stop arrived, the node wrote up to a credit window into it (about 1 MiB, 2 MiB with banked lane credit) and counted it in decdn_bytes_served_total. #2239 introduced this when it removed the client's PrimedSource adoption from #2063.

Measured. The issue reported 2.3×; in the gateway_public e2e I measured 1.36×: the node wrote 36,379,334 bytes for 26,859,715 wire bytes of pulls. decdn_serve_stream_client_declined_total rose by 8, one per pull including the manifest, and the node's request log shows the (0, 0) opens. The rest is proof overhead (about 0.4%) and range padding.

Changes

  • A known size is the first claim and needs no probe. ProbeOpts::known_size carries a manifest entry size, which the gateway passes from its size_cap. A decdn get bundle entry uses its manifest size.
  • With no known size, probe_pinned probes the pinned node once on cdn/probe/v1: 2 s timeout, no backoff on a shed probe, no wait for a direct path (probe_answer_once). It takes the reported size as the hint. A failed, unverifiable, non-holder or sizeless answer falls back to the header open, and the node stays the fetch's only holder.
  • The bundle engine probes a pinned node for the manifest and for entries without a manifest size. A pinned rediscovery probes nothing, because only the first claim reads the hint.
  • pinned_target moves from quote.rs to targets.rs so both use it.
  • Docs: decdn_bytes_served_total is the bao wire bytes the node writes, the unit payment uses (ADR 038 § Payment metering), including frames a requester never pays for. No new series. ADR 039, the gateway appendix and the CHANGELOG are updated to match.

Closes #2619

Follow-ups: #2632 (a gateway re-probes for a bare hash's size on every request) and #2633 (the peer-store fast path still uses the header open). #2629 is a flaky test that also fails on main.

Reviewer notes

  • Start with probe_pinned, resolve_target_node and probed_size_hint in crates/client/src/targets.rs. Then read resolve_entry_targets in bundle/engine.rs and discover in lane_sources.rs.
  • A probe answer gives an unsigned size hint, the same trust as on the discovery path. ADR 039's grow/shrink rule and each leg's signed size still govern. A probe that fails or is shed costs only the old header open.
  • Not changed on purpose: the peer-store fast path (client: the peer-store fast path still takes its first size claim from a stream it drops unread #2633), the bundle engine's use of a known manifest size, and decdn quote.
  • targets is #[doc(hidden)], so the new ProbeOpts field leaves the decdn-client public-API snapshot unchanged; public_api passes.

Verification

  • pre-commit run --all-files: passed.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: passed. CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items: passed.
  • cargo nextest run --workspace: 5850 passed. One flaky test passed on retry: decdn-node::client_loopback a_closing_pool_is_unfunded_to_its_lane_and_not_found_to_anyone_else. It covers pool closing and doesn't touch the size claim.
  • The 12 anvil e2e binaries that pin --node-id (23 tests), with --retries 0: all passed.
  • New gateway_public check (served = pulls' wire bytes, within 16 KiB): failed before the fix (36,379,334 vs 26,859,715) and passes after; measured overhead 384 B. New cli_bundle_pull_pool_id check: fails with the engine change reverted (2,631,838 vs 1,315,919) and passes with it.
  • New unit tests, each mutation-checked. a_pinned_node_that_sheds_its_probe_stays_the_holder_with_no_hint fails with the retrying probe swapped in (4 probes vs 1). a_pinned_fetch_with_a_known_size_probes_nothing fails with the known-size path disabled.
  • make -C adr check-refs: passed. cargo nextest run -p decdn-client --features public-api-test --test public_api: passed.

Checklist:

  • pre-commit run --all-files
  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features
  • cargo nextest run
  • PR title type and lowercase subject
  • adr/: make -C adr check-refs; adr/architecture.md doesn't mention the size claim
  • User-visible change: CHANGELOG.md entry

🤖 Generated with Claude Code

…ream (#2619)

A fetch pinned with `--node-id` and no known size read its first size
claim from the header of a whole-blob paid open, then dropped the
stream. The node wrote up to a credit window into it first and counted
it in `decdn_bytes_served_total`: in the gateway e2e the node wrote 1.36
times the wire bytes of the pulls.

- A known size is the first claim: `ProbeOpts::known_size` carries a
  manifest entry size (the gateway's `size_cap`), and a bundle entry
  uses its manifest size. Neither probes.
- With no known size, `probe_pinned` probes the pinned node once on
  `cdn/probe/v1` (2 s, no shed backoff, no direct-path wait) and takes
  its size as the hint. A failed, unverifiable, non-holder or sizeless
  answer falls back to the header open; the node stays the only holder.
- The bundle engine probes a pinned node for the manifest and for
  entries without a manifest size. A pinned rediscovery probes nothing.
- `decdn_bytes_served_total` is documented as bao wire bytes, the unit
  payment uses, including frames a requester never pays for.
- The gateway and bundle e2es assert the node writes the wire bytes of
  their pulls and no more.

Closes #2619

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras thiras self-assigned this Oct 26, 2026
Copilot AI balanced review requested due to automatic review settings October 26, 2026 18:39

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.

🟢 Approval recommended

The changes preserve advisory size handling and fallback recovery, with targeted regression coverage and no unresolved blocking findings.

No open issues 🎉

What changed in this PR

This PR reduces wasted traffic during pinned downloads by using a known size or a lightweight probe instead of opening and discarding a paid stream. It preserves the header-open fallback when a probe supplies no usable size.

Changes:

  • Uses manifest sizes directly and probes pinned nodes once when the size is unknown.
  • Adds regression checks for probe behavior and excess bytes served during gateway and bundle downloads.
  • Clarifies that node served-byte metrics count bao wire bytes, including unpaid frames.
File Description
crates/​node/​src/​metrics.rs Clarifies served-byte counter documentation.
crates/​e2e/​tests/​gateway_public.rs Checks node wire-byte totals across gateway pulls.
crates/​e2e/​tests/​cli_bundle_pull_pool_id.rs Checks bundle pulls avoid excess served bytes.
crates/​client/​src/​targets/​tests.rs Tests pinned probing, known sizes, and hint eligibility.
crates/​client/​src/​targets.rs Adds pinned size probing and known-size selection.
crates/​client/​src/​quote.rs Reuses the relocated pinned-target helper.
crates/​client/​src/​probe.rs Adds answer-only probing without direct-path waiting.
crates/​client/​src/​lane_sources/​tests.rs Updates fallback test documentation.
crates/​client/​src/​lane_sources.rs Skips unnecessary probes during pinned rediscovery.
crates/​client/​src/​bundle/​engine.rs Probes pinned targets when manifest sizes are unavailable.
crates/​cli/​src/​commands/​fetch.rs Passes known sizes into target resolution.
crates/​cli/​src/​commands/​fetch_timings.rs Updates probe timing documentation.
CHANGELOG.md Records the download fix and metric clarification.
adr/​appendix-observability.md Defines served-byte accounting as bao wire bytes.
adr/​appendix-gateway.md Explains gateway versus node byte counters.
adr/​039-multi-source-parallel-fetch.md Documents known-size and pinned-probe hint selection.

Review effort: Balanced

@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 77a08da fix/2619-pinned-size... f519e9f +/-
77% 77% 0%
View coverage of the 9 most impacted files.
File main 77a08da fix/2619-pinned-size... f519e9f +/-
crates/client/src/probe.rs 98% 97% -1%
crates/client/s...undle/engine.rs 65% 65% 0%
crates/client/s...lane_sources.rs 40% 40% 0%
crates/node/src...gin/pull_leg.rs 84% 84% 0%
crates/cli/src/...mmands/fetch.rs 48% 48% 0%
crates/protocol/src/framing.rs 92% 93% +1%
crates/node/src/dht/publish.rs 78% 80% +2%
crates/client/src/targets.rs 60% 64% +4%
crates/client/src/quote.rs 74% 78% +4%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

@thiras
thiras merged commit da7c178 into main Oct 26, 2026
36 checks passed
@thiras
thiras deleted the fix/2619-pinned-size-probe branch October 26, 2026 20:08
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.

node: decdn_bytes_served_total appears to count ~2.3× the bytes the client legs deliver

2 participants