Skip to content

perf(cli): prefer manifest node for bundle chunks - #1328

Merged
thiras merged 3 commits into
mainfrom
feat/1294-prefer-manifest-node
Jul 20, 2026
Merged

thiras merged 3 commits into
mainfrom
feat/1294-prefer-manifest-node

Conversation

@altanoruc

@altanoruc altanoruc commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

What

  • retain the node/provider that served a bundle entry when that entry is a DECDNMAN file manifest
  • fetch its chunks directly from that preferred target without probing on the common path
  • on a typed delivery-side refusal, discover a holder for that chunk, fetch it there, and carry the successful fallback forward
  • keep explicit --node-id pulls pinned and keep sibling bundle entries independently selected

Why

The previous reconstruction callback called normal discovery for every missing chunk. Large files therefore paid one full probe fan-out per chunk even though the node that served the manifest commonly serves its chunks too.

Impact

Auto-discovered DECDNMAN reconstruction now performs one initial entry discovery in the common case instead of probing before every chunk. If the serving node no longer holds or cannot serve a chunk, normal per-hash discovery preserves availability. Explicit node selection remains strict.

Validation

  • cargo test -p decdn-cli bundle_pull
  • cargo test -p decdn-cli
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo fmt --all -- --check
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items
  • independent code review: approved with no findings

Closes #1294

Summary by CodeRabbit

  • Bug Fixes

    • Improved bundle downloads by continuing chunk retrieval from the same node/provider that served the manifest.
    • Added fallback discovery when an automatically selected delivery target refuses a request, and reuse the discovered target for later chunks.
    • Preserved explicit node selection behavior by preventing fallback when a pinned target is unavailable.
  • Documentation

    • Clarified retry guidance for BlobTooLarge errors: try a different node rather than retrying the same one.

@coderabbitai

coderabbitai Bot commented Jul 19, 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: 114f4063-825c-4e5f-9eaf-c3213679ab59

📥 Commits

Reviewing files that changed from the base of the PR and between 70e5871 and dc105fe.

📒 Files selected for processing (2)
  • crates/cli/src/commands/bundle_pull.rs
  • crates/protocol/src/client.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/cli/src/commands/bundle_pull.rs

Walkthrough

Bundle pulling now preserves the node and provider selected for each manifest, reuses that target for chunk retrieval, and conditionally discovers a fallback holder after typed delivery refusals. Tests cover reuse, fallback, pinning, and voucher rejection. The protocol documentation clarifies retry guidance for oversized blobs.

Changes

Bundle pull target reuse

Layer / File(s) Summary
Target selection and fetch abstraction
crates/cli/src/commands/bundle_pull.rs
Adds FetchTarget, separates target selection from direct fetching, and implements preferred-target fallback behavior.
Manifest target propagation and chunk fallback
crates/cli/src/commands/bundle_pull.rs
Passes the manifest-serving target into reconstruction and reuses it for DECDNMAN chunks, with conditional discovery fallback.
Fallback behavior validation
crates/cli/src/commands/bundle_pull.rs
Tests target reuse, discovery carry-forward, explicit pinning, and voucher rejection handling.
Delivery refusal documentation
crates/protocol/src/client.rs
Clarifies that oversized-blob retries should use another node rather than the same node.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PullCtx
  participant Delivery
  participant Discovery
  PullCtx->>Delivery: Fetch manifest and selected FetchTarget
  Delivery-->>PullCtx: Manifest bytes and target
  PullCtx->>Delivery: Fetch chunks using preferred target
  Delivery-->>PullCtx: Typed delivery refusal
  PullCtx->>Discovery: Discover holder when entry is not pinned
  Discovery-->>PullCtx: Fallback target
  PullCtx->>Delivery: Retry chunk fetch using fallback target
Loading

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.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request optimizes the bundle pull command by allowing manifest chunks (for DECDNMAN entries) to reuse the holder node that served the manifest, bypassing discovery unless a typed delivery refusal occurs. It introduces a fetch_preferred helper function to manage this fallback behavior and updates PullCtx to track and pass the preferred target. Additionally, comprehensive unit tests have been added to verify the chunk reuse and fallback logic. I have no feedback to provide as there are no review comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@altanoruc
altanoruc marked this pull request as ready for review July 19, 2026 20:12
@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.72% (was 81.74%, ▼ 0.02%) — 51002/62413 lines

