Skip to content

feat(cache): range-aware present_ranges / missing_ranges query - #1609

Merged
alpergundogdu merged 4 commits into
mainfrom
feat/cache-present-ranges
Aug 5, 2026
Merged

alpergundogdu merged 4 commits into
mainfrom
feat/cache-present-ranges

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds two pure, additive query methods to CacheEngine, the present-range oracle:

  • present_ranges(hash) -> PresentRanges — which chunk ranges of a blob are on disk right now (via iroh-blobs' per-blob bitfield).
  • missing_ranges(hash, byte_offset, byte_len, blob_size) -> ChunkRanges — the chunk-aligned sub-ranges of a requested span that are not present (requested \ present).

Plus the PresentRanges type and an integration test suite.

Why

This is the foundation ("Phase 1") of a range-aware cache API. A completeness-aware read (serve what's present, report what's missing) and a resumable paid-pull (re-fetch only what's absent) both need a single, cheap answer to "which ranges of this hash do I hold?". Today that reasoning is implicit and scattered; this makes it a first-class query. No existing path changes behavior — this PR is purely additive.

Notes

  • Point-in-time, never blocks. present_ranges classifies absence via status() (BlobStatus::NotFound) and snapshots the current bitfield by awaiting observe(hash) directly — deliberately not ObserveProgress::await_completion(), which blocks until a blob is complete and would hang on a partial or absent blob.
  • Disjoint partials, sparse accounting come for free: iroh-blobs already stores interior ranges as sparse partial blobs and reports present-byte sizes.
  • missing_ranges mirrors export_bao_range_stream's align_range error mapping (an out-of-range request is an argument error, not an origin fault).

Tests

  • New crates/cache/tests/present_ranges.rs — 7 tests covering absent / partial / complete classification and the missing_ranges set-difference (empty when present, whole span when absent, empty on a complete blob).
  • Full crate suite green: cargo nextest run -p decdn-cache → 324 passed, 0 skipped. clippy -D warnings, cargo fmt --check, cargo doc, cargo deny all clean.

Follow-ups (later phases, not in this PR)

  • Retain partials on mid-import abort instead of dropping the TempTag (kills the "orphan bytes" class) — gated on an iroh-blobs "can you tag an incomplete blob?" spike.
  • Unify the four ingest entrypoints behind one admit(hash, range) writer, and collapse the read paths onto a completeness-aware read.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added cache status inspection for determining which portions of a blob are available.
    • Added support for identifying missing byte ranges within requested, aligned spans.
    • Added completeness and availability indicators for cached content, including empty results for unavailable or declined data.
    • Exposed range information through the cache package for broader use.
  • Tests

    • Added coverage for complete, partial, absent, and disjoint cached ranges, including range-based retrieval scenarios.

Copilot AI lite review requested due to automatic review settings August 5, 2026 11:06
@coderabbitai

coderabbitai Bot commented Aug 5, 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: 49 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: ee704e1c-5857-4e4a-9404-360373e45caf

📥 Commits

Reviewing files that changed from the base of the PR and between bf7fadc and 582ec34.

📒 Files selected for processing (1)
  • crates/cache/tests/present_ranges.rs

Walkthrough

Changes

Cache range inspection

Layer / File(s) Summary
Presence snapshot API
crates/cache/src/engine.rs, crates/cache/src/lib.rs
Added PresentRanges with completeness, emptiness, and chunk-range accessors. Re-exported it from the cache crate.
Engine range queries
crates/cache/src/engine.rs
Added present_ranges and missing_ranges for status inspection and aligned missing-range calculation.
Range query integration tests
crates/cache/tests/present_ranges.rs, crates/cache/tests/util/mod.rs
Added coverage for absent, complete, partial, and disjoint ranges. Added whole-blob and ranged HTTP test fixtures.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant CacheEngine
  participant CacheStore
  Caller->>CacheEngine: present_ranges(hash)
  CacheEngine->>CacheStore: inspect status and chunk bitfield
  CacheStore-->>CacheEngine: present ranges and completeness
  CacheEngine-->>Caller: PresentRanges
  Caller->>CacheEngine: missing_ranges(hash, byte range)
  CacheEngine->>CacheEngine: validate and align span
  CacheEngine-->>Caller: missing ChunkRanges
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 Aug 5, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.29% (was 80.28%, ▲ +0.01%) — 57261/71320 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 91.43% 3284/3592 ▼ 0.05%
crates/cache/src/lib.rs 100.00% 28/28 ● 0.00%
History
Commit Total Δ vs base
bf7fadc 80.29% ▲ +0.01%
582ec34 (HEAD) 80.29% ▲ +0.01%

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 adds a range-aware “presence oracle” to decdn-cache via new additive CacheEngine query APIs, enabling future completeness-aware reads and resumable range pulls to cheaply determine what parts of a blob are already cached.

Changes:

  • Introduces CacheEngine::present_ranges(hash) -> PresentRanges to snapshot which chunk ranges are currently present (without blocking on completion).
  • Adds CacheEngine::missing_ranges(hash, byte_offset, byte_len, blob_size) -> ChunkRanges to compute requested \ present over an aligned request span.
  • Adds an integration test suite (with shared fixtures) covering absent/partial/complete cases and set-difference behavior.

Reviewed changes

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

File Description
crates/cache/src/engine.rs Adds PresentRanges type and the present_ranges / missing_ranges query methods.
crates/cache/src/lib.rs Re-exports PresentRanges from the crate root.
crates/cache/tests/present_ranges.rs Integration tests for presence classification and missing-range computation.
crates/cache/tests/util/mod.rs Test fixtures for standing up origins and building CacheEngine instances used by the new suite.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/cache/tests/present_ranges.rs Outdated
Comment on lines +51 to +54
let group_chunks = (aligned.fetch_end() - aligned.fetch_start()) / 1024;
assert!(group_chunks > 0);
// Whole-blob chunk count is strictly greater than what we imported.
let whole_chunks = blob_size.div_ceil(1024);
…d 1024

Addresses PR #1609 review: avoids a magic number that could drift from the
canonical block/chunk size.

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

Copy link
Copy Markdown
Contributor Author

Addressed the review nit in 582ec34 — present_ranges.rs now derives chunk counts via bao_tree::ChunkNum::chunks() instead of a hard-coded 1024, so it tracks the canonical block/chunk size. (Note: IROH_BLOCK_SIZE is the 16 KiB chunk-group, so the byte→chunk conversion is the right unit here.)

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