Skip to content

fix(node): own origin streams blobs past max_blob_size without storing the rest - #2937

Merged
alpergundogdu merged 2 commits into
mainfrom
fix/2934-own-origin-blob-too-large
Nov 25, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
fix/2934-own-origin-blob-too-large

Conversation

@yigitdot

@yigitdot yigitdot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What

max_blob_size means one thing on every path: the bytes of one blob a node keeps.

  • Own origin: a blob larger than the cap is always served in full. Its stream gets its own origin pull, which stores the blob until the node holds the cap's worth. Past that point each chunk group is still verified against H, then handed to the serve leg in memory and not stored. No refusal, no mid-stream Declined.
  • Pull-through: unchanged. It serves while its held bytes fit, then stops with Declined, because it pays its upstream for every byte.

Closes #2934.

Why

#2934 found an own-origin blob over the cap answered NotFound. In practice main served such a blob and kept all of it, since the own-origin fill never checked the cap. Declining it instead would make the largest objects in an origin unservable, and tie the reach of a blob to whichever origin node has the biggest cap: if that node dies, the blob is gone. Keeping it all lets one large blob evict many small ones. Passing the excess through keeps every origin object servable and holds the cap on disk.

How

  • decdn-cache:
    • AdmitControl::store_budget: the admit stores leaves while they fit, and hands every later verified leaf to the fill session (FillSession::pass_leaf) with its proof nodes dropped from the store. The session already captured those nodes for the serve's outboard.
    • CacheStore with an exclusive session sets the budget from CacheEngine::held_room at each leg and counts handed-over ranges as present, so the pull does not fetch them again. is_complete still reads the real store, so nothing finalizes early.
    • FillRegistry::claim_exclusive registers an owner that attaches to no live fill, and claim never attaches to an exclusive fill: each handed-over leaf goes to exactly one serve leg.
  • Serve reader: AwaitingDataReader takes handed-over leaves from its session, and wakes on each hand-over.
  • Node: serve_via_backend_origin claims an exclusive fill when CacheEngine::exceeds_held_cap(total_bytes).
  • Metrics: decdn_serve_origin_passthrough_streams_total, decdn_serve_origin_passthrough_bytes_total, and one info! line per pass-through stream naming the blob size and the bytes passed through.
  • ADRs: 005 (max_blob_size enforcement, the Declined row, discovery), 037 (origin tier), the observability appendix. Config docs updated.

Reviewer notes

  • Memory: the pull runs at most PULL_AHEAD_BYTES past the paid frontier, so only a few handed-over chunk groups wait in memory.
  • Overshoot: each fill reads the bytes held when a leg opens, so two concurrent streams of one over-cap blob can pass the cap by at most one leg each.
  • Egress: streams of an over-cap blob do not share an origin pull. Each pass-through stream reads the origin again.
  • What is kept: first-come bytes, so for model files the first layers (loaders read from byte 0).
  • Wire / config: no wire or config change; two new counters.

Verification

  • cargo nextest run -p decdn-cache: 493 passed. -p decdn-node --lib --test origin_range_pull: 1258 passed. A full five-crate run (node, cache, client, common, cli) before the final claim-path change: 5027 passed, two node_origin_pull tests passed on retry.
  • Clippy (--all-targets --all-features), fmt, cargo doc with warnings denied, and make -C adr check-refs are clean. Hooks ran on the commit.
  • New tests:
    • integration: a blob twice the cap serves in full with the node holding at most the cap, and the pass-through bytes equal blob size minus held bytes; a range opened after the cap is held serves by pass-through with the store unchanged; tampered origin bytes fail the stream and never count as a cap stop; two concurrent streams of one over-cap blob both serve;
    • unit: the admit store budget (partial and zero), and the exclusive claim in both directions.
  • Mutation check: disabling the exclusive fill fails both past-the-cap integration tests (the node keeps the whole blob).

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 22, 2026 03:33

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-code-quality

