Skip to content

fix: unstall bundle pull (runtime I/O, lane credit, ingest fsync, probe limits, boundary legs) - #2124

Merged
thiras merged 7 commits into
mainfrom
fix/bundle-pull-unstall
Sep 23, 2026
Merged

thiras merged 7 commits into
mainfrom
fix/bundle-pull-unstall

Conversation

@thiras

@thiras thiras commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Summary

A decdn bundle pull smoke test of the gpt-oss bundle (27.6 GB, --exclude 'metal/*') exited 0, but it only got there through failover and one retry round. Big entries fell to 100 KiB/s – 3 MiB/s, and the nodes logged proof read timed out after 10s. This PR fixes each cause. One commit per fix:

  1. fix(cli): keep bundle pull file I/O off the runtime, move staging into place, report paid bytes.
    • Every group of a pull is a future on one task (buffer_unordered). materialize copied each finished blob, up to 13 GB, and fsynced it on that task, so every other stream stopped reading and paying.
    • First writes, links, staging removal and the donor sweep now run on the blocking pool.
    • A non-donor blob is renamed into place instead of copied. A donor's first destination is a hard link.
    • downloaded now counts bytes actually paid for.
    • The iroh endpoint is closed on every exit, so Endpoint dropped without calling Endpoint::close is gone.
  2. fix(cli): tell a rate-limited probe apart from a silent node and retry it.
    • At the start of a pull, the per-entry probes exceed the per-peer limit in ADR 005 (5/s, burst 5). The nodes shed the extra probes with 0x10, and probe_and_order reported those nodes as "did not answer".
    • A shed probe is now retried after 250 ms, 500 ms and 1 s. A node that still sheds after that is reported as rate-limited.
  3. fix(node): a metering voucher pays no whole chunk.
    • Rooted Open, re-anchor and Roll vouchers took lane headroom that belonged to a reveal on a sibling stream the node had not read yet. The sibling then waited for a proof the payer never sends, until the 10 s proof-read timeout.
    • Rooted vouchers now credit nothing against a whole chunk.
    • A new loopback test reproduces the wedge.
    • ADR 003 and ADR 005 now state the rule. They also correct two places where the ADRs no longer matched the code: the preimage sent per stream, and the closing voucher that rolls.
  4. fix(client-pull): pipeline ingest checkpoints so a slow fsync does not stop payment.
    • ingest_stream waited for every 4 MiB fsync before it decoded more, so payment stopped while the disk was slow.
    • Checkpoints now go through a bounded queue: at most 3 checkpoints not yet on disk, merged fsyncs, and present still updated only after the fsync.
  5. perf(cli): splice adjacent donor chunks as one run so boundary groups are not fetched.
    • Each donor chunk was aligned inward on its own, so every chunk boundary left one 16 KiB group to fetch as its own paid request of about 110 ms. There were thousands of them.
    • Adjacent chunks now form one spliced run. A donor that fails its check is fetched again over the whole groups it touches.
    • adr/appendix-bundles.md is updated to match.

Test plan

  • cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --check, RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items
  • cargo nextest run --workspace --all-features: 3937/3937 passed
  • New tests:
    • first_write_* and group_transfer_downloads_only_the_paid_bytes_of_a_spliced_blob
    • probe_candidate_* (loopback server that sheds probes) and no_serve_target_error_*
    • a_sibling_roll_does_not_take_a_retired_reveals_credit; checked that it fails with the fix reverted
    • ingest_stream_decodes_past_a_slow_fsync, …_bounds_undurable_bytes, …_coalesces_queued_checkpoints
    • plan_dedup_adjacent_donors_*, reassemble_dedup_refetches_the_outward_group_span_of_a_failed_donor, reconcile_deferred_falls_back_to_the_outward_group_span
  • Live testnet rerun of the same pull with the new client (the nodes do not have commit 3 yet):
before after
wall time 8m32s 5m56s
retry rounds 1 (3 entries) 0
client WARN/ERROR lines many (early eof, all sources failed, did not answer) 0
node proof read timed out yes (bcl, lon1) 0
16 KiB serve_stream legs (Tempo) thousands 0
summary downloaded 27.6 GB downloaded 14.8 GB → reconstructed 27.6 GB
gap between last entry and exit ~32 s (13 GB copy) ~0 s (rename)

Deploy note

Commit 3 changes node crediting, so it only takes effect after the testnet nodes are redeployed. Until then, the loopback test is the proof for it.

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings September 23, 2026 01:41
@thiras thiras self-assigned this Sep 23, 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

bundle_pull.rs can over-report paid bytes for resumed fetches and stale or incorrect manifest sizes.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR improves large bundle-pull performance and payment liveness across runtime I/O, probe retries, lane crediting, ingest checkpoints, and donor-range handling.

