Skip to content

feat(node): multi-observer coalescing for the serve-miss (B3, #1656) - #1660

Merged
alpergundogdu merged 13 commits into
mainfrom
claude/xenodochial-pare-a46ac2
Aug 12, 2026
Merged

alpergundogdu merged 13 commits into
mainfrom
claude/xenodochial-pare-a46ac2

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

B3 — multi-observer coalescing (one upstream pull → N paying serve legs)

Closes the remaining Phase B work after Flow A (#1655). One upstream (or own-origin) serve-miss pull now feeds N downstream clients that want overlapping bytes, each paying its own egress on its own payment channel — removing the redundant second upstream pull when requested ranges overlap. Disjoint requests keep opening their own pulls (already correct).

Implements the design locked in #1656, with one refinement agreed during authoring (see Design).

Design

  • Cache-owned coalescing (honors B3: multi-observer coalescing (one upstream pull → N paying serve legs) #1656 decision 2, via relocation). The node's SharedOutboard was a redundant mirror of proof nodes the cache already produces (outboard_pairs). So the shared outboard + a new FillSession terminal-signal + a range-aware FillRegistry were relocated into cache (crates/cache/src/fill_session.rs); capture now happens inside admit_bao_stream. node keeps only pull-driving (mark_ended) and the N per-observer serve legs. This is source-agnostic — it serves both the paid peer pull and the own-origin (S3/fs/http) pull, where not double-pulling a range is a direct egress-cost saving.
  • Atomic claim closes the coalescing race. FillRegistry::claim decides attach-vs-own and registers under one map-lock acquisition, so two concurrent same-hash misses can't both open a pull. First miss = Owner (opens one pull); later overlapping miss = Attach (runs its own serve_leg over the shared FillSession, no second pull).
  • Two-tier pacing (ADR 037, B3: multi-observer coalescing (one upstream pull → N paying serve legs) #1656 decision 1/B). The shared pull's WindowPacer binds on the max-over-live-observers PAID content frontier (the fastest payer covers the one-time upstream cost — tightest correct exposure), with the LeechGovernor as the node-wide breaker: window-full → pause (Wait), leech-cap → terminal Refuse. Each serve leg keeps its own per-channel credit window unchanged.
  • Lease-driven teardown (Remove speculative client-less background warm (unpaid-egress → paid-ingress deposit-drain surface) #1610). Pull + observers hold observer leases; the last observer leaving cancels the session's CancellationToken, stopping the pull — no orphan ingest. Cancellation is never unilateral, so a live observer is never cut off.
  • Deleted the old hash-coarse machinery — open_tee_sink / TeeOpen / TeeReservation / await_coalesced_fill. (The origin-fetch inflight map used by populate/get is kept.)

Scope — conservative cut. Only full/subset overlaps coalesce (the common case — identical/subset requests). A genuinely partial overlap opens a whole-R pull as today. The registry is range-aware from day one, so lifting the cut later is the deferred per-hash-HashOutboard + await_or_fail work; it never wedges or double-bills in the shipped scope.

Incentive sign-off

(a) One pull, node-owned exposure. The shared pull's exposure = pulled − max-over-observers(served_paid) ≤ pull_ahead_bytes (ADR 037 window), node-wide unrecouped ≤ max_unrecouped_leech_bytes (LeechGovernor). Pacing gates on the PAID frontier (advanced only on committed vouchers), never the delivered frontier. Backed by window_pull_through_concurrent_same_hash_single_upstream_pull (asserts exactly one upstream pull, by count) + the LeechPacer unit tests.

(b) N independent per-channel ledgers, no cross-client leakage. Each serve_leg owns its own ChannelDeliveryState + voucher collection over its own send stream, metering only bytes that client received. The shared FillSession carries no per-client billing counter — only tree geometry, the terminal signal, and one AtomicU64 pacing frontier (a content offset for the pull's window, never an amount-owed). Proven end-to-end by the anvil-e2e test below (two distinct channels, each settling a non-zero, near-equal amount).

(c) Abandoned-pull exposure = the leech budget and nothing more. When the last observer leaves before completion, its ObserverLease drop cancels the session token, stopping the pull (no orphan ingest, no from-zero speculative warm). Unit-tested (last_observer_leaving_cancels, last_observer_leaving_removes_session, teardown_decrement_and_cancel_are_lock_serialized).

Testing

  • Unit (cache): range-aware claim/fill_plan (same-range / disjoint / subset / superset / partial-overlap), lease teardown + the resurrection-race serialization, relocated outboard round-trip/await/terminal.
  • Node: pacing contract (Wait on window vs Refuse on leech cap); the existing peer-path window_pull_through_concurrent_same_hash_single_upstream_pull passes unmodified (proves end-to-end peer coalescing); own-origin one-fetch coalescing (fetch_range count == 1, two byte-exact deliveries).
  • anvil-e2e (coalesce_two_clients.rs): two real paying clients coalesce onto one upstream fill; both byte-exact; two distinct channels each settling a non-zero, near-equal amount (no cross-billing). Passes, 37.3s.
  • Full workspace gate green: cargo build && cargo clippy --all-targets -- -D warnings && cargo nextest run (2924 passed) && cargo fmt -- --check + cargo test --no-run -p decdn-e2e --features anvil-e2e.

Follow-ups (documented, not silent)

  • Partial-overlap de-dup (lift the conservative cut) — needs the per-hash HashOutboard + await_or_fail; its precondition is fixing the latent multi-session-union attach (an attach binds to a single best-overlap session, which is always safe under today's whole-blob gating but must become union-covering before range serving lands).
  • Node-to-node paid coalescing e2e — the harness can't fund a NodeFixture as a USDC buyer or wire cross-node discovery; (b) is proven via the source-identical own-origin path meanwhile.
  • Owner accept-task join hand-off to the last-out observer; peer-Attach peek-registry-before-handshake; an evict_under_inflight_lease test (reader-pinning is unchanged by coalescing).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Concurrent requests for the same content can now share an in-progress cache fill, including overlapping ranges.
    • Requests can begin receiving shared data while the original fetch is still completing.
    • Shared proof and progress handling improves streaming consistency across concurrent requests.
  • Bug Fixes

    • Improved cancellation and failure handling when a shared fetch ends unsuccessfully.
    • Prevented stalled or duplicate origin pulls during concurrent cache misses.

alpergundogdu and others added 9 commits August 12, 2026 10:51
…-state into cache (B3.1)

Move SharedOutboard/OutboardWriter/OutboardReader + the pull_ended/pull_result
terminal pair out of node/src/node_origin/serve_outboard.rs into a new
cache-resident FillSession (crates/cache/src/fill_session.rs). The whole-tree bao
outboard, its capture, the terminal mark_ended/outcome signal, and the shared
downstream paid frontier are now session-owned; both serve-miss legs hold one
Arc<FillSession>. Capture moves into CacheEngine::admit_bao_stream (node threads
the session in). The #1651 await/terminal-race logic moves verbatim. No coalescing
or registry yet (B3.2); behavior preserved (node+cache 1320 tests green).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…3.2)

Add FillRegistry to the cache: a serve-miss of range R against the live
in-flight fills for a hash splits into attach = R ∩ covered_union (bytes an
in-flight pull already produces — attach an observer) and remainder = R −
covered_union (bytes no live pull covers — fetch them). Binds the attach handle
to the largest-overlap session and hands back an RAII ObserverLease whose
last-out drop cancels the pull (via CancellationToken) when no observer remains
while the pull is still running (#1610).

FillSession gains covered (set at registration), an observer count, and a
cancel token; new(root, total) keeps working unchanged for existing callers.
CacheEngine holds an Arc<FillRegistry> and exposes fill_plan / register_fill.
No live-pull wiring yet — that is B3.4.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…B3.2)

ObserverLease::drop decremented the observer count and fired cancel()
lock-free, while add_observer ran under the FillRegistry map lock. That
opened a resurrection race (a concurrent fill_plan could fetch_add a
session 0->1 between a last-out fetch_sub 1->0 and its cancel(), binding
a live observer to an aborting fill) and let fill_plan attach to sessions
already ended or cancelled.

- ObserverLease now holds Weak<FillRegistry> + Hash; its drop takes the
  registry map lock before the decrement + cancel decision, the same lock
  fill_plan/register_fill hold to attach, so the two are mutually
  exclusive. Upgrade-fail (registry gone) => fill moot, skip.
- Lease minting moves to FillRegistry::mint_lease under the map lock;
  register_fill/fill_plan take self: &Arc<Self> (engine.rs unchanged).
- fill_plan skips dead sessions (ended or cancelled) for both covered_union
  and the attach target.

Tests: fill_plan_skips_cancelled_session, fill_plan_skips_ended_session,
teardown_decrement_and_cancel_are_lock_serialized; four canonical registry
tests kept green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…cap) (B3.3)

LeechPacer already composes WindowPacer (money + ADR 037 window) with the
LeechGovernor's node-wide admission gate, overriding only a Draw with a
terminal Refuse on leech-cap denial. Pin that contract with two unit
tests, both green on first run (confirmation, not a behavior change):
window-full pauses (Wait) rather than terminally refusing, so a
coalesced pull with live observers is never killed by a transient
window-full state; a genuine LeechGovernor denial is the only source of
a terminal Refuse and latches `refused` so run_pull_leg skips provider
scoring.

Also documents that the served_paid frontier the pacer's WindowPacer
bounds against is, under coalescing, the shared max-over-live-observers
paid content frontier (DECISION-B) — a solo pull is the N=1 case. The
actual fetch_max frontier-advance wiring is B3.4's job.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
… fetch_max (B3.4a)

Two substrate changes making the shared FillSession safe for N concurrent
observer serve legs (prerequisite for B3.4b orchestration wiring).

1. serve_leg's shared paid-frontier write becomes fetch_max (was store), so
   N observers advancing the SHARED frontier cannot regress each other; the
   pull's WindowPacer binds on the MAX-over-observers paid frontier
   (DECISION-B). Behavior-preserving for N=1 (a single contiguous delivery is
   already monotone, so fetch_max == store).

2. ObserverLease::drop now removes the session from the registry map on
   last-out (prev == 1), by Arc pointer identity so a sibling session for the
   same hash survives; the hash key is dropped when its Vec empties. Fixes a
   slow leak where dead sessions accumulated in the map forever (fill_plan
   skipped them via is_dead but never freed them). Removal + cancel run under
   the held map lock; cancel still fires on last-out while the pull runs.

Tests: last_observer_leaving_removes_session (map-key inspection is the
discriminating check, since fill_plan already skips dead-but-mapped sessions
via is_dead) and removing_one_session_keeps_a_sibling_for_the_same_hash.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…3.4b)

Add FillRegistry::claim: decide attach-vs-own AND register a fresh
FillSession under ONE map-lock acquisition, closing the coalescing TOCTOU
race that the separate fill_plan (read) + register_fill (write) calls
leave open. Two concurrent identical fresh misses can no longer both see
an empty registry and both open a pull.

FillClaim { Attach, Owner } carries the target session + observer lease.
make_session is a closure so the outboard buffer is built only on the
owner branch, never built-and-dropped on attach. The owner covers the
WHOLE R (conservative cut). Add FillSession::total_bytes() so the attach
path signs its StreamResponse without re-running the header handshake.
CacheEngine::claim_fill forwards to the registry. fill_plan/register_fill
kept (additive). Cache-only; orchestration wiring is B3.4c.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
… delete open_tee_sink (B3.4c)

Both serve-miss orchestrations (serve_via_window_pull_through peer and
serve_via_backend_origin own-origin) now claim the fill atomically via
CacheEngine::claim_fill instead of holding a hash-coarse TeeReservation. After
signing the StreamResponse, each miss either OWNS a fresh pull for the hash or
ATTACHES as an observer to a live same-hash fill, so two concurrent same-hash
misses share ONE upstream/origin fetch while each keeps its own per-channel
voucher stream. serve_leg is already session-based (B3.1), so an attach is just a
serve_leg over the shared FillSession.

Teardown is lease-driven: the pull thread receives the session's shared cancel
token; the owner drops its ObserverLease after serve_leg (last-out cancels the
pull, #1610; otherwise the pull keeps filling for remaining observers) then joins
the bounded pull thread. The attach path drops its lease with no thread to join.

Deletes open_tee_sink / TeeOpen / TeeReservation (and their tests + re-exports),
the two dispatch TeeOpen::Owner/InFlight branches, and the now-unused
await_coalesced_fill. Keeps the inflight origin-fetch map used by populate/get.

Adapts the own-origin coalescing integration test to the new semantics (one
origin fetch, two live serve legs) and adds a disjoint two-hash no-wedge test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
… own egress (B3.5)

Two independently-funded cdn/client/v1 buyers fetch the same missing blob
from one pull-through node concurrently. The node runs the range-aware
coalescing serve-miss (CacheEngine::claim_fill): the first miss owns the
single own-origin fill, the overlapping second attaches as an observer and
streams the same filling cache, each metering its own egress over its own
channel and voucher collection. Asserts both misses enter the coalescing
serve tier, both clients get the blob byte-exact, the two channels settle
independently and near-equal (no cross-client leakage), and the concurrent
misses promote one shared cache entry.

The node-to-node paid-upstream variant is not expressible in this harness:
a NodeFixture is funded only for its seller/operator role (a TOKEN capacity
bond), never as an upstream-paying buyer, and there is no cross-node
discovery wiring. The own-origin path exercises the identical claim_fill /
FillSession machinery, so the downstream money property proven here (N
independent per-channel ledgers) is the same. The strict one-pull count and
abandoned-pull leech bound are discharged by the node-level test
window_pull_through_concurrent_same_hash_single_upstream_pull and the
fill_session.rs unit tests.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…val (B3)

Comments in node_origin_pull.rs, node_to_node_pull_through.rs,
origin_range_pull.rs, dispatch.rs, and coalesce_two_clients.rs still
described the deleted open_tee_sink/TeeOpen/await_coalesced_fill
mechanism. Update the prose to describe CacheEngine::claim_fill's
Owner/Attach split, and soften an over-claiming assertion-4 doc comment
in coalesce_two_clients.rs. Comments and doc text only; no logic or
assertions changed.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 12, 2026 12:53
@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@alpergundogdu, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 3af13ecb-dc96-4114-8f76-68139118ac64

📥 Commits

Reviewing files that changed from the base of the PR and between 89abcf1 and da7e9bd.

📒 Files selected for processing (12)
  • crates/cache/src/fill_session.rs
  • crates/node/Cargo.toml
  • crates/node/src/handlers/client/dispatch.rs
  • crates/node/src/handlers/client/mod.rs
  • crates/node/src/handlers/client/serve_encoder.rs
  • crates/node/src/handlers/client/serve_leg.rs
  • crates/node/src/handlers/client/window.rs
  • crates/node/src/metrics.rs
  • crates/node/src/node_origin/mod.rs
  • crates/node/src/node_origin/pull_leg.rs
  • crates/node/src/runtime/mod.rs
  • crates/node/tests/node_origin_pull.rs
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: fd473ece-326f-4d51-9478-60327a1ad110

📥 Commits

Reviewing files that changed from the base of the PR and between 40a12a4 and 89abcf1.

📒 Files selected for processing (17)
  • crates/cache/src/engine.rs
  • crates/cache/src/fill_session.rs
  • crates/cache/src/lib.rs
  • crates/e2e/tests/coalesce_two_clients.rs
  • crates/node/src/handlers/client/dispatch.rs
  • crates/node/src/handlers/client/fill.rs
  • crates/node/src/handlers/client/mod.rs
  • crates/node/src/handlers/client/serve_encoder.rs
  • crates/node/src/handlers/client/serve_leg.rs
  • crates/node/src/handlers/client/window.rs
  • crates/node/src/node_origin/admit_store.rs
  • crates/node/src/node_origin/mod.rs
  • crates/node/src/node_origin/pull_leg.rs
  • crates/node/src/node_origin/serve_outboard.rs
  • crates/node/tests/node_origin_pull.rs
  • crates/node/tests/node_to_node_pull_through.rs
  • crates/node/tests/origin_range_pull.rs
💤 Files with no reviewable changes (3)
  • crates/node/src/handlers/client/fill.rs
  • crates/node/src/node_origin/mod.rs
  • crates/node/src/node_origin/serve_outboard.rs

Walkthrough

This change replaces tee-sink coalescing with range-aware FillSession coordination. It adds atomic owner-or-observer claims, shared Bao outboard capture, session-based pull state, updated serving paths, and end-to-end coalescing tests.

Changes

Shared fill coordination

Layer / File(s) Summary
Fill session and registry primitives
crates/cache/src/fill_session.rs, crates/cache/src/engine.rs, crates/cache/src/lib.rs
Adds FillSession, FillRegistry, observer leases, range planning, atomic claims, session outboard readers, and public cache APIs. Removes tee-sink APIs.
Session-backed pull ingestion
crates/node/src/node_origin/admit_store.rs, crates/node/src/node_origin/pull_leg.rs, crates/node/src/node_origin/mod.rs
Passes shared sessions through admission and pull legs. Captures proof nodes, publishes paid progress, and records terminal outcomes through FillSession.
Claim and attach serving orchestration
crates/node/src/handlers/client/dispatch.rs, crates/node/src/handlers/client/window.rs, crates/node/src/handlers/client/fill.rs, crates/node/src/handlers/client/mod.rs
Moves peer and backend-origin coalescing into claim_fill. Owner requests run one pull. Observer requests serve from the shared fill.
Session-based frame serving
crates/node/src/handlers/client/serve_encoder.rs, crates/node/src/handlers/client/serve_leg.rs
Uses FillSession for outboard reads, terminal signaling, pull outcomes, and monotonic paid-frontier updates.
Coalescing integration coverage
crates/e2e/tests/coalesce_two_clients.rs, crates/node/tests/node_origin_pull.rs, crates/node/tests/node_to_node_pull_through.rs, crates/node/tests/origin_range_pull.rs
Covers live same-hash observers, separate-hash pulls, independent settlement claims, exact delivery, and cache promotion.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ClientHandler
  participant CacheEngine
  participant FillSession
  participant UpstreamPull
  ClientHandler->>CacheEngine: claim_fill(hash, range)
  CacheEngine->>FillSession: create or attach observer
  FillSession->>UpstreamPull: run one owner pull
  UpstreamPull->>FillSession: capture proof nodes and mark completion
  FillSession->>ClientHandler: provide shared fill state
Loading

Note

🎁 Summarized by CodeRabbit Free

Your 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 @coderabbitai help to get the list of available commands.

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 implements Phase B3 multi-observer coalescing for serve-miss fills: one upstream pull (peer or own-origin) can now feed N concurrent downstream serve legs for overlapping bytes, while each downstream client continues to pay independently on its own payment channel. The coalescing coordination and shared outboard/terminal signaling are relocated into the cache layer via a new FillSession + range-aware FillRegistry, and node-side code is updated to claim/attach to fills and drive/join the single pull leg.

Changes:

  • Introduces cache-owned FillSession/FillRegistry and threads it through admit_bao_stream so proof-node capture + terminal signaling are cache-resident.
  • Replaces node-side open_tee_sink / TeeReservation coalescing with CacheEngine::claim_fill (Owner vs Attach) in both peer pull-through and own-origin serve-miss paths.
  • Adds/updates integration + e2e tests to assert coalescing behavior (one origin fetch, N concurrent serve legs, independent settlements).

Reviewed changes

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

Show a summary per file
File Description
crates/node/tests/origin_range_pull.rs Updates coalescing tests and adds a disjoint-miss regression test to ensure no wedge and correct origin fetch counts.
crates/node/tests/node_to_node_pull_through.rs Updates documentation to reflect the new serve-miss fill primitive (claim_fill).
crates/node/tests/node_origin_pull.rs Updates comments/expectations to match Owner/Attach coalescing via claim_fill.
crates/node/src/node_origin/serve_outboard.rs Removes node-owned shared outboard implementation (relocated into cache).
crates/node/src/node_origin/pull_leg.rs Switches pull-leg coordination from ad-hoc atomics/notifies to FillSession and adds LeechPacer contract tests.
crates/node/src/node_origin/mod.rs Removes exports for the deleted node-owned outboard types.
crates/node/src/node_origin/admit_store.rs Passes an optional FillSession into admit_bao_stream so cache capture happens during admit.
crates/node/src/handlers/client/window.rs Replaces tee-based coalescing with claim_fill Owner/Attach orchestration for peer and own-origin serve-miss.
crates/node/src/handlers/client/serve_leg.rs Advances a shared served_paid frontier via FillSession (using fetch_max under coalescing).
crates/node/src/handlers/client/serve_encoder.rs Migrates the coherent encoder to use cache-provided SessionOutboardReader + session terminal signal.
crates/node/src/handlers/client/mod.rs Removes tee/coalescing types from imports now that tee-based coalescing is gone.
crates/node/src/handlers/client/fill.rs Deletes await_coalesced_fill since coalescing is now live attach rather than park-and-wait.
crates/node/src/handlers/client/dispatch.rs Removes open_tee_sink gating and routes directly to new orchestration that claims fills internally.
crates/e2e/tests/coalesce_two_clients.rs Adds anvil-e2e proof that two clients coalesce onto one fill while settling independently on distinct channels.
crates/cache/src/lib.rs Exposes the new fill-session API surface from the cache crate.
crates/cache/src/fill_session.rs Adds cache-owned FillSession, shared outboard reader, observer leases, and range-aware FillRegistry/claim.
crates/cache/src/engine.rs Adds fill-registry plumbing, exposes claim/plan/register APIs, and captures outboard proof nodes during admit_bao_stream.
Suppressed comments (1)

crates/node/src/handlers/client/window.rs:753

  • Same race as the peer Attach path: an attaching request can start serving before the Owner finishes best-effort seeding the FillSession with outboard proof nodes for already-present (held) ranges. Since held ranges are not re-admitted by the pull, the coherent encoder can later fail with “outboard node … was never captured”. Seeding on Attach is idempotent and prevents attach-before-seed failures.
            // ATTACH: a live same-hash pull already covers this request. Run a serve leg
            // over the shared session — NO new pull, NO thread, NO held-range seed (the
            // owner does all that). This is the S3-egress saving: the observer streams
            // the cache the owner fills from origin, so the origin is fetched once.
            decdn_cache::FillClaim::Attach { session, lease } => {

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

…changelog voice)

Rewrite serve-miss / pull-leg / serve-leg / coalescing / fill comments as
present-tense documentation of what the code IS. Remove references to the
retired fused serve path, window_forward_loop, SpanProducer, upstream tee, and
"re-homed"/"lifted verbatim"/"the old path" narrative, plus project-phase
labels (B2/B3, Flow A/FA.x, Strategy B, Path A, Task N). Correct the stale
serve_via_window_pull_through gate rationale: the byte_offset==0 && byte_len==0
gate is a conservative routing constraint, not a serve_leg limitation
(serve_leg clamps to the requested span; the pull leg is range-minimized).

Comments and doc-comments only; no code, test-assertion, or logic changes.

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

github-actions Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.56% (was 80.44%, ▲ +0.12%) — 62837/77999 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 91.50% 3455/3776 ▼ 0.14%
crates/cache/src/fill_session.rs 94.57% 627/663 new
crates/cache/src/lib.rs 100.00% 28/28 ● 0.00%
crates/node/src/handlers/client/dispatch.rs 87.71% 371/423 ▲ +1.61%
crates/node/src/handlers/client/fill.rs 67.19% 86/128 ▲ +2.19%
crates/node/src/handlers/client/mod.rs 89.25% 523/586 ▲ +0.17%
crates/node/src/handlers/client/serve_encoder.rs 80.28% 114/142 ▼ 0.61%
crates/node/src/handlers/client/serve_leg.rs 91.72% 133/145 ▲ +0.06%
crates/node/src/handlers/client/window.rs 82.76% 360/435 ▲ +5.37%
crates/node/src/metrics.rs 95.67% 1105/1155 ● 0.00%
crates/node/src/node_origin/admit_store.rs 89.00% 186/209 ▼ 0.96%
crates/node/src/node_origin/mod.rs 90.09% 1000/1110 ● 0.00%
crates/node/src/node_origin/pull_leg.rs 86.69% 619/714 ▲ +1.55%
crates/node/src/node_origin/serve_outboard.rs — — deleted
crates/node/src/runtime/mod.rs 46.43% 1094/2356 ● 0.00%
History
Commit Total Δ vs base
b501c50 80.57% ▲ +0.11%
002d93c 80.55% ▲ +0.11%
da7e9bd (HEAD) 80.56% ▲ +0.12%

alpergundogdu and others added 3 commits August 12, 2026 14:34
…fused path)

The node crate's own code hashes content via `bao_tree::blake3`; the standalone
`blake3` crate is now used only by `tests/self_hosted_discovery.rs` to derive a
gossip topic id. Move it to `[dev-dependencies]` so a production build no longer
links it, and drop the stale comment that justified it via the deleted
window-paced pull-through hashing path.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
An attaching serve leg reads held-range proof nodes from the shared FillSession
outboard, which only the owner seeded (before spawning the pull). That is safe
today — the owner's seed completes before any terminal signal an observer can
observe — but it is a subtle non-local invariant. Extract the seed into
`seed_held_outboard` and call it from the Attach branches of both orchestrations
too, so every serve leg seeds the held-range proof its own coherent encoder
reads. Idempotent (capture overwrites the same bytes) and near-free on a full
miss (empty present set short-circuits before `outboard_pairs`). Also DRYs the
previously duplicated seed block across the two Owner branches.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu merged commit 370e5fc into main Aug 12, 2026
28 checks passed
alpergundogdu added a commit that referenced this pull request Aug 12, 2026
…#1656) (#1665)

* test(cache): eviction composes with N coalesced serve-leg readers (B3, #1656)

B3 multi-observer coalescing (#1656, PR #1660) deferred a test for the
decision-5 claim that eviction under in-flight serve legs stays logical and
composes with reader-pinning. Add `evict_mid_serve_lets_coalesced_readers_finish_then_reclaims`:
two in-flight `export_bao_range_stream` readers over one tagged partial, evicted
mid-serve, gated on a control blob's GC reclaim; both readers must still drain
byte-for-byte to the pre-evict wire, then the partial is reclaimed.

The invariant holds — no bug — but the mechanism is subtler than the earlier
mental model of "GC reclaims only after the last reader": the serve leg takes no
TempTag/own GC root, so the partial is protected solely by the admit-path
`decdn-partial-{hash}` named tag. Evict drops it and the next GC sweep deletes
the blob, flipping `blobs().status()` to `NotFound` immediately. In-flight
readers still complete because each holds its own live iroh `export_bao` handle
and the bytes stay reachable through the open fd until it drops (Unix
unlink-while-open; disk space frees on last close). Reader-pinning is therefore
unchanged by coalescing: N readers survive evict + GC exactly as one does.

Test-only. The full two-observer FillSession serve harness stays deferred; the
cache-level two-reader test is the honest reduction of it.

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

* test(cache): assert the target's own reclaim in the evict-composition test (review)

Address PR #1665 review (Copilot):

- Gate the drain on the TARGET hash flipping to `NotFound` while both serve legs
  are still held, instead of on a separate control blob. This turns the
  documented subtlety — the GC sweep deletes the untagged blob and flips its
  logical status without waiting for in-flight readers — into a direct
  assertion, and still proves a sweep ran after the tag drop. Drops the now
  -unneeded control partial.
- Remove the redundant post-drain `wait_reclaimed` (the store already reported
  `NotFound` while the handles were open) and its overstated comment
  (`BlobStatus::NotFound` is a logical view, not a filesystem-usage check).
- Fix a doc line-break that rendered "already -pulled"; state the summary in
  terms of the logical removal rather than disk reclaim.

Test-only; still passes.

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

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
alpergundogdu added a commit that referenced this pull request Aug 12, 2026
…nished owner (#1664)

* perf(node): last-out serve-miss observer joins the pull, freeing a finished owner

Follow-up from B3 multi-observer coalescing (#1660). Both serve-miss
orchestrations (`serve_via_window_pull_through`, `serve_via_backend_origin`)
had the pull OWNER park in `spawn_blocking(pull_thread.join()).await` right
after its OWN serve leg returned. When the owner's client finished first while
an `Attach` observer was still streaming, the owner's accept task stayed blocked
in that join until the pull ended — bounded (the pull ends on fill-completion or
the last observer's lease-drop cancel), but it held the finished owner's
QUIC/accept-task and a blocking-pool thread longer than necessary.

Park the pull-thread `JoinHandle` on the shared `FillSession` and hand it back
only to whichever observer leaves LAST, so a non-last-out owner returns at once:

- `FillSession` gains `pull_thread: StdMutex<Option<JoinHandle<()>>>` with
  `set_pull_handle` (owner parks it after spawn) and private `take_pull_handle`.
- `ObserverLease::release() -> Option<JoinHandle<()>>` shares one `teardown()`
  with `Drop` (idempotent via an `armed` flag). Teardown runs the identical
  last-out decrement + map-removal + cancel UNDER the registry map lock (the
  B3.2 resurrection-race fix), and returns the parked handle only on the last-out
  drop. It TAKES the handle under the lock but never JOINS there; the node's
  async teardown joins off-task via `spawn_blocking`. `detach()` is removed.
- Both orchestrations park the handle on the owner branch and, in every teardown
  (owner and attach), join iff `release()` yields a handle.

Invariants preserved: #1610 (last observer cancels the pull, no orphan ingest),
#852 `SettleOnDrop` buyer-watermark (runs inside the pull leg regardless of
joiner), and the pull thread is always joined by the last-out observer, never
detached.

Mechanism covered by new unit tests in `fill_session.rs`
(`last_out_release_takes_the_pull_handle`,
`last_out_release_without_a_parked_handle_returns_none`).

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

* refactor(cache): set_pull_handle refuses to overwrite a parked pull handle

Address Copilot review on #1664: overwriting an already-parked JoinHandle would
drop the first handle and detach its thread, orphaning a pull that keeps
paying/draining — violating the "always joined" guarantee. It cannot happen
today (FillRegistry::claim returns exactly one Owner per session, so the owner
parks once), but harden the setter against a future regression: keep the first
handle (the one the last-out observer joins) and debug_assert the double-park
loudly in tests/dev.

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

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu deleted the claude/xenodochial-pare-a46ac2 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.

2 participants