github-code-quality Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 386b1cf fix/2934-own-origin-... 139b947 +/-
78% 78% 0%
View coverage of the 6 most impacted files.
File main 386b1cf fix/2934-own-origin-... 139b947 +/-
crates/cache/sr...fill_session.rs 96% 95% -1%
crates/cache/src/engine.rs 92% 92% 0%
crates/cli/src/...ommands/node.rs 65% 66% +1%
crates/node/src...lient/window.rs 74% 75% +1%
crates/cache/sr.../cache_store.rs 87% 88% +1%
crates/node/src...erve_encoder.rs 89% 90% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 25, 2026 11:18 UTC

@yigitdot yigitdot changed the title fix(node): decline an own-origin blob over max_blob_size at open fix(node): own origin caps bytes held per blob, like pull-through Nov 22, 2026

Copy link
Copy Markdown
Contributor

I don't think max_blob_size should be a reason for an own-origin node to refuse.

The gap this PR fixes is real. run_local_pull_leg drives the origin bytes into a CacheStore, so since #2922 an own-origin serve can fill the cache disk with no cap. But a held-bytes refusal on own origin leads to a worse failure:

  1. It permanently walls off part of the blob. Eviction only removes whole blobs (ADR 040 § Whole-blob reclaim). Take a 100 GB blob and a 50 GB cap. Once the origin node holds 50 GB of it, every later missing range gets Declined and nothing is read from the origin. Those bytes stay unreachable until the whole blob is evicted.
  2. It recreates the problem the PR description argues against. The description rejects declining the whole blob because "nothing can fill the blob". When a relay hits its cap, the requester can try another node. The origin node is the source, so when it declines a range, no relay can fill that range either. own_origin_blob_over_max_blob_size_serves_until_the_cap_is_held checks for exactly this outcome.
  3. Bounding the disk doesn't require refusing. The bytes are already durable in the node's backend, and {H}.obao4 lets the node verify any range against the hash without storing it. Staging into the cache helps later hits, but the origin doesn't need it to serve.

Suggestion: keep the limit on held bytes, but treat it as a cache limit on own origin, not a reason to refuse. When an own-origin range would push held bytes past the cap, stream it from the backend to the requester, verified against the outboard, without storing it, instead of stopping with Declined. The disk stays bounded and every byte stays servable. In ADR 005: "max_blob_size limits what a node caches. A cache-miss relay declines past it. An own-origin node serves past it without caching."

This probably needs a non-holding store, or a separate streaming leg, for drive, since drive is written around a store it fills.


Generated by Claude Code

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.

🟡 Changes recommended

At its cap, an own-origin node declines discovery with empty coverage, causing usable blocks to be dropped or negative-cached and potentially breaking multi-source fetches.

1 open issue

Review effort: Balanced

@yigitdot yigitdot changed the title fix(node): own origin caps bytes held per blob, like pull-through fix(node): own origin serves blobs past max_blob_size by pass-through Nov 22, 2026
@yigitdot

Copy link
Copy Markdown
Contributor Author

Commit ddafe97: own origin serves blobs past max_blob_size by pass-through

This commit changes how the PR handles an own-origin blob larger than max_blob_size. Before, the node refused the rest with Declined. Now own origin never refuses a range for size:

  • Lands until the cap. The node stores ranges until it holds max_blob_size bytes of the blob.
  • Pass-through after the cap. Any bytes no fill landed are read from the node's own origin (OriginPassthrough) and streamed into the serve's single encode, which verifies each leaf and outboard pair against H. None of them are written to the store. The stream answers ok: true at open and never stops mid-stream for size.
  • Pull-through unchanged. A fill from another node still refuses with Declined, at open and mid-stream.

Strict cap

  • decdn-client: a leg the cap shortens now ends on a chunk-group boundary, so alignment can't push the store past the cap.
  • BackendSource reserves each leg's range (CacheEngine::reserve_held). A leg that doesn't fit beside the store and the reservations of concurrent fills ends with BlobTooLarge.

