Skip to content

feat: serve-side stream-while-store for http/s3 via publisher outboard (#1130) - #1528

Merged
thiras merged 8 commits into
mainfrom
claude/1130-serve-stream-while-store
Jul 31, 2026
Merged

thiras merged 8 commits into
mainfrom
claude/1130-serve-stream-while-store

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Serve-side stream-while-store for http/s3 (#1130, part 3B)

Serves a whole-blob http/s3 cache miss by streaming the blob from the origin straight to the paying client while teeing it into the store — so time-to-first-byte no longer waits for the whole blob to land. When the node's own origin (S3/R2/B2/HTTP/fs) holds the blob and publishes the sibling {H}.obao4 outboard, the node produces bao verified-wire on the fly from that outboard and drives it through the existing #856 window/voucher serve loop. When no outboard is published it degrades cleanly to today's buffered populate_local-then-serve path.

How it works

  • Origin::fetch_outboard (+ OutboardFetch) fetches just the {H}.obao4 sibling (fs/http/s3 impls; default Unsupported).
  • decdn-bao-range::streaming — a sync, header-less whole-blob bao encoder (leaf crate stays tokio-free / iroh-blobs-free, CLI binary-split regression: publisher links cache crate (iroh-blobs/AWS SDK) #578).
  • LocalOutboardPull (decdn-cache) fetches the outboard once, then runs the encoder on spawn_blocking bridged to the async origin plaintext stream via two bounded mpsc channels, exposing next_chunk/finish/abandon — the same shape as NodeProgressivePull.
  • ProgressiveSource { Node, LocalOutboard } abstracts the bao source so the window serve loop drives either uniformly.
  • serve_via_local_outboard + a new dispatch tier (whole-blob, pull_authorized) that prefers the stream path and falls back to try_local_populate when no outboard exists.

Safety / correctness

  • Bao wire is produced from an untrusted outboard: a tampered outboard, tampered data, or wrong root all fail verification against H. A mid-stream verify failure is a wire fault handled by the existing window_forward_loop corruption arm — no new signing or slash path (signing ok:false is provably safe post-refactor(slashing): retire the phantom-announcement offense #1512).
  • Billing is unchanged: WIRE bytes through the same loop; total_bytes is the outboard/HEAD-derived content size; emitted wire length == expected_wire_bytes.
  • decdn-bao-range leaf-crate invariant held (only bao-tree/bytes/positioned-io/thiserror).

Tests

  • 3 anvil-e2e tests (origin_stream_while_store.rs): first-fetch streams (proven via the new decdn_local_outboard_serves_total counter == 1 + teed into store), no-outboard falls back byte-correct (counter == 0), corrupt outboard fails safe (client rejects, daemon stays healthy, no slash).
  • Unit coverage in bao-range (reference-equality of the streaming encoder) and cache (LocalOutboardPull).
  • Full gate green: clippy --workspace --all-targets clean, cargo nextest run all pass, both anvil-e2e targets compile.

Reviewer notes (disclosed)

  • The stream tier is always-on — gated only on whole-blob + pull_authorized, independent of the local_populate config (a deliberate choice; trivially tied to local_populate if preferred).
  • On an InFlight collision or a deposit/leech/size reject, the node has already fetched the {H}.obao4 outboard (~0.4% of blob) and opened the origin stream before abandoning — bounded, and strictly less egress than the buffered fallback it precedes.
  • Corrupt-outboard: a client may receive and pay for a verified prefix before the tamper trips bao verification mid-blob and resets the stream; nothing is cached, no slash (matches node→node corrupt-upstream semantics, protocol/node: bao verified-range streaming on cdn/client/v1 (verified resume + parallel multi-source fetch) #915).

Originally planned as stacked on #1523; that PR squash-merged to main first, so this targets main directly and its 3 base commits (already in main) were dropped on rebase.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Full-blob cache misses can now stream directly from supported origins while simultaneously storing the content locally.
    • Responses are verified during delivery, with corrupted content rejected and incomplete cache entries discarded.
    • Filesystem, HTTP, and S3 origins can provide the supporting outboard data.
    • Ranged requests and origins without outboard data continue using existing behavior.
  • Observability
    • Added a metric for stream-while-store deliveries.
  • Documentation
    • Documented the new delivery flow, fallback behavior, and metric.

@coderabbitai

coderabbitai Bot commented Jul 30, 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: 34 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: e5cf35a1-098a-44e7-9b41-18475d255a5c

📥 Commits

Reviewing files that changed from the base of the PR and between fe813ab and 1975762.

📒 Files selected for processing (18)
  • adr/037-regional-proxy-warming.md
  • adr/appendix-observability.md
  • crates/bao-range/src/lib.rs
  • crates/bao-range/src/streaming.rs
  • crates/cache/src/engine.rs
  • crates/cache/src/lib.rs
  • crates/cache/src/local_outboard_pull.rs
  • crates/cache/src/origin/fs.rs
  • crates/cache/src/origin/http.rs
  • crates/cache/src/origin/mod.rs
  • crates/cache/src/origin/s3.rs
  • crates/cache/tests/s3_origin.rs
  • crates/e2e/tests/origin_stream_while_store.rs
  • crates/node/src/handlers/client/dispatch.rs
  • crates/node/src/handlers/client/mod.rs
  • crates/node/src/handlers/client/source.rs
  • crates/node/src/handlers/client/window.rs
  • crates/node/src/metrics.rs

Walkthrough

This change adds origin outboard discovery and verified, header-less BAO streaming for whole-blob cache misses. The node can stream origin data to clients while teeing it into local storage, falls back when no outboard is available, and exposes metrics and end-to-end validation for the new path.

Changes

Origin outboard stream-while-store

Layer / File(s) Summary
Streaming BAO pull pipeline
crates/bao-range/src/*, crates/cache/src/local_outboard_pull.rs, crates/cache/src/lib.rs
Adds a sequential reader adapter, verified header-less BAO encoding, and an asynchronous LocalOutboardPull that forwards encoded chunks while validating against the supplied root.
Origin outboard discovery and adapters
crates/cache/src/origin/*, crates/cache/tests/s3_origin.rs, crates/cache/src/engine.rs
Adds OutboardFetch, extends the Origin trait, implements bounded .obao4 retrieval for filesystem, HTTP, and S3 origins, and opens local outboard pulls with fallback when size or outboard data is unavailable.
Window-paced local delivery
crates/node/src/handlers/client/{dispatch.rs,source.rs,window.rs}, crates/node/src/handlers/client/mod.rs
Adds the local outboard cache-miss route, unifies node and local pulls through ProgressiveSource, and reuses window-paced delivery and tee cleanup behavior.
Metrics, fallback, and end-to-end validation
crates/node/src/metrics.rs, crates/e2e/tests/origin_stream_while_store.rs, adr/*
Adds decdn_local_outboard_serves_total, documents the metric and serving scope, and tests successful streaming, buffered fallback, cache reuse, and corrupted-outboard failure.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant CacheEngine
  participant Origin
  participant LocalOutboardPull
  participant WindowForwardLoop
  participant CacheStore
  Client->>CacheEngine: request whole blob
  CacheEngine->>Origin: fetch size and .obao4 sibling
  Origin-->>CacheEngine: outboard and plaintext stream
  CacheEngine->>LocalOutboardPull: start verified BAO encoding
  LocalOutboardPull->>WindowForwardLoop: encoded chunks
  WindowForwardLoop-->>Client: window-paced response
  WindowForwardLoop->>CacheStore: tee plaintext into cache
  LocalOutboardPull-->>WindowForwardLoop: verification completion
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.

@github-actions

github-actions Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.14% (was 80.25%, ▼ 0.11%) — 55210/68890 lines

File Coverage Lines Δ
crates/bao-range/src/lib.rs 93.88% 138/147 ● 0.00%
crates/bao-range/src/streaming.rs 77.98% 85/109 new
crates/cache/src/engine.rs 91.35% 3232/3538 ▼ 0.05%
crates/cache/src/lib.rs 100.00% 28/28 ● 0.00%
crates/cache/src/local_outboard_pull.rs 80.22% 73/91 new
crates/cache/src/origin/fs.rs 78.38% 591/754 ▼ 0.10%
crates/cache/src/origin/http.rs 84.73% 394/465 ▲ +1.85%
crates/cache/src/origin/mod.rs 47.19% 42/89 ▲ +0.52%
crates/cache/src/origin/s3.rs 88.67% 493/556 ▲ +0.10%
crates/node/src/handlers/client/dispatch.rs 81.67% 361/442 ▼ 5.45%
crates/node/src/handlers/client/mod.rs 90.10% 737/818 ● 0.00%
crates/node/src/handlers/client/source.rs 88.66% 86/97 new
crates/node/src/handlers/client/window.rs 62.84% 257/409 ▼ 20.82%
crates/node/src/metrics.rs 95.59% 1084/1134 ● 0.00%
History
Commit Total Δ vs base
fe813ab 80.06% ▼ 0.11%
1975762 (HEAD) 80.14% ▼ 0.11%

alpergundogdu and others added 8 commits July 30, 2026 18:55
Adds a standalone way to fetch just the sibling {H}.obao4 outboard with
no accompanying blob data, feeding a later stream-while-store serve path
(#1130). New OutboardFetch enum (Found/NotFound/Unsupported) alongside a
fetch_outboard trait method (default Unsupported); fs/http/s3 override it
by mirroring their existing fetch_range outboard sub-fetch and size
patterns (fs reads the sibling file bounded by outboard_max_bytes; http
GETs {url}.obao4 with redirects disabled, distinguishing 404 from other
declines; s3 issues GetObject on {key}.obao4).
…upt-safe

Adds decdn_local_outboard_serves_total (incremented at entry to
serve_via_local_outboard) so tests can distinguish the stream-while-store
serve tier from the buffered populate_local fallback deterministically.
Fixes a real bug it caught: LocalOutboardPull's WireWriter forwarded
bao-encoder writes verbatim (up to one 16 KiB chunk-group per write),
violating window_forward_loop's CHUNK_SIZE-per-chunk relay invariant and
causing every stream-while-store fetch to fail as NotFound; WireWriter now
splits into CHUNK_SIZE-bounded pieces before sending.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu force-pushed the claude/1130-serve-stream-while-store branch from fe813ab to 1975762 Compare July 30, 2026 18:06
@thiras
thiras merged commit 60ae2f3 into main Jul 31, 2026
25 checks passed
@thiras
thiras deleted the claude/1130-serve-stream-while-store branch July 31, 2026 19:20
alpergundogdu added a commit that referenced this pull request Aug 3, 2026
…1563, #1576, #1579) (#1581)

* docs: strike the never-implemented origin_range_pull_enabled knob (#1555)

The knob only ever existed in ADR 037 and one stale doc comment; range
pull-through is ungated in code and the whole-blob fallback already makes
every attempt correct, so the toggle bought nothing. Remove the ADR
Parameters row, the "MAY disable" sentence, and the dead clause in the
cache engine's `Unsupported` doc.

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

* docs(adr): stop linking canonical ADRs into _history; widen link-gate (#1559)

Canonical ADRs no longer reference the _history archive (it stays on disk
for audit): delink the retired-ADR mentions in 026/028/architecture to
inline-code names, drop the "Body archived verbatim" clauses, and add a
check-no-history-links guard so they cannot come back.

Widen check-anchor-targets to docs/ + root markdown (runbook, CONTRIBUTING,
CLAUDE, CHANGELOG, README) by resolving each link relative to its own
file's directory, and widen the CI adr changes filter to match.

Also drop the changelog-voice amendment note atop ADR 026 — the body
already carries the final 10% POL / 19% App Incentives / 15% combined
numbers.

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

* docs(adr): correct residual propose/ratify origin-assignment language (#1558)

#1491 replaced per-assignment DAO ratification with one-time publisher
vetting + instant assigns, but the glossary Publisher entry and ADR 019's
authorized-origins bullet still described the old model. Align both with
the vetted-publisher-seats-directly model already stated elsewhere in the
same files.

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

* docs(adr): sync BuybackBurner docs with the three-layer venue-neutral refactor (#1579)

The docs still described BuybackBurner as one flat contract. Add a
"Declared on" column to the ADR 003 member table and mark setVault
Balancer-only; document the Permit2 approvals footgun in the L2 deployment
appendix (with the canonical Permit2 address); and drop references to a
nonexistent IBuybackBurner interface across ADR 018 and a stale contract
comment — FeeRouter holds buybackBurner as a plain address and never calls
a typed method on it, so no interface is warranted.

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

* refactor: delete dead public surface and stale lint suppressions (#1563)

Sweep zero-caller public items and out-of-date `#[allow]`s left behind by
landed work:

- protocol: delete `StreamRequest::requested_len()` (no callers; serving
  sites derive the `byte_len == 0` sentinel inline).
- gossip: drop `GossipService::spawn`'s `_endpoint` param and its
  `needless_pass_by_value` allow; the caller no longer clones an endpoint
  for nothing.
- node/admin: remove the never-read `AdminState::signer` field, its
  `dead_code` allow, and its construction sites (handlers use
  `voucher_signer`).
- node/handlers: drop the stale `dead_code` allow + comment on
  `ProgressiveSource::LocalOutboard`; it is constructed in the production
  serve path (`window.rs`) since #1528.
- common/config: remove the blanket `#![allow(dead_code)]` in
  `resolved.rs`; the fields are `pub` and genuinely read, so none is
  actually dead.
- cache: delete the `CacheEngine::stats()` zeros-stub and its `CacheStats`
  type (no callers; intended gossip consumer never materialized).
- node: collapse `probe_client` into the identical
  `decdn_client_pull::probe::probe_once` (re-exported as
  `client_requester`); delete the duplicate module.
- common/cli: `--publisher-registry-address` is validate-only on the
  daemon; document it as such (dropping it cascades into the resolver,
  `ResolvedConfig`, `config validate`, and ~60 test literals).
- gossip: verified `RESUBSCRIBE_FAILED_LABEL` is incremented on the
  resubscribe-failure path; left as-is.

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

* test(e2e): scope long-journey lint allows to the functions that need them (#1576)

`clippy::too_many_lines` / `clippy::cognitive_complexity` were suppressed
file-wide alongside the standard test allows. Narrow them to
function-scoped `#[allow(..., reason = "...")]` on only the long journey
functions, matching the #1569 idiom in `slash_appeal.rs` / `g_origin_01`.
The standard test allows (`unwrap_used`, `expect_used`, `panic`,
`indexing_slicing`, `duration_suboptimal_units`) stay file-level.

Narrowing surfaced functions that had quietly grown past the threshold
under the file-wide blanket:

- cli_fetch_topup.rs: `run_multi_interval_topup` (144) and
  `run_two_topup_fetch` (162), not just `run`.
- anvil_bringup_shutdown_e2e.rs: `build_config` (101, a flat
  resolved-config struct literal) alongside the drain journey test.

Each now carries its own reason. `coop_close_watermark_reconcile.rs`'s
`run` is under the threshold, so it needs no scoped allow at all.

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

---------

Co-authored-by: Claude Opus 4.8 <[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

Development

Successfully merging this pull request may close these issues.

2 participants