Skip to content

feat(node): stream bounded and resumed cache-miss requests through the two-leg spine - #2064

Merged
alpergundogdu merged 25 commits into
mainfrom
feat/2060-stream-bounded-miss
Sep 21, 2026
Merged

alpergundogdu merged 25 commits into
mainfrom
feat/2060-stream-bounded-miss

Conversation

@yigitdot

@yigitdot yigitdot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2060. #2061 (outboard once per fill, minimum draw) is deliberately NOT in this PR — it ships separately; until it lands, the spine re-reads {H}.obao4 per draw and draws per voucher as main already does for whole-blob misses. Also fixes #2062 (the anvil journey bundle_pull_reuses_unchanged_and_splices_changed hit it on every cold spliced tail once bounded requests routed through the spine). Follow-up filed: #2063.

On a cold miss the CLI's real request is byte_len = total_bytes, which dispatch routed to try_range_pull_through: download the whole span + outboard into memory, verify, import, and only then sign StreamResponse. No timeout, no keepalive — a multi-GiB file trips the client's 30 s stall clock while the node is still buffering.

Every authorized miss — whole blob, bounded, resumed — now takes the two-leg spine (serve_via_backend_origin / serve_via_window_pull_through): sign first, pull only the span's missing chunk groups in credit-window draws, stream each verified group as it lands. The buffered range tier and CacheEngine::pull_through_range are deleted.

Spine hardening that the offset-0 gate had been hiding:

  • RampPacer ramps on served_paid − served_start, so a resumed request does not open credit_max before its first voucher.
  • serve_leg maps paid wire back to content from the group-aligned fetch start and guards an attached observer's frontier extension.
  • Both spine functions refuse an out-of-bounds range with RangeNotSatisfiable before signing and price their floor guard at the request's aligned span.

Throwaway-then-real open, and the stalled owner. FillRegistry::claim now attaches a request to a live fill only when the request starts at or behind that fill's paid frontier; a request ahead of it owns its own span, so a tail request no longer starves behind a never-paying opener (pinned by a registry test and an integration test that keeps the opener connected). The CLI's (0,0) prelude open followed by the real (0,total) open is pinned against the fill registry in both claim orderings (attach to a live fill; own a fresh one after teardown). Measured while writing the test: the real open parks in serve_audit → iroh-blobs status(hash) behind the throwaway's in-flight admission of the same hash, so it never sees a dying session — but its TTFB is delayed by the throwaway's first draw. Recorded on #2063, whose fix removes the prelude claim.

Tests: CLI-shaped (0, total) and unaligned-offset misses stream via the own-origin tier; the mixed present/absent range pulls only the missing group; a resumed node→node miss is served by the fused path; two throwaway-open sequences (multi-draw and single-draw); the resumed-offset-refused test is flipped and the range-tier cache tests are gone. Full workspace: 3573 passed (one unrelated warn_throttle timing test retried once).

🤖 Generated with Claude Code

Review fixes (four-agent review, second push)

Gate on the fixed branch: fmt, clippy -D warnings, doc -D warnings, crate edges, 3606 workspace tests, 64 anvil journeys.

yigitdot and others added 13 commits September 19, 2026 11:35
The pull leg's window is paid / divisor, but served_paid is an absolute
content frontier seeded at the request's byte_offset. Subtract the
session's served start so a resumed request ramps from the floor instead
of opening credit_max before its first voucher.

Co-Authored-By: Claude Opus 5 <[email protected]>
Every voucher opens about one chunk of room and wakes the pull, so a fast
origin was driven in one-chunk draws. Once the window has ramped past
PULL_WINDOW_FLOOR, wait until half of it is free (unless a serve leg is
parked at the frontier, or the gap remainder is smaller); the exposure
bound is unchanged and the draw count drops from total / CHUNK_BYTES to
about 2 * total / window. At the floor the minimum is zero, so the
floor's rounding slack stays drawable. Refs #2061.

Co-Authored-By: Claude Opus 5 <[email protected]>
…r draw

Origin::fetch_range returns the data span only; the outboard comes from
fetch_outboard, which the dispatch serviceability probe already performs.
BackendSource carries that outboard and hands it to origin_encode_range on
every draw. Refs #2061.

Co-Authored-By: Claude Opus 5 <[email protected]>
serve_leg maps paid wire back to content from the group-aligned fetch
start and guards an attached observer's frontier extension; both spine
functions refuse an out-of-bounds range before signing and price their
floor guard at the request's aligned span.

Co-Authored-By: Claude Opus 5 <[email protected]>
…e two-leg spine