Changes:

  • Moves blocking bundle I/O off runtime workers and closes endpoints cleanly.
  • Retries rate-limited probes, corrects voucher crediting, and pipelines ingest fsyncs.
  • Coalesces adjacent donor ranges and updates related ADR documentation.
File Summary
crates/​node/​tests/​client_loopback.rs Adds rollover-credit regression coverage.
crates/​node/​src/​handlers/​client/​voucher.rs Prevents metering vouchers from claiming whole chunks.
crates/​node/​src/​handlers/​client/​serve_leg.rs Adds proof failure context.
crates/​node/​src/​handlers/​client/​mod.rs Updates proof-budget documentation.
crates/​node/​src/​handlers/​client/​delivery.rs Updates delivery proof context and documentation.
crates/​client-pull/​src/​scheduler.rs Updates checkpoint bounds.
crates/​client-pull/​src/​ranged_store.rs Adds bounded asynchronous checkpoint processing.
crates/​cli/​src/​commands/​fetch.rs Retries rate-limited probes and closes endpoints.
crates/​cli/​src/​commands/​bundle_pull.rs Moves I/O off-runtime and coalesces donor runs; paid-byte accounting needs correction for resumed fetches and stale manifest sizes.
adr/​appendix-bundles.md Documents spliced-run behavior.
adr/​005-protocol.md Clarifies payment-lane protocol rules.
adr/​003-payments.md Documents metering-voucher credit rules.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/cli/src/commands/bundle_pull.rs Resolved
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 84.12% (was 84.04%, ▲ +0.08%) — 92237/109648 lines

File Coverage Lines Δ
crates/cli/src/commands/bundle_pull.rs 75.80% 3781/4988 ▲ +1.19%
crates/cli/src/commands/fetch.rs 56.10% 1946/3469 ▲ +2.42%
crates/client/src/ranged_store.rs 92.10% 1387/1506 ▼ 0.09%
crates/client/src/scheduler.rs 94.16% 2207/2344 ▼ 0.04%
crates/node/src/handlers/client/delivery.rs 92.33% 337/365 ▲ +0.15%
crates/node/src/handlers/client/mod.rs 94.86% 2012/2121 ● 0.00%
crates/node/src/handlers/client/serve_leg.rs 74.38% 151/203 ▲ +0.65%
crates/node/src/handlers/client/voucher.rs 93.19% 575/617 ▲ +0.30%
History
Commit Total Δ vs base
cf1a7a3 84.09% ▲ +0.07%
f6b258e 84.12% ▲ +1.26%
fd07d27 84.11% ▲ +0.10%
bd69bf8 (HEAD) 84.12% ▲ +0.08%

thiras and others added 5 commits September 23, 2026 16:09
…o place, report paid bytes

Every group of a bundle pull is a future polled by one task
(`buffer_unordered`). `materialize` copied each finished blob (up to
13 GB) plus an fsync synchronously on that task, so every other
group's streams stopped reading and paying; serving nodes then ended
them at their 10s voucher-read timeout and the client saw `early eof`.

- Run the first write, links, staging removal and the run-end donor
  sweep on the blocking pool.
- Move a non-donor staging blob into its first destination with a
  rename (copy only across filesystems) instead of writing it again;
  hard-link a donor's first destination so its staging name survives.
- Report `downloaded` as the content bytes paid for: a range-dedup
  blob no longer counts the bytes it spliced from disk, and an
  already-finalized staging blob counts nothing.
- Close the iroh endpoint on every exit of `bundle pull` and `fetch`,
  so the run no longer ends with "Endpoint dropped without calling
  Endpoint::close".

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…y it

A bundle pull probes every candidate for every entry, so its first
seconds send each node more probes than the ADR 005 per-peer limit
(5/s, burst 5) admits. The node sheds the extra ones with
APP_ERR_RATE_LIMITED, and `probe_and_order` dropped the error and
counted the node as "did not answer" — an entry then failed with
"none of the 3 probed node(s) could serve the blob (3 did not answer)"
and waited for a retry round.

- Probe a candidate that sheds the probe again after 250 ms, 500 ms
  and 1 s; the per-peer bucket refills one probe every 200 ms.
- Count a candidate that still sheds as rate-limited and name it in the
  terminal error, apart from the silent ones.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Every proof credited a stream's outstanding chunk from lane-shared
headroom, including rooted open, re-anchor, and rollover vouchers. A
rollover folds every reveal the payer released, including one a sibling
stream carries and the node has not read yet. When the rolling stream's
task read its voucher first, it took that reveal's headroom for its own
chunk. The sibling's reveal then landed on the retired root, credited
nothing, and the sibling waited for a proof the payer never sends, until
the 10s proof-read timeout killed the stream. Multi-stream bundle pulls
hit this as `proof read timed out after 10s: peer-side fault`.

A voucher that carries a live chain_root now credits nothing against a
whole chunk. It still advances the watermark and anchors its stream, and
the stream waits for its reveal. Reveals, sealed vouchers, and vouchers
that settle a partial closing chunk keep crediting from headroom.

