Skip to content

fix(client-pull): keep ingest disk I/O off the tokio runtime - #2121

Merged
thiras merged 2 commits into
mainfrom
fix/2117-ingest-blocking-io
Sep 22, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/2117-ingest-blocking-io

Conversation

@thiras

@thiras thiras commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Closes #2117

Problem

ClientRangedStore::ingest_stream ran write_all_at and the 4 MiB checkpoint sync_alls inline on the tokio workers. The client pays from inside that decode loop (next_chunk → pay_one), so a slow fsync on a multi-GB sparse .partial stalled voucher sends on every lane at once. Nodes then dropped every stream with proof read timed out after 10s.

Fix

  • Ingest (ranged_store.rs). Verified leaves and parents collect into ~INGEST_CHECKPOINT_BYTES batches. Each batch flushes on spawn_blocking: write, fsync data then outboard, then union into present (fsync-before-union kept). One flush runs in flight while the next batch decodes, bounding memory at ~2 intervals per stream.
  • Error handling. A stashed peer fault outranks a local flush error on both the fault and Done paths. A flush logs its own failure, so a detached flush (dropped future) does not lose it. Checkpoint errors name the file and offset.
  • Scheduler (scheduler.rs). Once lanes interleave, a steal could cancel a victim whose range was already fully present, dropping it just before finish. Work::pick now only trims the victim. The stealer cancels via Work::cancel_victim after its present-bytes backstop finds missing bytes, and only while the victim still runs the unit the steal trimmed. A per-worker unit counter means a second steal from the same victim cannot hide the first stealer's cancel.
  • Docs. The re-pay bound is under two intervals when the future is dropped (the flush in flight detaches and may land after the requeue read). Docs now say so.

Out of scope: VOUCHER_SEND_DEADLINE vs the node's VOUCHER_READ_TIMEOUT (fix C in the issue).

Tests

  • ingest_stream_slow_flush_does_not_block_the_runtime: 1-worker runtime, 3 s test-only flush delay, ticker max-gap < 1.5 s. Failed with a 2.0 s stall before the fix.
  • ingest_stream_mid_gap_fault_checkpoints_received_prefix: now holds the flush in flight past the fault. Fails if the fault-path reclaim is removed (mutation-checked).
  • forced_steal_no_double_pay_on_multi_thread_runtime: asserts the victim billed its leg. Fails 3/3 with the cancel moved back into pick.
  • steal_cancels_the_victim_only_through_cancel_victim: single steal, double steal, moved-on victim, idle victim.
  • Re-anchored three tests whose assertions held only while ingest never yielded:
    • distinct_providers_each_pay_their_own_lane uses disjoint coverage.
    • large_multi_block_gap_seeds_about_one_span_per_holder checks each holder's first (seeded) open instead of the total open count.
    • forced_steal_does_not_double_fetch_the_stolen_tail widens the slow start from 200 ms to 1 s.
      Each was stress-verified against main under parallel load.

Local: cargo clippy --workspace --all-targets -D warnings, rustdoc -D warnings, fmt, and nextest -p decdn-client-pull -p decdn-cli -p decdn-node all pass (2323 tests).

Not yet confirmed on testnet. The regression test proves the runtime-starvation mechanism, not the field cause. Re-run the gpt-oss bundle pull and check fra1/lon1/bcl for proof read timed out.

🤖 Generated with Claude Code

ClientRangedStore::ingest_stream ran write_all_at and the 4 MiB
checkpoint fsyncs inline on the runtime workers. The paid pull pays
from inside that decode loop, so a slow fsync stalled voucher sends on
every lane at once, and nodes dropped every stream with "proof read
timed out after 10s".

ingest_stream now collects each ~4 MiB of verified leaves and parents
into a batch and flushes it (write, fsync, union into present) on
spawn_blocking, with one flush in flight while the next batch decodes.
A stashed peer fault outranks a local flush error, and a flush logs its
own failure so a dropped leg does not lose it.