Dispatch routes every authorized miss — whole blob, bounded range, or
resumed tail — into serve_via_backend_origin / serve_via_window_pull_through.
The signed StreamResponse goes out before the fill; the pull leg fetches
only the span's missing chunk groups; the serve leg streams them as they
land. The buffered try_range_pull_through tier, which downloaded, verified
and imported a whole requested span before answering, is gone.

Closes #2060

Co-Authored-By: Claude Opus 5 <[email protected]>
…fill registry

The throwaway (0,0) open claims a fill and drops it. The real (0,total)
open parks in serve_audit behind the same hash's in-flight admission,
then attaches to the live fill (its teardown is then not last-out) or
owns a fresh one after the teardown — never a dying session. Registry
unit tests pin both claim orderings; two integration tests drive the
CLI's exact sequence on a multi-draw and a single-draw blob.

Co-Authored-By: Claude Opus 5 <[email protected]>
pull_through_range / range_pull_attempt / origin_fetch_range_bytes /
RangePullOutcome have no caller: the node serves every ranged miss
through the two-leg spine, whose BackendSource uses origin_encode_range.
present_ranges tests admit their partial spans directly.

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

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 83.40% (was 83.39%, ▲ +0.01%) — 84547/101370 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 93.15% 5111/5487 ▼ 0.02%
crates/cache/src/fill_session.rs 93.98% 1139/1212 ▼ 0.76%
crates/cache/src/lib.rs 100.00% 28/28 ● 0.00%
crates/cache/src/origin/mod.rs 63.64% 70/110 ▼ 3.64%
crates/cache/src/origin_range.rs 87.95% 365/415 ▼ 0.48%
crates/cache/src/range_pull.rs 100.00% 3/3 ● 0.00%
crates/client-pull/src/driver.rs 94.35% 1453/1540 ● 0.00%
crates/client-pull/src/pacer.rs 98.43% 313/318 ▲ +0.09%
crates/e2e/src/node.rs 30.62% 192/627 ● 0.00%
crates/node/src/handlers/client/dispatch.rs 81.62% 524/642 ▲ +0.56%
crates/node/src/handlers/client/fill.rs 74.22% 95/128 ▲ +0.84%
crates/node/src/handlers/client/mod.rs 94.86% 2012/2121 ● 0.00%
crates/node/src/handlers/client/serve_encoder.rs 92.11% 560/608 ▲ +0.01%
crates/node/src/handlers/client/serve_leg.rs 73.74% 146/198 ▲ +1.66%
crates/node/src/handlers/client/window.rs 71.56% 312/436 ▲ +1.32%
crates/node/src/node_origin/pull_leg.rs 86.64% 759/876 ▲ +0.26%
History
Commit Total Δ vs base
11f02c8 83.05% ▲ +0.03%
d28bae3 83.07% ▲ +0.05%
f90b539 83.16% ● 0.00%
7b10fbd 83.19% ▲ +0.03%
b14fe85 83.18% ▲ +0.02%
a05149b (HEAD) 83.40% ▲ +0.01%

…wn span

FillRegistry::claim attached any request whose range a live fill covered,
even when the request started past that fill's paid frontier. The pull
runs one window past served_paid and parks, and an observer's payments
extend the paid prefix only once it reaches the observer's start, so with
the owner not paying — the CLI's throwaway prelude open on every cold
entry, or any stalled client — the observer starved until its own stall
budget expired. The anvil journey
bundle_pull_reuses_unchanged_and_splices_changed hit this on the spliced
tail (4 MiB in) of b.bin: 30 s stall, twice.

A live session is now an attach candidate only when the request starts
at or behind its paid frontier; otherwise the request owns its own span
and the two fills coexist under the hash. Pinned by a registry test and a
node integration test that keeps a never-paying opener connected while
the tail request is served beside it.

Closes #2062

Co-Authored-By: Claude Opus 5 <[email protected]>
…stream-bounded-miss

Keeps main's streaming, window-bounded origin_range_wire / OriginRangeCursor
as the own-origin pull leg and drops this branch's buffered
origin_encode_range. The buffered pull_through_range tier that #2066
windowed is deleted again: with every miss routed through the two-leg
spine it has no caller, so its RangePullOutcome, second semaphore and
tests go with it. The cursor now takes the outboard dispatch already
probed instead of fetching it on every draw, so a fill reads {H}.obao4
once (own_origin_miss_fetches_the_outboard_once_across_draws holds
against the windowed reader).

Co-Authored-By: Claude Opus 5 <[email protected]>
yigitdot and others added 9 commits September 19, 2026 22:10
… degraded node