The recoup loops add the proof attempt, the chunk size, and the pending
count to a failed proof read. The loopback tests cover the wedge and the
anchor voucher that credits nothing. ADR 003 and ADR 005 state the rule.
They also describe the per-stream preimage cadence and the rolling
closing voucher that the payer uses.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…t stop payment

ingest_stream checkpoints every 4 MiB, and before it queued the next
checkpoint it waited for the previous one's write and fsync. While it
waited the decode loop pulled no bytes, so the paid pull sent no
vouchers. A slow fsync (several multi-GB partials, writeback
throttling) held payment past the serving node's 10 s voucher timeout,
and the node ended the stream.

The decode loop now queues each verified batch and keeps decoding. It
waits only when INGEST_MAX_QUEUED_CHECKPOINTS (3) checkpoints are not
yet durable. A spawn_blocking worker runs while checkpoints are queued,
takes them in order, folds the queued ones into one fsync, and only
then extends `present`, so the fsync-before-record rule holds. The
worker exits when the queue is empty, so an idle ingest holds no
blocking-pool thread and does not stop a paused test clock.

A stream fault now also checkpoints the verified batch it holds, so a
fault re-pays only bytes past the last verified chunk group. A crash or
dropped future re-pays at most INGEST_MAX_QUEUED_CHECKPOINTS + 1
intervals. Checkpoints use sync_data: fdatasync persists the size
growth and block allocation that reading the data back needs.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… are not fetched

Range-dedup aligned each donor chunk inward to 16 KiB chunk groups on
its own, so wherever two spliced chunks met inside a group that group
was left uncovered and driven as its own paid request. A large entry has
thousands of chunk boundaries; Tempo showed them as a stream of
`byte_len=16384` legs of ~110 ms each, mostly run one after another.

Donor and deferred chunks that touch now form one spliced run, and only
the run's two ends round inward to group boundaries. A boundary between
two spliced chunks is spliced from both sides. A donor that fails its
hash check, and a deferred chunk whose fetcher never produces it, are
fetched over every group their span touches, so a shared boundary group
ends up whole. The ranged store's finalize verify still drops any group
a lying placement corrupted, so a bad hint costs a re-fetch, never a
corrupt output.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@thiras
thiras force-pushed the fix/bundle-pull-unstall branch from cf1a7a3 to f6b258e Compare September 23, 2026 13:15
The job ran every decdn-client test beside the rustdoc render, and the
CPU contention failed a different timing-sensitive scheduler test on
each run. The `test` job already owns those tests, so each step now
runs the snapshot target alone.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 90.63% (2399/2647 lines)
▲ +0.88pp vs base (89.75% → 90.63%)
Run: 35869312476

The plain whole-file path never checks the manifest's optional `size`,
so a wrong declared size still fetches and verifies the real blob. The
paid count now reads the finalized staging file's length instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@thiras
thiras merged commit 8d7c6f5 into main Sep 23, 2026
25 checks passed
@thiras
thiras deleted the fix/bundle-pull-unstall branch September 23, 2026 13:54
thiras added a commit that referenced this pull request Sep 23, 2026
#2132) (#2133)

A proof credits at most the lane headroom it finds, so a sealed voucher
that moves the watermark by a sliver pays a sliver of the chunk. Both
recoup loops added that sliver to `paid` but popped the whole chunk, so
the unpaid rest was tracked nowhere. On a cache hit, once it filled the
credit window, `deliver` looped without awaiting and held one tokio
worker per stream; two such streams wedged a 2-vCPU testnet node.

- `OwedChunk { len, remaining }` replaces the bare delta in both queues.
  A chunk leaves the queue only when proofs have paid all of it, and
  `MAX_PROOFS_PER_CHUNK` counts every proof that leaves it unsettled.
- `voucher_credit_delta` classifies by the chunk's delivered length, so
  a metering voucher still pays no part of a whole chunk (#2124).
- Both loops check after each recoup that `delivered - paid` equals the
  bytes not yet cut into a chunk, and `settle` refuses an over-credit.
  Either break fails the stream as a node fault.
- The no-progress guard in both loops is a node fault. The miss path
  filed it as a client abandon; `ServeStop::ClientAbandoned` is gone.
- ADR 003/005: the payer anchors a stream immediately before its first
  reveal, not at stream open, and an honest payer never gets a partial
  credit. Both statements match the client and are now load-bearing.
- `two_hashes_reuse_one_warm_connection` reused a zero-based context for
  a second fetch on one lane and relied on the leak; it now seeds the
  second fetch from the lane's totals.

Tests: sliver credit, proof budget and last-proof settle on the cache
hit; sliver credit and proof budget on the miss path; a sub-chunk stream
on a live chain sends only its closing voucher (mutation-checked).

Closes #2132

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.

2 participants