Resource bounds

  • Each window read takes a range-pull permit only for that read, so a slow client holds no permit while it waits for credit.
  • Outboards pinned by pass-through serves share a 512 MiB budget. A 50 GB blob's outboard is about 186 MiB.

Docs: ADR 005, 037 and 039 and the observability appendix are updated, and there are two new counters: decdn_serve_origin_passthrough_streams_total and decdn_serve_origin_passthrough_bytes_total.

Follow-up commit: fc90364 updates the decdn-client public-API snapshot for the new BlobTooLarge::held constructor. That snapshot was the public API snapshot CI failure.

@yigitdot

Copy link
Copy Markdown
Contributor Author

I don't think max_blob_size should be a reason for an own-origin node to refuse.

Agreed. ddafe97 does what you suggest: max_blob_size is now a cache limit on own origin, not a reason to refuse.

  • Serves past the cap without caching. The node lands ranges until it holds max_blob_size bytes of the blob. It then streams any range no fill landed from its backend by pass-through, verifies it against {H}.obao4 and H, and does not store it. Own origin answers ok: true at open and never stops mid-stream for size. In your 100 GB / 50 GB example, every range stays servable and the disk holds at most 50 GB.
  • No non-holding store for drive. The local pull leg still fills the store up to the cap. The fallback lives in the serve leg's two encode readers instead: AwaitingDataReader and SessionOutboardReader get a decdn_cache::OriginPassthrough. When a leaf or outboard pair was not landed by any fill and the store lacks it, they read it from the origin in forward 4 MiB windows. The single coherent encode verifies those bytes like any other, so the switch can happen mid-stream with no second encoder.
  • Relays unchanged. A cache-miss fill from another node still declines past the cap, at open and mid-stream.
  • Test replaced. own_origin_blob_over_max_blob_size_serves_until_the_cap_is_held is replaced by tests that require the opposite:
    • own_origin_serves_a_blob_past_the_cap
    • own_origin_range_past_a_held_cap_serves_at_open
    • own_origin_passthrough_rejects_tampered_bytes
  • ADR 005 now reads close to your wording. max_blob_size limits the bytes a node holds. A relay declines past it, and an own-origin node serves past it by pass-through without storing the bytes.

The commit also makes the cap strict:

  • A leg the cap shortens now ends on a chunk-group boundary.
  • Concurrent own-origin fills of one blob reserve their legs, so together they never hold more than the cap.

The details are in the commit comment above.

@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@yigitdot

Copy link
Copy Markdown
Contributor Author

Commit 5962d33: review fixes for origin pass-through

This commit fixes what a three-part review of ddafe97 found (correctness, test coverage, and error handling with doc accuracy). The review found no problems with the reservation ordering, deadlocks, Send bounds, permit release, the window and cursor logic, or the applies gating.

Fixes

  • The cap could still be passed by part of a chunk group. leg_range cut a leg only when the room itself shortened it. When an unaligned room or pacer bound shortened it instead, align_range could round the leg's end past the cap. A held partial tail group makes the room unaligned. This affected pull-through fills and decdn get; own origin was already caught by its reservation check. Now any leg whose aligned end would pass resume_start + max_len ends on the last chunk-group boundary inside that reach.
  • A tampered pass-through byte was not remembered. The encode's LeafHashMismatch / ParentHashMismatch never reached the presence memo, so every later open failed mid-stream. OriginPassthrough::note_verify_fault now records VerifyFailed, as a fill's verify fault does: the next open refuses, and the pinned outboard copy leaves the cache.
  • A takedown at the cap read as a cap refusal. An own-origin serve error no longer goes through stop_at_held_cap, so a takedown at the cap no longer ends as Declined or bumps serve_stream_midstream_blob_too_large.
  • Smaller fixes:
    • A wait on the pass-through outboard budget logs a warning after 10 s.
    • A failed window load leaves no stale cursor.
    • A store fault in an own-origin leg now logs as a store fault, not an origin fault. The metric is unchanged.
  • Docs: the comments, ADR 005 and 037, and the observability appendix now say pass-through covers any bytes no fill landed, and that the 512 MiB outboard budget is a soft bound.

