Skip to content

fix(client): let sibling bundle entries finish their lane-build drain - #2518

Merged
thiras merged 2 commits into
mainfrom
fix/2509-bundle-sibling-drain
Oct 18, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/2509-bundle-sibling-drain

Conversation

@thiras

@thiras thiras commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

What

When one entry ended a bundle pull (a give-up, a pool replacement, a fault that stops every entry), run_groups dropped every other entry's fetch where it stood. An entry in the middle of a topUp or openPool lane build lost it before the receipt read and the local record. #2516 names such a tx at the end of the command; this PR stops dropping the build in the first place. first_open had the same shape: its give-up dropped an in-flight lane build and a recovery step.

  • A per-pass halt on StopPolicy. A private CancellationToken (halt, is_halted, ensure_running, halted, next_pass) and a crate-private Halted error. PullCtx::run clears it as each pass starts and ends, so it reaches neither the next pass, nor a later manifest fetch or pull of the same puller.
  • run_groups halts and waits. On the first fault that ends the pull, it starts no further item, calls halt, and keeps settling items for up to GROUP_DRAIN (40 s = BUILD_DRAIN + 10 s). A later fault that may have escrowed USDC no record credits (carries_untracked_escrow, which sees through LaneBuildFault) is folded in with fold_late_escrow: the escrow wins, so a give-up does not exit 75. Every other later fault is logged at WARN and dropped. An item still running at the bound is dropped as before, with a WARN that counts them.
  • acquire stops at its loop top (ensure_running) and in its select! (halted), so it starts no lane build after the halt, and checks again right before a funding recovery step. Its existing tail drains the builds.
  • first_open takes the stop into its loop's select!. A recovery step runs to its outcome, and the build in flight drains through the shared drain_builds / fold_late_escrow (now generic and pub(crate)).
  • Halted entries are EntryOutcome::NotRun. The summary does not count them, the skip-cache does not record them, and merge_passes keeps an entry's first-pass outcome when the second pass did not run it. A pass that ends with no fault on a halt it did not set fails (pass_stop) instead of ending complete with nothing pulled.

Closes #2509

Reviewer notes

  • Read first: run_groups, pass_stop and PullCtx::run in crates/client/src/bundle/engine.rs; StopPolicy in crates/client/src/stop.rs; first_open / open_loop in crates/client/src/first_open.rs.
  • Public API: none. StopPolicy gains a private field, so it can no longer be built with a struct literal outside the crate; every caller uses StopPolicy::new. The decdn-client public-api snapshot is unchanged.
  • Behavior a user can see:
    • A pull that ends early can now take up to 40 s longer to return, while the other entries drain.
    • A give-up in first_open can land after its limit while a recovery step finishes.
  • Known limits, filed as fix(client): a halted bundle pull can leave a pool replacement, unrun entries and a pending escrow unreported #2517:
    • A pool replacement made during the drain, or hidden under a folded escrow, is not reported, so the CLI skips its reclaim note. No funds are lost: the new pool is recorded.
    • Entries the pull did not run are not counted anywhere in the summary.
    • GROUP_DRAIN is shorter than RECEIPT_TIMEOUT, so a slow recovery step can still be dropped mid-receipt. The CLI names its pending tx, but pull_end does not fold it for library callers.
  • Halt landing during a recovery-step lock wait: this window is left open on purpose. An entry queued behind a sibling's step only sends a new topUp if that step failed and a byte was verified in between. Closing it means changing the RecoveryGate::step signature, which the node also uses.
  • Review: I ran code, test-coverage, comment and silent-failure passes, then re-reviewed the fixes. Everything at confidence 80 or above is fixed here or filed in fix(client): a halted bundle pull can leave a pool replacement, unrun entries and a pending escrow unreported #2517.
  • Tests:
    • bundle/engine/tests.rs:
      • siblings are halted and settled, and the escrow wins over a give-up;
      • every escrow is named, and another fault stays dropped;
      • an escrow that lands before the bound survives a sibling that is dropped;
      • NotRun outcomes and the merge;
      • a halted fetch whose build escrowed still ends the pull;
      • the stale-halt guard.
    • scheduler/tests.rs: a halt awaits the build in flight and its escrow wins; a pre-set halt starts no build.
    • first_open/tests.rs:
      • a give-up awaits the build in flight, and a late escrow wins;
      • a pre-set halt builds no lane;
      • a give-up, and a halt, that land during a recovery step;
      • a halt while the open waits on a header.
    • stop/tests.rs: next_pass.
    • Mutation checks: I removed each guard in turn. Each removal fails a test: the loop-top checks, the select! arms in acquire and first_open, the escrow fold, take_while, the LaneBuildFault look-through, the NotRun mapping and merge arm, and pass_stop.
    • Not covered: the halt check before the recovery step in acquire, which guards a timing window, and the re-arm calls in PullCtx::run, which have no harness. pass_stop makes a regression there loud.

Verification

  • cargo fmt -- --check
  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features (run as -- -D warnings)
  • cargo nextest run --workspace: 5135 passed. One flaky retry, decdn-node::client_loopback a_closing_pool_is_unfunded_to_its_lane_and_not_found_to_anyone_else ("both refusals must count as pool_closing"). It passed 8 of 8 runs on its own and does not touch the changed code.
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items
  • decdn-client public-api snapshot (cargo nextest run -p decdn-client --features public-api-test --test public_api): unchanged
  • contracts/ changed: n/a
  • User-visible change: CHANGELOG.md entry added
  • Design change: n/a. No ADR describes the sibling drain.
  • PR title uses an allowed type with a lowercase subject

🤖 Generated with Claude Code

When one entry ended a bundle pull, run_groups dropped every other
entry's fetch where it stood. An entry in the middle of a topUp or
openPool lane build lost it before the receipt read and the local
record, which left a tx to reconcile by hand. first_open dropped an
in-flight lane build and a recovery step on a give-up the same way.

The pull now halts the other entries through a per-pass halt on
StopPolicy. Each stops at its next wait or loop pass, starts no new
lane build or recovery step, and drains its builds (30 s); run_groups
waits up to 40 s for them all. A build that may have escrowed USDC no
record credits wins over the stop, so a give-up does not exit 75.
Halted entries are NotRun: not counted, not recorded, and a pass merge
keeps their earlier outcome. A pass that ends on a halt it did not set
fails instead of ending complete.

Closes #2509

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 18, 2026 09:15
@thiras thiras self-assigned this Oct 18, 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.

🟡 Changes recommended

Dropping a draining pull leaves a stale halt that can break subsequent manifest fetches on the same puller.

1 open issue
What changed in this PR

This PR lets stopped bundle pulls drain sibling lane builds, reducing interrupted funding transactions and preserving late escrow errors.

Changes:

  • Adds per-pass halting and bounded sibling draining.
  • Makes initial opens drain builds and finish recovery steps.
  • Adds halted-entry handling and regression tests.
File Description
crates/​client/​src/​stop/​tests.rs Tests halt isolation between passes.
crates/​client/​src/​stop.rs Adds shared per-pass halt state.
crates/​client/​src/​scheduler/​tests.rs Tests halting and build draining.
crates/​client/​src/​scheduler.rs Handles halts and shares drain helpers.
crates/​client/​src/​first_open/​tests.rs Tests stops during builds and recovery.
crates/​client/​src/​first_open.rs Drains builds before returning.
crates/​client/​src/​fault.rs Detects wrapped escrow errors.
crates/​client/​src/​bundle/​engine/​tests.rs Tests sibling draining and outcome handling.
crates/​client/​src/​bundle/​engine.rs Coordinates halting, draining, and pass outcomes.
CHANGELOG.md Documents changed stop behavior.

Review effort: Balanced

Comment thread crates/client/src/bundle/engine.rs Resolved
@github-code-quality

github-code-quality Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 6d5bbd5 fix/2509-bundle-sibl... e8b6611 +/-
76% 76% 0%
View coverage of the 9 most impacted files.
File main 6d5bbd5 fix/2509-bundle-sibl... e8b6611 +/-
crates/client/src/lib.rs 89% 89% 0%
crates/node/src...s/client/mod.rs 91% 91% 0%
crates/cache/src/engine.rs 91% 91% 0%
crates/client/src/scheduler.rs 94% 94% 0%
crates/client/src/fault.rs 96% 96% 0%
crates/client/src/stop.rs 100% 100% 0%
crates/client/s...c/first_open.rs 89% 90% +1%
crates/protocol/src/framing.rs 92% 93% +1%
crates/client/s...undle/engine.rs 62% 64% +2%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 18, 2026 09:37 UTC

A caller that drops BundlePuller::pull during the sibling drain leaves
the pull's halt set: the re-arm after the pass never runs. A later
fetch_manifest on the same puller went through acquire_entry on that
policy and failed at once with Halted, since it never reaches run.

acquire_entry and fetch_to_staging now take the stop policy. An entry
passes the pull's own policy, which a sibling halts; a manifest passes
an unhalted copy on the same progress clock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 36c8239 into main Oct 18, 2026
31 checks passed
@thiras
thiras deleted the fix/2509-bundle-sibling-drain branch October 18, 2026 09:38
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.

fix(client): a bundle pull drops sibling entries mid-drain, losing a late escrow and allowing exit 75

2 participants