CacheEngine::origin_size advances the origin chain past a per-origin
fault but surfaces the last one when no origin answers, mirroring
origin_fetch_outboard_bytes — reviving dispatch's #1129 latch arm, which
was dead: a node whose own origin timed out terminally refused CacheMiss
(NotFound) instead of InternalError. Both dispatch probe-fault arms now
warn and count node_pull_through_errors, so a broken own origin is
visible even while the peer spine masks it.

Co-Authored-By: Claude Fable 5 <[email protected]>
…as a decline

A truncated {H}.obao4 under the size cap passed origin_fetch_outboard_bytes,
so dispatch signed ok: true and every stream for the hash then hard-failed
on the first draw's verify — and a broken origin permanently shadowed a
healthy later one. The probe now compares against expected_outboard_len
and treats a mismatch as a decline that advances the origin chain, so the
node degrades to the buffered whole-blob path before signing. The wire's
in-draw length check stays as the backstop.

Co-Authored-By: Claude Fable 5 <[email protected]>
…own-origin gate hardened

The peer path's pre-signature RangeNotSatisfiable gate judged the
counterparty's unverified handshake total — the deflation twin of the
#1895 inflation attack: an under-reporting holder makes every relay
refuse valid bounded/resumed requests with a client-attributable error.
The gate is gone; a total that cannot satisfy the request surfaces in
serve_leg's own bounds check as a pull-attributed stream fault.