New tests

  • leg_range_never_ends_past_the_cap_reach
  • first_leg_opens_nothing_under_a_chunk_group_of_room
  • a_takedown_stops_origin_pass_through (data and outboard readers)
  • backend_source_reservations_release_on_next_leg_and_drop
  • own_origin_passthrough_recovers_a_failed_fill
  • own_origin_passthrough_rejects_a_tampered_outboard_pair
  • own_origin_passthrough_rejects_tampered_bytes now also asserts the origin fault is recorded.

Mutation checks: restoring the old leg_range condition, dropping note_verify_fault, and dropping the refuses check in applies each fail their test.

Verification: cargo nextest run -p decdn-node -p decdn-cache -p decdn-client passed 3489 tests before the last edit. That edit split one logging function for clippy, and its 33 pull-leg tests pass. Clippy (--all-targets --all-features), fmt, cargo doc with warnings denied, make -C adr check-refs and the decdn-client public-API snapshot are all clean.

Not covered by a test: a mid-stream takedown on an own-origin serve at the cap, and a store fault that must not fall back to pass-through. Both need fault injection that the harness doesn't have.

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.

🟡 Changes recommended

Active pass-through defects can falsely fault healthy origins, fetch beyond requested ranges, and overcharge shared outboard memory, causing unnecessary egress and stalled serves.

4 open issues
1 resolved since last review

Review effort: Balanced

Comment thread crates/cache/src/engine.rs Resolved
Comment thread crates/cache/src/origin_passthrough.rs Resolved
Comment thread crates/cache/src/origin_passthrough.rs Resolved

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.

🟡 Changes recommended

Cancelling a pending serve skips slot cleanup, allowing abandoned requests for distinct hashes to grow the registry without bound.

2 open issues
3 resolved since last review

Review effort: Balanced

Comment thread crates/cache/src/origin_passthrough.rs Resolved
…g the rest

max_blob_size bounds the bytes of one blob a node holds. An own-origin
blob larger than the cap gets an exclusive fill: it stores the blob up to
the cap, then verifies each further chunk group against H and hands it to
the serve leg in memory without storing it. The serve never refuses, so
every origin object stays servable, and one large blob cannot evict many
small ones. Pull-through keeps its Declined at the cap.

- decdn-cache: AdmitControl::store_budget routes leaves past the budget to
  FillSession::pass_leaf; CacheStore counts handed-over ranges as landed
  for an exclusive session; FillRegistry::claim_exclusive registers an
  owner no claim attaches to.
- serve reader takes handed-over leaves from its session.
- metrics: decdn_serve_origin_passthrough_streams_total and _bytes_total,
  plus an info! line per pass-through stream.
- ADR 005, 037 and the observability appendix describe the behavior.

Closes #2934.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alpergundogdu
alpergundogdu force-pushed the fix/2934-own-origin-blob-too-large branch from 9e3ee19 to 2e13337 Compare November 25, 2026 10:31
@alpergundogdu alpergundogdu changed the title fix(node): own origin serves blobs past max_blob_size by pass-through fix(node): own origin streams blobs past max_blob_size without storing the rest Nov 25, 2026
@alpergundogdu
alpergundogdu enabled auto-merge (squash) November 25, 2026 10:50
…he-passthrough-fcc7a0

# Conflicts:
#	crates/cache/src/engine.rs
@alpergundogdu
alpergundogdu merged commit f3aa0a2 into main Nov 25, 2026
36 checks passed
@alpergundogdu
alpergundogdu deleted the fix/2934-own-origin-blob-too-large branch November 25, 2026 11:21
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.

ADR 005 says an oversized own-origin blob answers Declined; the node signs NotFound

3 participants