Skip to content

fix(cli,client-pull): harden bundle pull failover, dedup complement, and data-dir guards - #2122

Merged
thiras merged 5 commits into
mainfrom
fix/cli-bundle-pull-robustness
Sep 22, 2026
Merged

thiras merged 5 commits into
mainfrom
fix/cli-bundle-pull-robustness

Conversation

@thiras

@thiras thiras commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2063
Closes #2086
Closes #2118
Closes #2119
Closes #2120

The four bundle-pull issues come from one testnet gpt-oss pull that crawled and failed silently. #2086 is a fail-open classifier on the pool guards that move USDC. One commit per concern.

#2086: daemon_marker fails closed

  • daemon_marker returns io::Result<Option<_>> and stats with symlink_metadata. Only NotFound reads as absent.
  • classify_buyer_store and ChainAdoption::for_buy propagate the error. A stat error therefore refuses escrow, sweep, implicit-node-dir buys and chain adoption.
  • pool list --all shows the TRACKED column as unknown.

#2118: failover, visible exhaustion, --entry-retries

  • One walk_candidates helper serves both the whole-file path and the range path.
  • PoolExhausted now fails over on the range path too, per retry_disposition's documented rule.
  • The last failover also logs a WARN.
  • An entry that exhausts its candidates now says all N candidate provider(s) failed, which shows in the end-of-run summary. The context wraps the original error, so classification still works.
  • --entry-retries N (default 2): after the first pass, each retryably failed entry runs again. The backoff is 2 s, doubling, capped at 30 s.
    • Each round probes again, so previously failed providers can be chosen again.
    • Each round resumes from the entry's .partial, so no byte is paid for twice.
    • PoolExhausted and terminal errors are not retried.
  • A retried entry's bar keeps its fold high-water mark, so the total bar does not count the landed prefix twice.
  • Latent bug fixed: ensure_partial created a .partial with no .ranges record. A later drive's open_or_create then truncated the spliced donor bytes, forcing a full-price self-heal. It now creates a real ranged store. A regression test fails without the fix (mutation-checked).

#2063: the prelude's first open is the drive's first leg

  • PrimedSource parks a live pull. The drive's first open of exactly that (hash, AlignedRange) adopts it.
    • Adoption requires exact equality, because finish drains and pays to stream end.
    • A primed pull older than 2 s is never adopted.
  • first_leg shares one leg_range helper with the Draw arm, so the primed range always equals the range the drive would open.
  • Whole-blob fetches keep the (0,0) open. It is adopted only when the first gap is the whole blob. A resume drops it, as before.
  • Range-dedup entries open a bounded first leg sized from the manifest. A size mismatch fails over.
  • Out of scope: the multi-source probe_admitted_total still drops its size probe, because the scheduler's first unit is a segment, never (0,total). The node's handshake_total_bytes is also unchanged.

#2119: one warm session per entry, concurrent ranges

  • RangeSession replaces drive_ranges. CtxRangeDriver keeps one session per provider across every drive of an entry: complement, re-fetch, deferred fallback, self-heal.
    • A failed drive drops the session and fails over.
    • The entry never returns to a provider that failed it within the same round.
  • PeerSource::with_warm_connection() dials once and opens every pull as a new stream on that connection. It redials if the connection has closed, and retries an open once if the connection closed under it. An open sends no voucher, so the retry is money-safe.
  • drive_range_set merges the gaps of all ranges and fills them up to --max-lane-streams at once. It uses one interval flush, one final flush (on failure too) and one finalize.
    • After the first failed gap, no new gap starts.
    • Without a SharedPool, gaps stay serial, so the top-up budget cannot multiply.
  • Extra lane permits come from a non-blocking LaneStreamCap::try_extra, so they cannot deadlock against permit_set.

