Repository navigation
feat(node): route own-origin serve-miss through the two-leg driver; delete window_forward_loop - #1655
Conversation
…dSource Add the unpaid own-origin serve-miss substrate (FA.1): - cache: `CacheEngine::origin_encode_range` returns header-full verified bao wire for one `AlignedRange`, hard-faulting `VerifyFailed` on a corrupt own origin (no degrade — the node has committed to serving under H), plus `origin_fetch_outboard_bytes` as the serviceability probe. Both share a new `origin_fetch_range_bytes` fetch+meter helper factored out of `range_pull_attempt`. - node: `BackendSource` implements `decdn_client_pull::BlobSource` over the cache's own origin, stripping the 8-byte size header and advancing a local `ChannelLedger` completion counter at rate 0 in `finish` so the driver's paid-frontier gap loop can terminate without any payment axis. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Add `run_local_pull_leg`, the unpaid own-origin twin of `run_pull_leg`. It drives `decdn_client_pull::drive` over the FA.1 `BackendSource` instead of a paid `PeerSource`, reusing the serve-leg coordination, shared-outboard capture, `WindowPacer`+leech pacer, and cancel/`ABANDON_DRAIN` teardown verbatim. Every paid-path axis (discovery, channel open, `NodeFunder`, provider scoring, region accounting, `SettleOnDrop`) drops out — there is no counterparty; a `drive` error is a LOCAL-origin fault, never scored upstream. The driver's paid-frontier completion is satisfied by the LOCAL bookkeeping ledger the `BackendSource` advances on `finish` (rate 0 wire bytes), plus a benign `local_bookkeeping_ctx` (deposit U256::MAX) and a `NullFunder`, so a `drive` over the unpaid source terminates instead of re-drawing forever (THE CRUX). Adds `BackendSource::ledger()` so the source and driver share one ledger. Tests: a full-miss local pull terminates under a hard timeout and fills the cache byte-exact (the no-hang proof, 0.085s); an origin transport fault and a corrupt origin each terminate with `Err` without hanging. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…fa.3a) Add `serve_via_backend_origin`, the local twin of the peer window path (`serve_via_window_pull_through`) with every paid-upstream axis stripped and no tee: it fills the cache from this node's own fs/http/s3 origin via the unpaid `run_local_pull_leg` (FA.2) beside `serve_leg` (reused verbatim), streaming a coherent hash-verifying whole-blob delivery to the paying client. Rewire dispatch: the whole-blob own-origin miss gate now confirms serviceability with `origin_size` + `origin_fetch_outboard_bytes` and, when serviceable, serves via `serve_via_backend_origin`; declines/faults degrade to the buffered local populate exactly as before. The tee-based `TeeOpen::InFlight` coalescing arm is dropped on this branch (the local pull fills via the cache, not a tee; B3 owns range-aware coalescing). Delete the node-side fused path now dead after the rewire: `serve_via_local_outboard`, `window_forward_loop`, `abandon_window_serve`, `handlers/client/source.rs` (`ProgressiveSource`), and the now-orphaned `leech_record_pulled`. `TeeReservation`/`open_tee_sink` stay (peer path uses them); the cache-crate `LocalOutboardPull`/`TeeSink` machinery is left for FA.3b. Preserves mid-stream takedown, client-disconnect, the `local_outboard_serve` metric, and the interior-hold shared-outboard seed. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…s (flow a fa.3b part a+c) After FA.3a the node fused serve-miss path is gone, leaving open_local_outboard_pull / LocalOutboardPull / LocalOutboardHeader with only cache-test callers. Remove the whole local_outboard_pull module, the engine accessor, the pub use, and the tests that exercised it (local_outboard_pull_streams_full_wire, local_outboard_pull_none_without_outboard, and the both_proof_sources_emit_identical_wire_bytes pull-through test whose source-1 was the deleted pull). Drop the now-unused OriginFetch import. Fix doc/inline comments that named deleted symbols: metrics counters now point at serve_via_backend_origin; the surviving serve_via_window_pull_through comments point at the two-leg serve_leg mechanism instead of the deleted window_forward_loop; the stream-while-store e2e narrative no longer names open_local_outboard_pull. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…fa.3b part b) After FA.3a the whole-blob node tee is gone; TeeSink and TeeReservation::begin had only cache-test callers. The compiler confirms the separation from the alive stream-import machinery is clean: removing TeeSink, begin, and the tee-exclusive bao_decoded_source leaves the survivors (import_and_verify_stream, ChannelRecvStream, StreamCommitOutcome, BaoVerifyMarker, admit_bao_stream) compiling under -D warnings with no gutting — only tee-only imports fell out. - Delete TeeSink (struct/impl/Drop), TeeReservation::begin, bao_decoded_source, and the five .begin()-driven tests plus their header_less helper. - TeeReservation is now a pure coalescing guard: drop the begin-only `active` field; Drop always releases the in-flight claim. open_tee_sink / TeeOpen / TeeReservation / abandon stay for the peer serve-miss path. - Keep the (now-vestigial-but-defensive) is_bao_verify_marker check and BaoVerifyMarker in import_and_verify_stream, per the survivor keep-list. - Rename TEE_SINK_CHANNEL_CAP -> ADMIT_STREAM_CHANNEL_CAP (its sole remaining user is admit_bao_stream); drop orphaned bao-decoder imports. - Reword doc/inline comments on the surviving tee machinery to describe the admit_bao_stream / two-leg reality instead of the deleted TeeSink. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…sts (flow a fa.4) Add two `cdn/client/v1` loopback integration tests for the own-origin two-leg serve path, mirroring the FA.3a full-miss test and reusing its harness: - interior_hold_own_origin_miss_pulls_only_the_gaps: the node already holds an aligned interior range; the whole-blob serve pulls ONLY the surrounding gaps from origin (asserts zero ranged GETs overlap the held span, both gaps are drawn), the client gets the whole blob byte-exact, and the own-origin tier fires once. Proves range-minimized pull + the shared-outboard held-range seed. - own_origin_serve_fails_not_hangs_on_origin_fetch_error: serviceability passes and ok:true is signed, but the ranged data GET returns 500; wrapped in a timeout so a hang is a failure. Asserts the client sees a delivery error, not a clean blob — the integration twin of FA.2's run_local_pull_leg no-hang unit. Own-origin cold-serve anvil-e2e is already covered by origin_stream_while_store journey 1 (same serve_via_backend_origin tier), so no duplicate e2e was added. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…anch serve_via_backend_origin dropped the in-flight double-pull claim its peer twin serve_via_window_pull_through keeps, so two concurrent same-hash whole-blob own-origin misses each spawned a local pull leg and admitted the same hash concurrently (double origin egress). Mirror the peer path exactly: dispatch wraps the serve in an open_tee_sink match (Owner serves passing the reservation; InFlight awaits the coalesced fill then serves from store), and serve_via_backend_origin holds the TeeReservation as the guard, abandoning it on every early return and at teardown. Serviceability is probed before the claim so a non-serviceable origin degrades without taking a slot. Adds concurrent_whole_blob_own_origin_misses_coalesce_to_one_pull: two staggered same-hash whole-blob requests coalesce to one origin ranged GET, both clients get the blob byte-exact. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Flow A deleted bao_decoded_source, the sole constructor of the private BaoVerifyMarker type. With no constructor, is_bao_verify_marker could never return true, so its branch in import_and_verify_stream was unreachable and StreamCommitOutcome::VerifyFailed had no producer. Delete the marker struct and its impls, the predicate fn, the unreachable branch, and the now-producerless VerifyFailed variant (plus its sole defensive consumer arm in the pull-through outcome mapping). Corruption is still caught by the whole-blob actual != hash check (HashMismatch) on the origin path and by classify_import_bao_reader_error (CacheError::VerifyFailed) on the admit_bao_stream path. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Warning Review limit reached
Next review available in: 32 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (2)
WalkthroughThe cache now uses verified origin range fetching and direct Bao admission. Node requests use backend-origin filling with separate pull and serve legs, shared coalescing, explicit cancellation, and hard verification failures. New tests cover full misses, partial gaps, failures, outboard lookup, and concurrent requests. ChangesBackend-origin streaming
Estimated code review effort: 5 (Critical) | ~90+ minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant Dispatch
participant CacheEngine
participant BackendSource
participant ServeLeg
participant PullLeg
Client->>Dispatch: request blob
Dispatch->>CacheEngine: probe origin size and outboard
CacheEngine-->>Dispatch: serviceability result
Dispatch->>ServeLeg: start backend-origin response
Dispatch->>PullLeg: start local cache fill
PullLeg->>BackendSource: fetch and verify Bao ranges
BackendSource->>CacheEngine: commit verified ranges
ServeLeg-->>Client: stream verified blob
PullLeg-->>ServeLeg: publish completion or fault
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Coverage reportTotal: 80.46% (was 80.17%, ▲ +0.29%) — 62443/77608 lines
History
|
There was a problem hiding this comment.
Pull request overview
This PR unifies the node’s own-origin (fs/http/s3) cache-miss serve path with the existing two-leg serve-miss spine (pull leg + serve leg), and removes the last remaining fused window_forward_loop-based local-outboard implementation. It introduces an unpaid own-origin BlobSource (BackendSource) that feeds verified header-less bao wire into the same cache-admit + coherent serve machinery used for peer pulls.
Changes:
- Add Flow A unpaid own-origin pull leg (
run_local_pull_leg) andBackendSource: BlobSource, routing own-origin miss serves throughdrive()+serve_leg. - Remove the fused local-outboard streaming path and associated types (
window_forward_loop,ProgressiveSource,LocalOutboardPull,TeeSink, etc.). - Add/adjust integration + unit coverage for own-origin full miss, interior-hold gap minimization, no-hang on origin failure, and coalescing.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/tests/origin_range_pull.rs | Adds Flow A integration tests (full miss, interior-hold gap minimization, no-hang, coalescing). |
| crates/node/src/node_origin/pull_leg.rs | Adds unpaid own-origin pull leg (run_local_pull_leg) and bookkeeping funder/context. |
| crates/node/src/node_origin/mod.rs | Exposes BackendSource + run_local_pull_leg for Flow A orchestration. |
| crates/node/src/node_origin/backend_source.rs | Implements unpaid BlobSource over CacheEngine::origin_encode_range with local ledger completion. |
| crates/node/src/metrics.rs | Updates tier naming/documentation for serve_via_backend_origin. |
| crates/node/src/handlers/client/window.rs | Replaces serve_via_local_outboard + window_forward_loop with serve_via_backend_origin two-leg orchestration. |
| crates/node/src/handlers/client/dispatch.rs | Updates dispatch routing and serviceability probe logic for own-origin two-leg serves. |
| crates/node/src/handlers/client/mod.rs | Removes now-dead client handler source module wiring (source.rs / TeeSink usage). |
| crates/node/src/handlers/client/fill.rs | Removes leech_record_pulled helper (accounting moved into pull-leg pacer). |
| crates/node/src/handlers/client/source.rs | Deletes ProgressiveSource (no longer needed after fused loop removal). |
| crates/e2e/tests/origin_stream_while_store.rs | Updates e2e test docs to reflect serve_via_backend_origin. |
| crates/cache/tests/serve_store.rs | Updates test comment to reflect new reference-encoding pattern. |
| crates/cache/tests/pull_through.rs | Removes wire-equivalence test that depended on open_local_outboard_pull. |
| crates/cache/src/local_outboard_pull.rs | Deletes LocalOutboardPull implementation (fused path removed). |
| crates/cache/src/lib.rs | Removes local_outboard_pull exports and updates crate-level docs. |
| crates/cache/src/engine.rs | Adds Flow A origin fetch/encode helpers (origin_encode_range, origin_fetch_outboard_bytes) and removes tee-sink machinery. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| Err(e) => { | ||
| // The pull could not start: record a terminal error and | ||
| // wake the serve leg so it fails a gap rather than hanging. | ||
| if let Ok(mut guard) = pull_result.lock() { | ||
| *guard = Some(Err(anyhow::anyhow!( | ||
| "serve-miss local pull runtime build failed: {e}" | ||
| ))); | ||
| } | ||
| pull_ended.notify_waiters(); | ||
| } |
There was a problem hiding this comment.
Fixed. The runtime-build-failure arm now writes pull_result through unwrap_or_else(std::sync::PoisonError::into_inner) instead of if let Ok(..), so pull_result is always Some(..) before pull_ended fires (a poisoned lock no longer leaves it None while the serve encoder waits on a permit-less notify_waiters). Applied to both this local twin and the identical peer twin (serve_via_window_pull_through), which shared the same latent hang.
| pub async fn origin_fetch_outboard_bytes( | ||
| &self, | ||
| hash: Hash, | ||
| total_bytes: u64, | ||
| ) -> CacheResult<Option<Bytes>> { | ||
| let outboard_max = expected_outboard_len(total_bytes).saturating_add(64); | ||
| for origin in &self.inner.origins { | ||
| match origin.fetch_outboard(hash, outboard_max).await { | ||
| Ok(OutboardFetch::Found(ob)) => return Ok(Some(ob)), | ||
| Ok(OutboardFetch::NotFound | OutboardFetch::Unsupported) => {} | ||
| Err(e) => { | ||
| tracing::debug!( | ||
| %hash, | ||
| kind = ?origin.kind(), | ||
| error = %e, | ||
| "origin outboard fetch failed; trying next origin", | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| Ok(None) | ||
| } |
There was a problem hiding this comment.
Fixed. origin_fetch_outboard_bytes now remembers a genuine per-origin transport Err and returns it (as CacheError::OriginError) when NO origin serves the outboard, so the dispatch.rs Err(e) arm that latches fault_seen (#1129) is now reachable — an outboard-probe transport fault terminates a resulting own-origin miss as InternalError, not a bare NotFound. A clean decline (all NotFound/Unsupported) still returns Ok(None) and degrades silently. Added a cache unit test (origin_fetch_outboard_bytes_surfaces_a_transport_fault). (Note: the pre-existing origin_size probe still swallows per-origin faults by the same best-effort convention; a genuine fault there is re-latched downstream by try_local_populate — left unchanged as out of scope for this PR.)
…e-build failure; surface outboard-probe transport faults Two Copilot review findings on the Flow A two-leg serve path: - The pull-thread runtime-build-failure arm wrote `pull_result` via `if let Ok(guard)`, so a poisoned lock left it `None` while still firing `pull_ended` — and `notify_waiters` stores no permit, so a late-waking serve encoder would hang. Write through `unwrap_or_else(PoisonError::into_inner)` so `pull_result` is ALWAYS `Some(..)` before `pull_ended`, matching the recover-poison the pull legs already use. Applied to both the own-origin twin (`serve_via_backend_origin`) and the identical peer twin (`serve_via_window_pull_through`). - `CacheEngine::origin_fetch_outboard_bytes` swallowed every per-origin transport `Err` and returned `Ok(None)`, making the `dispatch.rs` `Err` arm that latches `fault_seen` (#1129) unreachable — an outboard-probe transport fault was misclassified as a clean degrade (a resulting own-origin miss would report `NotFound` instead of `InternalError`). Remember the last transport fault and return it when NO origin serves the outboard; a clean `NotFound`/`Unsupported` decline still degrades via `Ok(None)`. Adds `origin_fetch_outboard_bytes_surfaces_a_transport_fault`. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Summary
Routes the node's own-origin (fs/http/s3) cache-miss serve path through the same
two-leg
drive()+serve_legmachinery the node→node peer path already uses(merged in #1651), then deletes the last fused
window_forward_loopcaller — sothere is now one serve spine for every source.
A cache miss the node can fill from its own configured origin now runs a
pull leg (
run_local_pull_leg→decdn_client_pull::driveover a newBackendSource, filling the cache) beside a serve leg (serve_leg, reusedverbatim — streams the filling cache to the paying client, gated on the PAID
frontier). The fused
serve_via_local_outboard/window_forward_loop/ProgressiveSource/LocalOutboardPull/TeeSinkpath is deleted.What changed
BackendSource: BlobSource(innode, notclient-pull— CLI binary-split regression: publisher links cache crate (iroh-blobs/AWS SDK) #578): presentsown-origin content as header-less interleaved bao wire per
AlignedRange, so theexisting
NodeAdmitStore/admit_bao_streamsink verifies-and-stores it againstthe blake3 root exactly as the peer path does. A corrupt/misconfigured origin
fails the pull with
VerifyFailed, scored as a local-origin fault (there isno upstream). New cache surface:
origin_encode_range,origin_fetch_outboard_bytes.run_local_pull_leg: the no-payment pull leg. No channel / discovery / ledger/
Funder. Reuses the shared coordination (served_paid/pull_ended/pull_result/ cancel +SharedOutboardcapture) and the cancel/drain teardown.Keeps the downstream
WindowPacerbound onserved_paid(Remove speculative client-less background warm (unpaid-egress → paid-ingress deposit-drain surface) #1610 + storage/egressexposure) — the free upstream still never runs unboundedly ahead of the paying
client.
serve_via_backend_origin: the own-origin serve orchestration, mirroring thepeer twin
serve_via_window_pull_throughminus the paid-upstream axes. Reusesserve_legverbatim; keeps the interior-hold shared-outboard seed, mid-streamtakedown, and client-disconnect handling; holds an
open_tee_sinkreservation asthe whole-blob same-hash coalescing guard (matching the peer path and the old path).
serve_via_local_outboard,window_forward_loop,abandon_window_serve,ProgressiveSource(wholehandlers/client/source.rs),open_local_outboard_pull/LocalOutboardPull/LocalOutboardHeader(
cache/src/local_outboard_pull.rs), and the now-deadTeeSink/TeeReservation::beginplaintext-import machinery. Keptopen_tee_sink/TeeOpen/TeeReservation(the coalescing guard the peer pathstill uses). Also removed the vestigial
BaoVerifyMarker/StreamCommitOutcome::VerifyFailed(producer deleted with the tee).The unpaid pull leg completes because
drive's per-gap completion is paid-frontiergated:
BackendSourceself-advances a local bookkeeping ledger onfinishbythe leg's header-stripped wire bytes at rate 0 (no channel/voucher/chain — matches
the
ScriptedSource::payingprecedent). The real downstream payment path(
serve_leg, the client's own channel) is untouched.Tests
client gets the whole blob byte-exact (asserts the held range is read locally, not
re-fetched — proves range-minimization + the shared-outboard held-range seed).
the pull-leg level + integration at the serve level, timeout-guarded).
pull.
origin_stream_while_store(3 journeys) now exerciseserve_via_backend_originend-to-end and pass.Full workspace
cargo build/clippy --all-targets -D warnings/nextest/fmtgreen.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests