Repository navigation
fix(cache): window origin range pulls to bound memory (#2065) - #2066
Merged
Merged
Conversation
pull_through_range and Flow A's origin encode fetched the whole requested span as one buffer, then built a second span-sized encoding. A few multi-GB range requests OOM-killed the node. - Origin::fetch_range becomes the data-only fetch_range_data; the outboard comes from fetch_outboard, read once per pull. - pull_through_range fetches, verifies, and imports the span in RANGE_PULL_WINDOW_BYTES (4 MiB) windows: O(window + outboard) memory. - Flow A: origin_range_wire replaces origin_encode_range and runs one coherent encode over on-demand windows behind a bounded channel; BackendReader streams it and parks a mid-stream VerifyFailed. - At most MAX_CONCURRENT_RANGE_PULLS (4) range pulls run at once. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Window lengths must be validated and malformed responses classified as VerifyFailed before approval.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
This PR bounds origin range-pull memory with 4 MiB windows, separate outboard/data reads, streamed Flow A handling, and concurrency limits.
Changes:
- Adds windowed range verification and importing.
- Splits the
Originrange API and updates adapters. - Adds concurrency, tests, documentation, and ADR updates.
| File | Summary |
|---|---|
crates/node/tests/origin_range_pull.rs |
Updates range API references. |
crates/node/src/node_origin/pull_leg.rs |
Updates local-origin documentation and test adapter. |
crates/node/src/node_origin/backend_source.rs |
Streams origin wires and preserves typed faults. |
crates/node/src/handlers/client/window.rs |
Updates Flow A documentation. |
crates/node/src/handlers/client/dispatch.rs |
Updates range API references. |
crates/e2e/src/node.rs |
Updates filesystem-origin documentation. |
crates/cli/tests/origin_import.rs |
Tests separate outboard and data fetching. |
crates/cache/tests/s3_origin.rs |
Updates S3 range and outboard tests. |
crates/cache/tests/pull_through.rs |
Adds windowing and concurrency coverage. |
crates/cache/src/origin/s3.rs |
Implements data-only range fetching. |
crates/cache/src/origin/mod.rs |
Splits the Origin range API. Nit (1 vote): clarify missing-outboard handling. Nit (3 votes): document required custom-implementation migration. |
crates/cache/src/origin/http.rs |
Implements data-only HTTP range fetching. |
crates/cache/src/origin/fs.rs |
Implements data-only filesystem range fetching. |
crates/cache/src/origin_range.rs |
Adds window cursors and streaming wires. Critical (2 votes): validate returned window lengths and park malformed responses as VerifyFailed. |
crates/cache/src/lib.rs |
Exports range-window APIs. |
crates/cache/src/engine.rs |
Integrates windowed pulls and concurrency limits. |
CHANGELOG.md |
Documents the memory and API changes. |
adr/037-regional-proxy-warming.md |
Updates the origin-tier design reference. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 83.16% (was 83.03%, ▲ +0.13%) — 81687/98233 lines
History
|
Flow A now checks each window it fetches for exact length and parks VerifyFailed, matching encode_verified_range. The Origin docs say a range pull needs both fetch_range_data and fetch_outboard. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
- OriginRangeWire ends a faulted wire with one terminal Err from next_chunk; a guard parks an OriginError when the encode task panics or is cancelled, so a truncated wire never reads as a clean end. - Only hash mismatches map to VerifyFailed; other encode errors are OriginError, and reader invariant breaks are local Store faults. - The cursor walks typed windows (Window / Declined / WrongLength) and checks length in one place. - pull_through_range and origin_range_wire draw from separate permit pools, so a long range pull cannot stall a committed own-origin serve; a wait for a permit is logged. - Per-origin range faults are logged; origin_range_wire advances past a transport fault instead of stopping the chain. - The async encoder skips the empty range (0-byte blob); it trips a bao-tree debug assertion there. - BackendReader::read_bytes fills across chunks (the decoder reads each leaf with one read_bytes_exact), keeps the terminal fault, and errors instead of skipping an impossible copy. - Tests: permit release on drop, separate pools, mid-stream decline / transport fault / panic, multi-origin fallback, empty blob, partial degrade then whole-blob fill, metering, window straddle, fine-chunked wire, mid-stream local pull leg fault. - Docs: Origin trait, engine, CHANGELOG (BREAKING entry), ADR 037. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
yigitdot
added a commit
that referenced
this pull request
Sep 19, 2026
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Closes #2065
Problem
pull_through_rangeasked the origin for the whole aligned span in one read. It then built a second buffer of the same size for the encoding. So each request held about 2× its span in memory, with no cap on size or concurrency. On bcl, a few 1–2.4 GB range requests OOM-killed the node. The own-origin serve-miss path (Flow A,origin_encode_range) had the same bug.Fix
Origin::fetch_range(hash, req, outboard_max)→fetch_range_data(hash, req), which fetches data only. A pull reads the outboard once through the existingfetch_outboard. Without this, a windowed loop would download theblob/256outboard again for every window. The http/s3/fs adapters drop their outboard sub-fetch, and the deadget_bounded/get_object_boundedhelpers are deleted.origin_rangemodule.OriginRangeCursor: reads the outboard, fetches the first window eagerly (so a decline still moves on to the next origin before we commit), then fetches the remaining windows.RANGE_PULL_WINDOW_BYTES= 4 MiB, a multiple of the chunk group.pull_through_range. Fetches, verifies (encode_verified_range) and imports (import_bao_bytes) the span one window at a time. Each window's encoding carries its own parent nodes, so it imports on its own. If a later window fails to verify, or the origin stops serving mid-span, the pull degrades toUnsupportedas before. Windows already imported stay as verified partial data underprotect_partial.origin_range_wirereplacesorigin_encode_range. Joining per-window encodings would repeat the shared parent nodes, so Flow A runs one coherentfsm::encode_ranges_validatedover anOriginWindowReaderthat loads windows on demand. The output goes through a bounded channel (the same pattern asserve_encoder.rs).BackendReaderstreams the wire.VerifyFailedis parked throughStashedFault, so the sink still reports a hard local-origin fault.VerifyFailed.MAX_CONCURRENT_RANGE_PULLS= 4 pulls, shared by both paths. A caller past the bound waits. It does not degrade, because the fallback is a whole-blob origin pull, which costs more egress.Peak memory per pull is now about 2 × window + outboard, whatever
byte_lenis. For a 2.4 GB blob that is about 8 MiB + about 9.4 MiB, down from about 4.8 GB.Tests
pull_through.rs::windowed_range_pull:H; each read is ≤ 1 window; a corrupt 2nd window ends onVerifyFailed; a wrong-length outboard fails withVerifyFailedat open; an unsupported origin givesNone.backend_source: the corrupt-origin test now drives the realNodeAdmitStoresink and asserts the parkedVerifyFailed.origin_import) are updated for the split. The cli test now actually verifies the range against the written outboard.Local runs:
cargo nextest run -p decdn-cache -p decdn-node -p decdn-cli -p decdn-client-pull -p decdn-bao-rangeis all green. Clippy (-D warnings --all-targets),cargo doc -D warnings, fmt and pre-commit also pass.Notes
blob/256). That is bounded, but not windowed.Originis a public trait. A custom implementation must renamefetch_range→fetch_range_data(see the CHANGELOG entry). Pre-launch, so there is no shim.🤖 Generated with Claude Code