#2120: drive-level throughput floor

  • throughput_watchdog (client-pull) runs the existing ThroughputFloor over a caller's counter, with a pause flag.
  • watched_drive wraps drive_fetch and every RangeSession drive. It applies the same --min-throughput-bps / --stall-timeout-ms floor, measured on the drive's position across every leg and the gaps between them.
  • PausingFunder stops the clock from a top-up until the next byte lands.
  • A trip ends the drive with EntryStalled (RetryElsewhere), flushes the present record the dropped drive skipped, and fails over.
  • At -v, each drive logs position, rate and ETA every 10 s, and each entry logs its size, time and effective rate when it finishes.
  • The driver's progress callbacks now take a borrowed trait object, so a caller can wrap its own. Existing callers are unaffected.

Risks worth a look

  • Concurrent same-lane legs. A dedup entry's gaps can now run concurrently on one lane. They rely on the existing delivered-frontier clamp in fill_gap, which the multi-source scheduler already uses. The existing billing e2e and the new one both assert exact wire billing.
  • Concurrent top-ups. Two gaps that hit exhaustion together can both top up. This is the same race the scheduler already has, bounded by max_topups and the working-deposit ceiling.

Tests

  • Unit tests:
    • walk_candidates: success, terminal, exhaustion failover, context.
    • entry_retryable, backoff, run_with_retries (paused clock).
    • Retry-bar fold.
    • ensure_partial truncation.
    • try_extra.
    • drive_range_set: concurrent (peak in flight between 2 and 4), merged gaps, serial without a pool, stop on fault.
    • first_leg: fresh, resume, ceiling, all present.
    • PrimedSource: adopted, mismatch, clear, stale.
    • Watchdog: trips, quiet while flowing, paused.
    • EntryWatch, PausingFunder, watched_drive.
    • cli: daemon_marker classifies a stat failure as 'not a node' #2086: stat error propagates; guards fail closed.
  • New e2e: cli_bundle_pull_drives_a_scattered_complement_concurrently. 24 donor chunks interleaved with unique tails give about 25 complement ranges. It runs with --max-lane-streams 4 and asserts byte-exact output and exact complement billing.
  • Local results:
    • clippy -D warnings --all-targets passes, including decdn-e2e --features anvil-e2e.
    • rustdoc -D warnings passes.
    • nextest -p decdn-cli -p decdn-client-pull -p decdn-common --all-features: 1604 pass.
    • anvil e2e (range-dedup, multi-source, pool-id, fetch resume, fetch multi-source, delegated): 12 pass.
    • -p decdn-node: 1245 pass.
  • Flake to know about. node_to_node_pull_through::upstream_hash_mismatch_is_rejected flaked (failed, then passed on retry) in 2 of 5 full-suite runs on this branch and 0 of 4 on main, where silent_upstreams_do_not_starve_the_candidate_loop flaked once instead. It passes alone. Its path (open_progressive_pull → decode_to_vec) touches no changed code. The failure is the lying upstream's own write or read hitting connection lost, which looks like a race with the requester's early close. I did not prove that it is unrelated.

Not yet confirmed on testnet. Re-running the gpt-oss bundle pull -v should show:

  • the original/model.safetensors complement finishing in minutes;
  • per-entry rate lines;
  • a WARN if an entry runs out of providers.

Review follow-ups (6c14310, eab658a)

Drive-level floor

  • The floor timed finalize's local re-hash of a complete blob, so a paid multi-GB download could fail as EntryStalled. The drop it caused could also race an older record write.
  • drive_range_set now takes a stop future that races only the gap work. The pending flush lands and the final flush runs; finalize is never timed.
  • Both CLI drives share FetchPrelude::drive_watched / settle_drive.

Money safety

  • Concurrent gaps top up one at a time: SharedPool::topup_lock, backed by the run's LaneLedgers::topup_lock. The waiting gap re-reads the deposit. This stops a double escrow, and without --max-approve a topUp reverting on a spent allowance.
  • Groups re-run in a retry round are unmarked as finished. A deferred shared chunk is no longer paid by both the donor and the recipient.
  • open_or_create uses try_exists, so a failed stat never truncates a paid .partial.
  • Extra lane permits are held per drive only, which removes the deadlock at the default --max-lane-streams.