File Coverage Lines Δ
crates/cli/src/commands/bundle_pull.rs 46.58% 313/672 ▲ +21.07%
crates/protocol/src/client.rs 97.31% 688/707 ● 0.00%
History
Commit Total Δ vs base
8181b7a 81.60% ▼ 0.03%
70e5871 81.61% ▼ 0.02%
dc105fe (HEAD) 81.72% ▼ 0.02%

`fetch_preferred` falls back to discovery only on a delivery-side
refusal. `VoucherRejected` is deliberately excluded: it is the one wire
code that arrives ONLY mid-stream, after bytes were delivered and paid
for, and it reports a buyer-side voucher fault that would follow the
retry to the next node — so falling back on it would re-fetch and re-pay
the chunk to lose the same way twice, once per remaining chunk.

Nothing pinned that exclusion from this side. Replacing the
`is_delivery_side()` gate with a bare `is_some()` left all ten existing
`bundle_pull` tests green; the new test fails there with two fetches
where one is expected. (`StreamError`'s own domain split stays covered
by `decdn_protocol`, so the delivery-side variants need no restating
here.)

Also thread the `FetchTarget` alias through `fetch_from` — destructured
in parameter position, since a `target` binding would shadow the
`EndpointAddr` local of that name — and let `fetch` delegate to
`fetch_with_target` rather than repeat pick-then-fetch.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 88.96% (2499/2809 lines)
▲ +0.00pp vs base (88.96% → 88.96%)
Run: 29762368504

@altanoruc

Copy link
Copy Markdown
Contributor Author

Reviewed the diff against StreamError's domain split, pick, discovery::rank, and file_manifest::reconstruct. The core design is sound: delivery-side codes ride only in the initial StreamResponse (crates/protocol/src/client.rs:699), so a fallback happens strictly before any bytes are delivered or any voucher is signed — the retry cannot re-pay. reconstruct is strictly sequential (crates/cli/src/commands/file_manifest.rs:192), so the Cell<FetchTarget> cannot lose an update. And the worst case for a node that serves the manifest but holds none of its chunks is one wasted round-trip, not one per chunk, since the first fallback is carried forward. Two things:

1. The fallback discovery can re-select the node that just refused. discover is self.pick, which probes and ranks with no exclusion for the refusing target. For NotFound/EvictedSinceProbe the probe answers has_blob: false and it drops out naturally, but for Overloaded the node still holds the blob, still probes true, and rank will happily return it again — especially since it is the node we already have a live channel with, which RTT_REUSE_TOLERANCE actively favors. We then re-fetch into the same refusal and fail the entry, even when a second-best holder was sitting right there in holders. This was latent before (per-chunk pick had the same blind spot), but it matters more now that this single fallback is the only retry the chunk gets. Threading an exclusion into pick — or letting rank skip a caller-supplied node — would close it.

2. The tests all exercise the free function, never the wiring. All four cases drive fetch_preferred directly with u8 targets. Nothing covers fetch_manifest_chunk passing self.explicit.is_some() as pinned, or fetch_entry threading the manifest's target into reconstruct_entry. If that boolean were inverted, or the target dropped and re-picked, every one of these tests still passes — and the pin-strictness half is the security-relevant one. One PullCtx-level test asserting an explicit --node-id reconstruction issues zero discoveries would pin the part that actually ships.

Minor: BlobTooLarge is delivery-side, so it now falls back, while its doc comment says "do not retry it". Retrying elsewhere is defensible (the limit is per-node config), but the two readings should agree.

The voucher_rejection_does_not_fall_back test and its comment are the right call — worth keeping that reasoning where it is.

@thiras
thiras merged commit f6a3ab6 into main Jul 20, 2026
23 checks passed
@thiras
thiras deleted the feat/1294-prefer-manifest-node branch July 20, 2026 17:46
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.

bundle pull: prefer the manifest's node for chunk fetches, fall back to discovery

2 participants