Interleaved lanes exposed a scheduler window: a steal cancelled a
victim whose range was already fully present, dropping it before its
finish. Work::pick now only trims the victim; the stealer cancels it
through Work::cancel_victim once its backstop finds missing bytes, and
only while the victim still runs the unit the steal trimmed (a per-
worker unit counter, so a second steal cannot hide the cancel).

Tests: a 1-worker regression test that fails while a flush blocks the
worker, fault-path and steal-billing assertions, and three scheduler
tests re-anchored off assumptions that only held while ingest never
yielded.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings September 22, 2026 19:13
@thiras thiras self-assigned this Sep 22, 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

Unresolved ranged-store finalization and error-propagation issues, plus synchronous record persistence that can still block the runtime.

Get a fresh assessment by requesting another Copilot review.

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

Open (3)
What changed in this PR

This PR moves client ingest writes/fsyncs off Tokio workers and hardens scheduler steal cancellation, with related durability documentation and tests.

Changes:

  • Batches verified data and outboard checkpoint flushes via spawn_blocking.
  • Refines victim cancellation and payment behavior during scheduler steals.
  • Updates durability documentation and regression coverage.
File Summary
crates/​client-pull/​src/​scheduler.rs Adds safer, unit-aware steal cancellation.
crates/​client-pull/​src/​ranged_store.rs Adds batched asynchronous ingest flushing; unresolved findings cover flush finalization races, I/O error propagation, and crash-bound documentation.
crates/​client-pull/​src/​driver.rs Retains synchronous present-record persistence, which can still block Tokio workers (moderate, 3 votes).

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

Comment thread crates/client-pull/src/ranged_store.rs Resolved
Comment thread crates/client-pull/src/driver.rs Resolved
Comment thread crates/client-pull/src/ranged_store.rs Resolved
…e fetch

The interval owner wrote the `.ranges` record (tempfile + fsync) inline
in its select! arm, which both blocked a runtime worker and stopped
polling the fetch future, i.e. every lane's pay loop, for the duration
of the fsync.

IngestStore::flush_present_record now returns a future. The client
store snapshots `present` at the call and writes it on spawn_blocking;
finalize's pre-sweep record write moves there too. drive_with_interval_flush
runs each tick's write beside the fetch, keeps at most one in flight,
and lands it before returning so an older snapshot cannot rename over
the caller's final one.

Also documents that a stream fault or decode failure outranks a flush
failure on ingest_stream's error path.

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

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 83.83% (was 83.82%, ▲ +0.01%) — 88065/105049 lines

File Coverage Lines Δ
crates/client-pull/src/driver.rs 94.83% 1872/1974 ▼ 0.17%
crates/client-pull/src/lib.rs 90.64% 1965/2168 ● 0.00%
crates/client-pull/src/ranged_store.rs 91.01% 1194/1312 ▼ 0.04%
crates/client-pull/src/scheduler.rs 93.92% 2039/2171 ▼ 0.19%
crates/client-pull/src/source.rs 93.29% 320/343 ● 0.00%
crates/node/src/node_origin/admit_store.rs 93.53% 217/232 ▲ +0.03%
History
Commit Total Δ vs base
d14f0a5 83.83% ▲ +0.01%
31d062e (HEAD) 83.83% ▲ +0.01%

@thiras
thiras merged commit 772e4ef into main Sep 22, 2026
25 checks passed
@thiras
thiras deleted the fix/2117-ingest-blocking-io branch September 22, 2026 19:42
alpergundogdu added a commit that referenced this pull request Sep 22, 2026
Resolve the #2121 × #1848 re-export overlap in client-pull/lib.rs: keep the
#1848 `scheduler::ConsumptionPacing`, `sink::{BlobCache, ByteSink, NoCache,
SinkFuture}`, and `streamer::{StreamCandidate, Streamer, VerifiedReader}`
re-exports, and add #2121's new `source::SourceFuture`. scheduler.rs
auto-merged.

Co-Authored-By: Claude Opus 4.8 <[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.

client-pull: blocking fsync on the tokio runtime stalls voucher sends; nodes drop every stream with 'proof read timed out after 10s'

2 participants