Error handling

  • The decisive gap error is kept (terminal, then PoolExhausted); the others are logged.
  • The warm-connection retry logs the first error and never re-asks a peer that refused.
  • A manifest size mismatch or a local disk fault never starts a retry round.
  • Failed entries queued for retry are logged with their error, and failover warnings name the entry.

Types, tests and docs

  • New types:
    • a generic SessionWalk with a fake-driven test suite;
    • EntryWatch::begin_topup;
    • GroupRun::fetch_failed;
    • the warm connection derived from PreludeLeg.
  • New tests:
    • warm PeerSource on one connection (node loopback);
    • landed bytes stay recorded after a stop;
    • one top-up for concurrent gaps;
    • error ranking;
    • concurrent progress;
    • retry settle and unmark;
    • open_or_create stat failure;
    • the flag default.
  • The scattered e2e now asserts the node served exactly 1 + complement opens, so no open is thrown away.
  • Docs, ADR and CHANGELOG corrected.

Local: workspace clippy -D warnings --all-targets --all-features, rustdoc -D warnings, 3,328 unit and node tests, and 12 anvil e2e all pass.

🤖 Generated with Claude Code

thiras and others added 3 commits September 23, 2026 00:24
…undle entries (#2086, #2118)

daemon_marker stats each daemon store with symlink_metadata and returns
a stat error other than NotFound instead of reading it as "not a node".
classify_buyer_store and ChainAdoption::for_buy propagate it, so every
money-moving refusal guard refuses when the owner is unknown.

bundle pull walks candidates through one walk_candidates helper: a pool
exhaustion fails over on both the whole-file and the range path, every
failover logs a warning (the last one too), and the exhausting error
names the candidate count. A new --entry-retries (default 2) re-runs
retryably failed entries after the first pass, with 2 s doubling
backoff capped at 30 s; each round re-probes and resumes the .partial.
A retried entry's bar does not recount its landed prefix on the total.

ensure_partial creates a real ranged store (with its .ranges record)
instead of a bare .partial, so a later drive into the entry no longer
truncates the donor bytes spliced into it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ranges over one warm session (#2063, #2119)

The fetch prelude opened a throwaway whole-blob pull only to read
total_bytes, dropped it, and let the drive open the same range again. The
node treats every open as real (sign, claim a fill, start an origin
draw), so every cold entry paid a duplicate draw and a delayed first
byte. The prelude now opens exactly the drive's first leg (first_leg,
built on the same leg_range the Draw arm uses) and parks it in a
PrimedSource, whose first open of that exact hash and range adopts it.
A dedup entry, whose manifest gives its size, opens a bounded first leg
instead of the whole blob. A resume or a mismatched range drops the
pull; a primed pull older than 2 s is never adopted.

A range-dedup entry paid its ~1,300 boundary groups one drive at a time,
each on a fresh QUIC connection and behind a fresh prelude. The CLI now
opens one RangeSession per provider per entry and reuses it for every
drive (complement, re-fetch, deferred fallback, self-heal). The session's
PeerSource keeps one warm connection (redialled if it closes) and
drive_range_set fills the merged gaps up to --max-lane-streams at once
under one flush owner and one finalize. Without a shared pool the gaps
stay serial so the top-up budget cannot multiply.

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

The throughput floor judged one stream at a time. A range-dedup entry's
short legs are each briefly healthy and the wait between legs belongs to
no stream, so an entry could deliver under 1 MB/s for 20 minutes with
no stall, no failover and no warning.

client-pull adds throughput_watchdog, the existing ThroughputFloor over
a caller's counter with a pause flag. The CLI runs drive_fetch and every
RangeSession drive under it (watched_drive), on an EntryWatch that folds
the drive's reported position across every leg. A PausingFunder stops
the clock from a top-up until the next byte lands. A trip ends the
drive with EntryStalled (RetryElsewhere), flushes the present record
the dropped drive skipped, and fails over; --entry-retries picks up an
entry that runs out of providers. At -v a drive logs its position, rate
and ETA every 10 s, and each bundle entry logs its size, time and rate.

The driver's progress callbacks take a borrowed trait object so a
caller can wrap its own. Adds a scattered-complement e2e that drives
~25 ranges four at a time and checks exact billing, and the CHANGELOG
entries for #2063, #2086, #2118, #2119 and #2120.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings September 22, 2026 22:08
@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 critical and moderate correctness issues remain in retry coordination, permit handling, watchdog accounting, and provider failure handling.

Get a fresh assessment by requesting another Copilot review.

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

Open (5)
What changed in this PR

Hardens bundle pulls with failover, retries, concurrent range deduplication, throughput monitoring, and fail-closed data-directory checks.

Changes:

  • Adds entry retries, warm sessions, and concurrent range driving.
  • Adds stall detection and improved progress reporting.
  • Propagates ownership-classification errors and updates documentation.
File Description
crates/​node/​tests/​origin_range_pull.rs Updates origin-pull test documentation.
crates/​e2e/​tests/​cli_bundle_pull_range_dedup.rs Adds concurrent complement billing coverage.
crates/​common/​src/​data_dir.rs Makes daemon-marker stat failures explicit.
crates/​common/​src/​cli/​bundle.rs Adds --entry-retries.
crates/​client-pull/​src/​source.rs Adds warm connections and primed pulls.
crates/​client-pull/​src/​progress.rs Adds drive-level throughput watchdog support.
crates/​client-pull/​src/​lib.rs Exports new driver and source APIs.
crates/​client-pull/​src/​driver.rs Adds first-leg and concurrent range driving.
crates/​client-pull/​src/​connection.rs Adds connection-closed detection.
crates/​cli/​src/​commands/​pull_progress.rs Prevents retry progress double-counting.
crates/​cli/​src/​commands/​pool.rs Propagates ownership-classification errors.
crates/​cli/​src/​commands/​fetch.rs Integrates priming, sessions, and watchdogs.
crates/​cli/​src/​commands/​buyer_store.rs Makes ownership guards fail closed.
crates/​cli/​src/​commands/​bundle_pull.rs Adds retries, failover, sessions, and store protection.
CHANGELOG.md Documents the fixes.
adr/​appendix-bundles.md Updates bundle concurrency and retry behavior.

💡 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
Comment thread crates/cli/src/commands/bundle_pull.rs Resolved
Comment thread crates/cli/src/commands/fetch.rs Resolved
Comment thread crates/cli/src/commands/fetch.rs Resolved
Comment thread crates/cli/src/commands/fetch.rs Resolved
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 84.02% (was 83.85%, ▲ +0.17%) — 91480/108878 lines

File Coverage Lines Δ
crates/cache/src/fill_session.rs 93.98% 1139/1212 ● 0.00%
crates/cli/src/commands/bundle_pull.rs 74.63% 3406/4564 ▲ +3.00%
crates/cli/src/commands/buyer_store.rs 98.71% 230/233 ▲ +0.15%
crates/cli/src/commands/fetch.rs 53.89% 1803/3346 ▲ +1.93%
crates/cli/src/commands/pool.rs 66.21% 966/1459 ▼ 0.32%
crates/cli/src/commands/pull_progress.rs 77.15% 260/337 ▲ +1.67%
crates/client-pull/src/connection.rs 91.30% 21/23 ▲ +1.30%
crates/client-pull/src/driver.rs 96.27% 2604/2705 ▲ +1.23%
crates/client-pull/src/ledgers.rs 98.41% 124/126 ▲ +0.04%
crates/client-pull/src/lib.rs 91.35% 2102/2301 ▲ +0.39%
crates/client-pull/src/progress.rs 98.30% 231/235 ▼ 0.41%
crates/client-pull/src/ranged_store.rs 91.98% 1216/1322 ▲ +0.06%
crates/client-pull/src/scheduler.rs 94.16% 2209/2346 ▼ 0.04%
crates/client-pull/src/source.rs 91.50% 463/506 ▼ 1.79%
crates/common/src/data_dir.rs 100.00% 42/42 ● 0.00%
crates/node/src/node_origin/pull_leg.rs 87.10% 790/907 ▲ +0.03%
History
Commit Total Δ vs base
6f7de6f 83.82% ▼ 0.04%
6c14310 83.84% ▼ 0.02%
eab658a (HEAD) 84.02% ▲ +0.17%

thiras and others added 2 commits September 23, 2026 01:34
…cross gaps

Review follow-ups on #2122.

- A range session took every free permit for its provider when it opened
  and kept them through reconcile_deferred. A recipient could then hold
  all of provider P's permits while waiting on a donor blocked on P, a
  deadlock at the default --max-lane-streams. The extra permits are now
  taken per drive and returned when it ends.
- Concurrent gaps can each start a top-up, and a byte from one gap
  cleared the drive watch's pause while another gap's top-up was still
  on chain. EntryWatch counts top-ups in flight and only progress with
  none pending ends the pause.
- EntryStalled prints its window with sub-second precision.
- A test pins that a donor retried after a recipient registered its
  chunk splices it rather than paying for it again.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Drive-level floor:
- The floor raced the whole drive, so it also timed finalize's local
  re-hash of a complete blob: a paid multi-GB download could fail as
  EntryStalled, and its dropped flush could race an older record write.
  drive_range_set takes a `stop` future that races only the gap work;
  the pending flush lands, the final flush runs, finalize is untimed.
  drive_fetch now runs drive_range_set too, and both CLI drives share
  FetchPrelude::drive_watched/settle_drive.
- EntryWatch::begin_topup owns the pause; observe re-checks after its
  store so a top-up starting between the check and the store stays
  paused. A failed drive stamps the peer store only when the peer caused
  it (not PoolExhausted / InsufficientDeposit).

Money:
- SharedPool gains topup_lock (the run's LaneLedgers::topup_lock, a
  local one for the scheduler and the node's pull legs). A lane that
  waited on it re-reads the deposit and decides again, so concurrent
  gaps no longer escrow twice or revert on a spent allowance.
- A group re-run in a retry round is unmarked as finished, so a sibling
  deferring its chunk waits instead of paying for it too.
- open_or_create uses try_exists: a failed stat of .ranges no longer
  reads as "no record" and truncates a paid .partial.

Errors:
- drive_range_set keeps the decisive gap error (terminal, then
  PoolExhausted) and logs the rest.
- The warm-connection retry logs the first error and never re-asks a
  peer that sent a refusal.
- entry_retryable also skips a ManifestSizeMismatch and a local disk
  fault; queued retries are logged with their entry and error, and the
  failover warnings name the entry.
- PrimedSource and the progress fold map recover a poisoned lock
  instead of dropping state; an unused primed pull is logged.

Types/tests/docs:
- open_fetch_prelude derives the warm connection from PreludeLeg;
  RangeSession::open takes &LaneLedgers; GroupRun::fetch_failed; the
  session walk is a generic SessionWalk with a fake-driven unit suite.
- New tests: warm PeerSource on one connection (node loopback), stop
  keeps landed bytes recorded, one top-up for concurrent gaps, error
  ranking, concurrent progress, primed + concurrent, retry settle and
  unmark, flag default, open_or_create stat failure; the scattered e2e
  counts the node's served opens (no open thrown away).
- Fix doc comments split by inserted tests, stale "throwaway" prelude
  wording, the PeerSource concurrency claim, the drive_fetch doc sitting
  on select_watermark, --entry-retries help, ADR and CHANGELOG wording.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@thiras
thiras merged commit 61c13b0 into main Sep 22, 2026
25 checks passed
@thiras
thiras deleted the fix/cli-bundle-pull-robustness branch September 22, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants