Skip to content

refactor(node): stream node-to-node pull to disk, drop the last O(blob) ingest buffer (#1682) - #1696

Merged
alpergundogdu merged 14 commits into
mainfrom
claude/issue-1682-spec-impl-a29324
Aug 14, 2026
Merged

alpergundogdu merged 14 commits into
mainfrom
claude/issue-1682-spec-impl-a29324

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

What

Ports node_origin's node-to-node cache-miss pull off its in-RAM whole-blob buffer onto the streaming gap-driven drive() / NodeAdmitStore path. After this, no ingest tier holds a whole blob in RAM — the node-to-node pull streams range-by-range to disk through admit_bao_stream, so a multi-GiB blob costs O(chunk-group) RSS instead of the full disk budget.

Closes #1682.

Why

resume::pull_blob accumulated the whole blob into LoopState.buf: Vec<u8> and returned it as OriginFetch::found_one_shot(bytes) — the last O(blob) ingest path. With #1685/#1686 defaulting max_blob_size_mb to cache_size_mb, its worst-case RSS became the entire disk budget on one pull. It buffered because its resumable-rewind + reactive-top-up loop rewound with Vec::truncate; the gap-driven driver makes retry "re-derive missing ranges" instead, so the buffer disappears.

How

  • OriginFetch::AlreadyAdmitted (new variant): the origin streams the blob into the store itself via admit_bao_stream and tells the engine not to re-ingest. pull_through_attempt short-circuits to the existing post-commit tail (CommitOnly → Committed, ReturnBytes → read_local).
  • pull_from_candidate now runs drive() over NodeAdmitStore + PeerSource + BudgetPacer + NodeFunder (the same machinery run_pull_leg uses), on a dedicated blocking-thread current-thread runtime because drive's future is non-Send vs Origin::fetch's Send bound. Cancellation (CancellationToken + select!), on-thread SettleOnDrop, and ABANDON_DRAIN mirror run_pull_leg so a dropped fetch future stops the pull, persists the final watermark, and never strands a connection.
  • Typed-fault recovery (important): admit_bao_stream now hands the reader back on its error path (Result<R, (R, CacheError)>) and NodeAdmitStore::ingest_stream recovers the reader's stashed typed fault (take_fault()), mapping bao verify failures to the typed HashMismatch. Without this, every mid-stream peer fault collapsed to Unreachable and reactive top-up never fired. This also repairs the same latent hole in the already-merged run_pull_leg serve path.
  • Shared-ledger completion clamp: drive's fill_gap clamps the gap-completion frontier to the store's delivered_frontier, so two concurrent pulls on one channel can't complete each other's blobs early via the shared voucher watermark. No-op on solo/CLI pulls.
  • Reactive-top-up metering moved into NodeFunder (the one seam both pull legs fund through) + a populate-path refuse-metering guard for a lying-peer CapExceeded (feat(node): reactive mid-pull deposit top-up on the node-to-node buyer leg (#1530) #1600).
  • Deletes the buffered resume loop (~1.1k lines) and rehomes its still-used settle-cadence constants into funder.rs.

Scope notes

  • The max_blob_size_bytes disk-budget ceiling, PullVerdict::OversizeClaim, and node_pull_too_large are kept — they gate/meter the real ceiling on the surviving path. The issue's other named deletions (BufferedTierTooLarge, buffered_tier_max_bytes) did not exist in the tree (leftovers from a closed PR).
  • The ported pull opens two connections per candidate (a free header handshake for total_bytes, then the drive pull) — the same shape run_pull_leg uses. Eliminating the redundant connection and the per-pull ephemeral runtime is tracked as Pull legs run on ephemeral per-serve runtimes, stranding shared connection drivers (HTTP + QUIC) #1675 and deliberately left for that work.

Testing

Full workspace green: cargo build, cargo clippy --all-targets, cargo fmt --check, cargo nextest run (2765 passed, 0 failed), and the anvil-e2e compile gate. Includes a new 8 MiB streaming-populate test, a cancellation-persists-watermark test, the fault-classification/reactive-top-up regression suite, and a concurrent-pull completion test (5× stable).

Known minor follow-ups (non-blocking)

🤖 Generated with Claude Code

alpergundogdu and others added 11 commits August 14, 2026 11:58
… refused reactive top-up

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…e for the gap-driven pull

Co-Authored-By: Claude Opus 4.8 <[email protected]>
It is now constructed on the live node-origin pull path, so the allow (and
its changelog-voice reason) no longer applies.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 14, 2026 15:17

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.

Pull request overview

This PR removes the last whole-blob in-RAM ingest path for node-to-node cache-miss pulls by porting NodeOrigin from the legacy buffered resume loop to the shared gap-driven decdn_client_pull::drive() machinery, streaming verified ranges directly into the cache store via admit_bao_stream.

Changes:

  • Introduces OriginFetch::AlreadyAdmitted to let origins admit into the store themselves and short-circuit cache re-ingest/readback paths.
  • Reworks NodeOrigin node-to-node pulls to run drive() on a dedicated blocking thread + current-thread runtime, with cancellation/settle/drain behavior mirrored from the serve-miss pull leg.
  • Strengthens ingest/driver correctness: typed-fault recovery for admit_bao_stream failures and a paid-frontier clamp against delivered_frontier to prevent shared-ledger concurrent pulls from “completing” gaps early.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/node/tests/node_origin_pull.rs Updates fixtures to use AlreadyAdmitted and read back from CacheEngine; adds streaming populate + cancellation/watermark tests.
crates/node/src/runtime/mod.rs Wires the node’s cache engine into NodeOriginDeps so node-to-node pulls can admit directly into the store.
crates/node/src/node_origin/resume.rs Deletes the legacy buffered resumable pull loop.
crates/node/src/node_origin/pull_leg.rs Adapts to new settle/funder wiring and exports ABANDON_DRAIN for reuse.
crates/node/src/node_origin/mod.rs Ports populate-path pull-through to gap-driven drive() + direct admission; adds cancellation/settle/drain thread model.
crates/node/src/node_origin/funder.rs Moves reactive-top-up budgeting + settle cadence constants here; extends NodeFunder to meter top-up outcomes and expose “funded” signal.
crates/node/src/node_origin/admit_store.rs Recovers parked typed peer faults from readers on admit failure and maps bao verification failures to typed HashMismatch.
crates/node/src/handlers/client/serve_encoder.rs Updates for admit_bao_stream’s new error return shape.
crates/client-pull/src/pacer.rs Updates module docs now that policy is fully unit-testable without referencing the deleted node resume loop.
crates/client-pull/src/driver.rs Clamps paid completion frontier to delivered_frontier to prevent shared-ledger concurrent pulls from completing gaps early.
crates/cache/tests/s3_origin.rs Adjusts tests for the new OriginFetch::AlreadyAdmitted variant (ensures S3 never returns it).
crates/cache/src/retry.rs Preserves AlreadyAdmitted through retry buffering logic (no buffering needed).
crates/cache/src/origin/s3.rs Extends exhaustiveness matches to include AlreadyAdmitted (documented as unreachable here).
crates/cache/src/origin/mod.rs Adds OriginFetch::AlreadyAdmitted and updates helpers/debug formatting accordingly.
crates/cache/src/origin/fs.rs Adjusts tests for the new OriginFetch::AlreadyAdmitted variant (ensures FS origin never returns it).
crates/cache/src/engine.rs Changes admit_bao_stream to return the reader on both success and failure; short-circuits pull-through when an origin returns AlreadyAdmitted; updates tests.

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

Comment thread crates/node/tests/node_origin_pull.rs Resolved
alpergundogdu and others added 2 commits August 14, 2026 17:27
Reconcile the node-origin pull port with main's credit-slow-start ramped
credit window (#1691) and fixed voucher cadence (#1676), and the
present-tense comment rewrite (#1687).

- Delete resume.rs (the buffered loop this branch already replaced); main
  only rewrote its comments.
- Keep the collapsed SettleOnDrop (no SettleDeps enum / lifetime), our
  driver delivered_frontier completion clamp, and the AlreadyAdmitted +
  typed-fault-recovery ingest changes, alongside main's RampPacer rework.
- Restore the AtomicBool import dropped with main's LeechPacer removal.
- Resize the concurrent-resume fixture to span several VOUCHER_INTERVAL_BYTES
  so it still exercises mid-pull exhaustion under the ramped credit window.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

github-actions Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.60% (was 80.71%, ▼ 0.11%) — 58669/72792 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 91.35% 3614/3956 ▼ 0.47%
crates/cache/src/origin/fs.rs 78.36% 594/758 ▼ 0.02%
crates/cache/src/origin/mod.rs 57.14% 64/112 ▲ +9.95%
crates/cache/src/origin/s3.rs 89.36% 546/611 ● 0.00%
crates/cache/src/retry.rs 79.57% 187/235 ▼ 0.68%
crates/client-pull/src/driver.rs 96.15% 775/806 ▲ +0.38%
crates/client-pull/src/pacer.rs 98.97% 192/194 ● 0.00%
crates/node/src/handlers/client/serve_encoder.rs 83.56% 249/298 ▲ +0.06%
crates/node/src/node_origin/admit_store.rs 89.55% 197/220 ▲ +0.55%
crates/node/src/node_origin/funder.rs 94.44% 221/234 ▲ +5.01%
crates/node/src/node_origin/mod.rs 91.14% 1059/1162 ▲ +0.12%
crates/node/src/node_origin/pull_leg.rs 85.80% 568/662 ▼ 0.41%
crates/node/src/node_origin/resume.rs — — deleted
crates/node/src/runtime/mod.rs 46.82% 1082/2311 ▼ 0.04%
History
Commit Total Δ vs base
933268d 80.59% ▼ 0.11%
bedee34 (HEAD) 80.60% ▼ 0.11%

…es contract

Both bytes-less variants collect to None; AlreadyAdmitted must never yield an
empty buffer that a caller could mistake for content.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu

Copy link
Copy Markdown
Contributor Author

Re: the coverage report (−0.11% total, non-blocking) — the dip is understood and expected:

  • The core new logic is covered, and the files that matter went up: funder.rs +5.01%, admit_store.rs +0.55%, driver.rs +0.38%, mod.rs +0.12%.
  • The small drops are almost all AlreadyAdmitted exhaustiveness match arms in adapters that never return it by design (s3.rs, origin/fs.rs, retry.rs) — untestable without contriving an impossible state.
  • The one genuinely meaningful gap — OriginFetch::collect_to_bytes() returning None for AlreadyAdmitted — now has a contract test (bytesless_variants_collect_to_none, bedee34), pinning that the variant can never yield an empty buffer a caller mistakes for content.

🤖 Addressed by Claude Code

@alpergundogdu
alpergundogdu merged commit e6149eb into main Aug 14, 2026
50 of 52 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issue-1682-spec-impl-a29324 branch August 17, 2026 17:47
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.

feat(node): port resume::pull_blob onto BlobSource/NodeAdmitStore — the last O(blob) ingest path

2 participants