Repository navigation
feat(client-pull,cli): multi-source parallel fetch scheduler (ADR 039, #1164) - #1773
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements ADR 039’s client-only multi-source parallel fetch path for large blobs: the CLI can now fan out a single paid cdn/client/v1 fetch across multiple full-holder nodes concurrently, with bao-aligned segmentation, tail-stealing, and per-provider payment lanes on one shared pool deposit.
Changes:
- Added a multi-source scheduler (
multi_source_fetch) and pure segmentation/tail-steal helpers, including cancellation + stall reassignment and an aggregate solvency gate across lanes. - Reworked
ClientRangedStorepresent-range persistence to support concurrent ingest writers via single-writer interval flushing (.rangessidecar) and explicit flush points. - Wired CLI flags/engagement gate and added an anvil-backed e2e test validating two-holder parallelism and per-lane payment settlement; updated ADR 039 to “Accepted”.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/node_origin/admit_store.rs | Implements flush_present_record as a no-op for the node origin ingest store. |
| crates/e2e/tests/cli_fetch_multi_source.rs | Adds an anvil-backed CLI e2e proving two-holder multi-source fetch and per-lane payment. |
| crates/common/src/cli/fetch.rs | Adds CLI flags and resolved helper for multi-source enablement and tuning knobs. |
| crates/client-pull/src/source.rs | Extends IngestStore with flush_present_record; enhances scripted source doubles for deterministic multi-source tests. |
| crates/client-pull/src/segment.rs | New pure segmentation + tail-steal utilities (bao-aligned, canonicalized). |
| crates/client-pull/src/scheduler.rs | New multi-source fan-out scheduler with tail-stealing, cancellation, watchdog, and aggregate solvency gating. |
| crates/client-pull/src/ranged_store.rs | Moves .ranges persistence to explicit flush points; adds flush_present_record API and concurrent-ingest test. |
| crates/client-pull/src/lib.rs | Exposes the scheduler API (MultiSourceConfig, SourceLane, multi_source_fetch) and re-exports RangedStore. |
| crates/client-pull/src/driver.rs | Adds interval .ranges flushing wrapper; threads aggregate spend gate into fill_gap; refactors counters. |
| crates/client-pull/src/discovery.rs | Adds admit_sources for set-valued, operator-spread source admission with tests. |
| crates/client-pull/Cargo.toml | Adds futures-util for driving worker futures concurrently without spawning. |
| crates/cli/src/commands/fetch.rs | Wires multi-source engagement into decdn fetch, builds per-provider lanes, persists per-lane watermarks. |
| Cargo.lock | Records the new futures-util dependency in the lockfile. |
| adr/039-multi-source-parallel-fetch.md | Rewrites ADR 039 in present tense and marks it Accepted, matching implemented behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 81.57% (was 81.57%, ● 0.00%) — 64676/79287 lines
History
|
PR #1773 Review — multi-source parallel fetch scheduler (ADR 039, #1164)ContextBranch The PR makes Reviewed by five specialist agents plus a direct read of the diff. Every finding CriticalC1.
|
alpergundogdu
left a comment
There was a problem hiding this comment.
Doc-convention cleanup not covered by the earlier review: seven comments in scheduler.rs reference internal task numbers or before/after states ("the Task-4 double-pay", "Task 4's bookkeeping-only steal", "the pre-fix scheduler/code/bug"). CLAUDE.md's present-tense canon rules these out — a cold reader has no way to resolve "Task 4", and history belongs in git. Each inline comment carries a suggested present-tense rewrite that keeps the technical content (the counterfactuals stay; only the task numbers and pre/post-fix framing go).
Generated by Claude Code
…ge claims in 005/038
initial_segments and steal_split each rounded a raw, possibly unaligned byte-range end up to the next bao chunk-group boundary via align_range, but compared that ceiling against the raw unaligned end. Two gaps separated by less than one group of held data (or a range whose true end fell mid-group) could produce two AlignedRanges whose fetch spans overlapped by up to one group -- a double-fetch and, once the multi-source scheduler pays per source, a double-pay. Canonicalize every input span to its enclosing group boundaries (and merge touching/overlapping spans) before splitting, so every boundary handed to align_range is already aligned and its ceiling-up can never carry a segment past where the caller intended it to stop.
…ing them canonicalize_ranges clamped a span's rounded-up end to total_bytes to handle the blob's legitimate partial last group, but that same clamp silently absorbed a genuinely out-of-bounds span too: a gap whose start was at or past total_bytes was dropped, and one whose raw (pre-rounding) end exceeded total_bytes was silently truncated. This contradicted the still-documented RangeVerifyError propagation and the repo's fail-loudly-on-malformed-input convention. canonicalize_ranges now checks each span's start and raw end against total_bytes before any rounding, and returns RangeVerifyError::RangeOutOfBounds -- the same error align_range itself raises -- for a span that is genuinely out of bounds. The legitimate final-partial-group clamp (raw end == total_bytes, rounds up then clamps back down) is unaffected and still succeeds.
Fan a request across several paid sources over one shared store (spec §5.3): bao-aligned segmentation, one worker per source, and a freed source steals the aligned second half of the largest in-flight range. One outstanding unit per source (lane correctness). Node path untouched. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…no double-pay) Co-Authored-By: Claude Opus 4.8 <[email protected]>
… double-pay Co-Authored-By: Claude Opus 4.8 <[email protected]>
Adds the CLI-side pieces for ADR 039 multi-source fetch: --multi-source (default on) / --no-multi-source, --max-sources, --multi-source-min-bytes, --unit-deadline-ms on ClientFetchArgs, and the pure should_multi_source engagement gate (enabled && total_bytes > min_bytes && admissible >= 2) in crates/cli/src/commands/fetch.rs, covered by a TDD unit test. Wiring the gate into drive_fetch/bundle_pull is deliberately deferred: see task-7-report.md for why multi_source_fetch's single shared ctx/ledger/funder cannot yet correctly pay several distinct-provider sources at once. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…or multi-source; wire scheduler into fetch/bundle multi_source_fetch now takes a SourceLane set — each source paired with its OWN PoolContext (provider) + PoolLedger — instead of one shared ctx/ledger, so a voucher is signed against the source's real on-chain provider and each lane's cumulative advances independently (ADR 039 § Payment model). fill_gap gains an optional aggregate-committed reader: multi-source workers gate remaining_deposit on pool_deposit - Σ committed across every lane, so concurrent lanes cannot each treat the whole deposit as their own; the single-source drive path passes None and is unchanged. Wired into `decdn fetch`: when should_multi_source engages, build one per-provider lane per admitted candidate and call multi_source_fetch, else the single-source failover loop runs unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ed pool Strengthen the multi-source solvency coverage (review finding #1): the existing observation test only proved the pacer SEES deposit-minus-Σcommitted. Add shared_gate_refuses_a_second_leg_into_a_drained_pool, which proves the gate actually BLOCKS. A peer lane's ledger is pre-seeded near the deposit; the healthy lane fetches its own segment, then is refused the reassigned second segment because the aggregate remaining is below the next voucher cost. Asserts the fetch ends incomplete, the healthy lane bills exactly one segment (never the refused second), and combined committed stays within deposit + one in-flight leg — the honest leg-boundary bound (on-chain redemption is the hard backstop). RED against a naive own-committed gate: the fetch completes and the lane bills two segments. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…to one interval (spec §5.5) Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ce scheduler instead of masking as "all sources failed" Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ti-source scheduler; keep single-source failover on budget refusal Co-Authored-By: Claude Opus 4.8 <[email protected]>
…rom PR review Address the review on #1773. Payment accounting first, then what happens when things go wrong, then the coverage that would have caught either. Payment accounting across lanes: - `admit_sources` admits at most ONE node per operator. A voucher lane is keyed on `(signer, provider)` and `provider` IS the operator address, so filling spare slots with a repeat operator built two concurrent voucher streams on one watermark and collided two watermark writes under one `LaneKey`. The admitted set now shrinks instead. `multi_source_fetch` re-checks the same precondition on the lane set it is handed, so the premise is verified at the boundary rather than asserted in prose. - The deposit, the spend that gates it, and the reactive-top-up budget are facts of the POOL, not of a lane. They move behind one shared view: the gate subtracts the aggregate committed, the top-up budget is counted once per fetch rather than once per lane (4 lanes x 3 = 12 real escrows against a documented bound of 3), and a landed top-up credits EVERY lane rather than only the one that funded it. - A multi-source lane persists its ARMED cumulative. A tail steal drops the victim's `fill_gap` future inside the voucher exchange on a SUCCESSFUL fetch, so settling that lane at `committed` persisted below what the node redeems. Failure paths: - Retryable worker errors are kept and reported. A failed fetch names each lane by its payee and carries the last real error as its cause, so a caller's downcast still reaches it — which is what makes the CLI's two-cause cache-miss diagnosis reachable on this path at all. - A failed fan-out falls back to the single-source failover loop unless the failure is terminal. It resumes the same `.partial`, so nothing already paid for is re-bought. - The present record is flushed on the error path too, in both `drive` and the scheduler: the bytes a failed fetch delivered are paid for. - `is_complete`'s error is propagated rather than read as "not complete", which reported success with no output file on disk. - A freed worker with nothing to steal PARKS instead of retiring, so it is still there when a peer faults and re-queues moments later. - `steal_split` returns WHICH range it split, deleting a cross-module argmax agreement that had no compiler support; a steal that cannot trim its victim is declined rather than handed out untrimmed; `pick`/`clear` refuse an out-of-range worker index. - The engagement gate applies its size floor to the probe's reported size before opening a pool and a throwaway header stream, and each decline says which condition was unmet. Coverage: - The stall watchdog had none, and the test named for it exercised the fault path. Renamed it, added a `stall_after` source double (a source that wedges WITHOUT erroring — the only shape that reaches the watchdog), and covered all four branches deterministically under a paused clock. - The per-lane watermark rule is a pure function with tests: cross the lanes and nothing else in the fetch path would notice. ADR 039 and the CHANGELOG record the behavior. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01JjiDQL7FuB8UHGBBpG1PjH
c423f10 to
71fecd6
Compare
|
Rebased onto Payment accounting (C1, C4, C5, I4)
Failure paths (C2, C3, I1, I2, I3, I5, I6)
I7 / I8
Coverage (T1, T3)
Not done in this passAll of S1–S15 and the remaining T2/T4/T5 items, by scope decision — happy to take them as a follow-up. Two notes from working through them:
ADR 039 is updated where this changes behavior (one-node-per-operator as a payment rule, the parking semantics, the fallback answer you flagged as an unspecified gap, and the shared-pool facts), and the PR now carries a CHANGELOG entry. Verified: 2934 workspace tests pass, |
…n exit status The journey retried `decdn fetch` until it exited 0, because a holder whose chain watcher has not yet observed the freshly-opened pool refuses the stream pre-serve. Exit status stopped being a readiness signal once a retryable refusal on one lane falls back to single-source failover: the fetch now exits 0 having been served by the OTHER holder alone, the retry loop stops, and the both-holders-paid assertion fails against a fetch that never fanned out. Wait for what the journey actually asserts — one invocation that bills BOTH lanes. Requiring both within a SINGLE invocation is what keeps it honest: a loop that accumulated payments across attempts would pass on two single-source fetches that each paid a different holder, which is the non-parallelized case this journey exists to rule out. Each attempt clears the output and `.partial` set first, so a resumed fetch cannot bill one lane for the other's remainder. Reproduced at ~1 run in 4 before, 10/10 green after. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01JjiDQL7FuB8UHGBBpG1PjH
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 89.69% (2575/2871 lines) |
Implements the ADR 039 multi-source parallel fetch scheduler (closes #1164). A client fetching a large blob now fans out across several full-holder nodes at once over the existing paid
cdn/client/v1protocol, instead of streaming from one peer. Client-only: the node's cache-miss pull leg is untouched.Design (ADR 039, rewritten in this branch)
byte_lenrequest; a source that finishes steals the tail of the largest remaining range (min_split_sizefloor, 16 MiB). "Keep the fastest source hot" is emergent from stealing, not a separate controller.(signer, provider)payment lane. Parallelism comes from source count.(signer, provider)lane seeded from that lane's cumulative; a shared aggregate-committed gate (deposit − Σ committed across all lanes) keeps concurrent lanes from overspending the one deposit.byte_lenrequests already exist and the node already bills the exact aligned span.What's included
client-pull/src/segment.rs— pure group-canonical segmentation + tail-steal helpers.client-pull/src/scheduler.rs— concurrent fan-out, tail-stealing, cancellation + deadline reassignment, present-bytes backstop (no double-pay), aggregate-solvency gate, interval.rangesflush.client-pull/src/ranged_store.rs— single-writer present-record flush (per-checkpoint fsync moved off the hot path; interval flush bounds crash-loss).discovery::admit_sources— set-valued admission with operator/region spread.--multi-source/--no-multi-source,--max-sources(4),--multi-source-min-bytes(64 MiB),--unit-deadline-ms(10s); engagement gate wired intodecdn fetch.Testing
Deferred (accepted, not blocking)
bundle pullstays single-source (itsopen_lockserialization + rarely-fired 64 MiB gate make multi-sourcing low-value for now).🤖 Generated with Claude Code