The own-origin twin keeps its gate (the total is this node's own probe)
and runs it BEFORE the floor guard, so an out-of-bounds range answers
RangeNotSatisfiable rather than InsufficientDeposit; its floor guard now
prices against the probed total, so a resumed tail span-caps too. New
tests: a cold out-of-bounds miss refuses pre-signature and the released
floor reservation does not leak; a window-poor pool is served for a
coverable span and refused for the whole blob.

Co-Authored-By: Claude Fable 5 <[email protected]>
…id frontier

The #2062 attach refusal trades duplicate origin egress for liveness;
it was invisible. FillRegistry now carries the cache metrics handle and
bumps decdn_cache_fill_not_coalesced_total (plus a debug line with the
frontier gap) at the skip site, claim's doc states the frontier
precondition its rule list omitted, and window.rs's coalescing promise
names the same carve-out instead of an unconditional no-double-spend. A
concurrent same-group admit test pins that overlapping fills stay
byte-exact (#2069 §4).

Co-Authored-By: Claude Fable 5 <[email protected]>
…and the wire docs

ADR 038 no longer specs a buffered third route for bounded origin-cold
requests; dispatch's miss-tier block names the whole-blob fallback tiers
its overclaim hid; the own-origin opener serves the request, not the
whole blob; serve_leg's guard rationale states the real invariant
(byte_offset >= fetch_start); origin_range_wire's doc drops the fetched
outboard and the second pool; ADR 037's streams-while-fills bullet
separates credit-window draws from 4 MiB fetch windows and names the
minimum-draw exceptions; acceptance item 12 is split into ASD-STE100
sentences; the e2e crate's dead range-tier naming points at the spine.

Co-Authored-By: Claude Fable 5 <[email protected]>
…essure

PaceDecision::Wait carries its cause: the minimum-draw batching pause
(#2061) is healthy pipelining, but it was bumping
node_pull_through_window_paused — inverting that metric's documented
meaning (a flat zero means the window never binds). The node hook now
counts batching in the new decdn_node_pull_min_draw_waits_total and
window binding where it was. The half-window pacer test asserts the
cause. origin_fetch_outboard_bytes regains a metering assertion: the
one-per-fill outboard read lands in pull_through_bytes. Observability
appendix rows added for both new counters.

Co-Authored-By: Claude Fable 5 <[email protected]>
- Peer path: a bounded, unaligned leaf→B→A miss is byte-exact and B's
  recorded upstream spend is exactly the aligned span's bao wire, with
  the head never pulled (the leg that fronts real USDC).
- The resumed peer test drains and byte-compares the tail instead of
  stopping at the signed header, via the new leaf_ranged_paid_pull.
- The #2062 attach arm end-to-end: a mid-blob open behind a paying
  owner's frontier attaches (fill_not_coalesced stays 0), the overlap is
  fetched once, and the guarded frontier extension wedges neither client.
- The outboard-once test gains a draw-count ceiling (#2061 §2), so a
  regression to chunk-sized draws fails loudly.
- A no-Range origin that passes the outboard probe is pinned: the stream
  fails cleanly after ok: true with nothing mis-cached (#2069 §3).

Co-Authored-By: Claude Fable 5 <[email protected]>
The outboard-once threading (BackendSource / origin_range_wire /
OriginRangeCursor::open taking a pre-read outboard), the WindowPacer
half-window minimum draw, the PaceDecision::Wait cause and its
decdn_node_pull_min_draw_waits_total counter, and the tests and ADR
sentences that assert them leave this branch; #2061 ships on its own.
The origin_range.rs dead-field and single-pool doc cleanups that the
tier deletion caused stay, as does RampPacer::paid_base.

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

@alpergundogdu alpergundogdu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comprehensive review — the PR is solid and mergeable. The two-leg-spine refactor holds up under close reading:

  • range_out_of_bounds mirrors decdn_bao_range::align_range's bound check across the edge cases (empty blob, tail reads, overflow).
  • RampPacer::paid_base = session.served_start() and the served_paid − paid_base ramp math are consistent with FillSession::starting_at; the serve leg's extend_served_from(fetch_start, …) with a group-aligned anchor is a genuine fix (content_paid_frontier needs a group-aligned anchor), not a regression.
  • The fill-registry frontier exclusion (fetch_start > served_paid() ⇒ own your own span) correctly fixes the #2062 starvation and its fill_not_coalesced metric is wired through FillRegistry::with_metrics.
  • origin_size surfacing a trailing transport fault as Err (reviving the #1129 latch) and the exact-length outboard gate are handled correctly by the dispatch fault_seen latch.
  • The b14fe85 revert of the #2061 min-draw work is clean — no dangling min_draw / PaceDecision::Wait-cause references remain.

One low-severity defect, inline on metrics.rs: the newly added serve_cache_* counter family is never incremented in production, so all three counters export a permanent 0 — which reintroduces the exact ambiguity the docstrings say the family exists to remove. Observability only; no serving/payment correctness impact.


Generated by Claude Code

Comment thread crates/node/src/metrics.rs Resolved
@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

Copy link
Copy Markdown

Contracts coverage

Line coverage: 90.63% (2399/2647 lines)
▲ +0.00pp vs base (90.63% → 90.63%)
Run: 35605482472

@alpergundogdu
alpergundogdu merged commit 4fc94b5 into main Sep 21, 2026
27 checks passed
@alpergundogdu
alpergundogdu deleted the feat/2060-stream-bounded-miss branch September 21, 2026 17:43
thiras pushed a commit that referenced this pull request Sep 26, 2026
…iew (#2162)

* fix(cache,node): close the two-leg spine residuals from the #2064 review

- Encode-task panic: the range-wire encode catches its own unwind and parks
  a CacheError::Store carrying the panic message; UnfinishedGuard now covers
  cancel only. The own-origin pull leg logs a Store fault in the chain as an
  internal fault (error!), not as a local-origin fault.
- Observability: decdn_cache_range_pull_permit_waits_total counts draws that
  find the range-pull pool full, with a warning past 10 s; the pacer hook
  records decdn_node_pull_through_wait_seconds per pause and warns once past
  30 s. Registry rows and dashboard targets added.
- No-Range origin: origin_range_serviceable probes the first chunk group
  before the node signs, so an origin that publishes {H}.obao4 but declines
  Range degrades to the buffered whole-blob pull. A per-origin latch makes
  the probe free once an origin has served a clean range window.
- Refused attach: an already-present overlap is never re-fetched (the owner's
  gaps come from missing_ranges), so no smarter attach rule helps without
  reintroducing starvation. fill_not_coalesced now counts once per claim and
  only when the skipped fill overlaps the request.

Closes #2069

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

* docs(changelog): note the two-leg spine residual fixes

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

* fix(cache,node): address #2162 review findings

- Add CacheError::Internal for code bugs (caught encode panic, broken
  reader invariant, closed permit pool). The own-origin pull leg flags only
  Internal as a code bug; a store fault such as a full disk stays Store.
- Key the range-probe latch on the origin that served the outboard, not on
  the outboard cache, which never holds an empty outboard (blobs of one
  chunk group) or one over 256 MiB. The probe hands that outboard to the
  cursor, so it no longer reads an uncacheable outboard twice.
- A wrong-length first window advances the origin chain instead of
  shadowing a healthy later origin.
- Record a pull pause's length from a drop guard, so a cancelled pause is
  observed too; log full error chains; debug-log a range decline.
- Tests: small-blob latch, range-declining and short-first-window origins
  ahead of a healthy one, permit wait past the warning, a range-probe
  timeout refusing InternalError, and the degrade test tied to the probe.
- Docs: ADR 037 serviceability and fallback conditions, stale comments.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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