Skip to content

test(cache): eviction composes with N coalesced serve-leg readers (B3, #1656) - #1665

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/goofy-payne-1c6cd4
Aug 12, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/goofy-payne-1c6cd4

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

What

Adds evict_mid_serve_lets_coalesced_readers_finish_then_reclaims to crates/cache/src/engine.rs, the deferred test from B3 multi-observer coalescing (#1656, PR #1660, decision 5). It proves eviction composes with N coalesced serve legs at the cache level:

  • Admit a genuine partial (tagged via the B0 decdn-partial-{hash} named tag).
  • Open two in-flight export_bao_range_stream readers over it (the serve-leg readers N coalesced observers reduce to) and pull the first frame of each.
  • Evict mid-serve.
  • Gate on a distinct untagged control blob being GC-reclaimed, so a full sweep has definitely run after the tag drop.
  • Assert both readers still drain byte-for-byte to the pre-evict wire, then the partial is reclaimed.

Why / finding

The invariant holds — no bug — but the earlier mental model ("GC reclaims only after the last reader") is imprecise, and the test pins the real mechanism:

  • The serve leg takes no TempTag / own GC root. The partial is protected solely by the admit-path named tag.
  • evict drops that tag, so the next GC sweep deletes the blob and blobs().status() flips to NotFound immediately — not deferred to the last reader.
  • In-flight readers still complete correctly because each holds its own live iroh export_bao handle; the bytes stay reachable through the open fd until it drops (Unix unlink-while-open — disk space is what frees on last close).
  • So reader-pinning is unchanged by coalescing: N readers survive evict + GC exactly as one does.

Scope / notes for the reviewer

  • Test-only. One file, 163 insertions, 0 deletions. No production change.
  • The full two-observer FillSession serve harness stays deferred (too heavy for a unit test); the cache-level two-reader test is the honest reduction of it — the FillSession observer leases are coordination bookkeeping, while the export handles are what actually pin the bytes.
  • Verified on the cache crate: cargo clippy -p decdn-cache --all-targets -- -D warnings, cargo nextest run -p decdn-cache --lib, and cargo fmt -p decdn-cache -- --check all pass; the workspace pre-commit hook (fmt + clippy) also passed on commit.
  • Memory of the reader-vs-GC behavior recorded for future work.

🤖 Generated with Claude Code

…#1656)

B3 multi-observer coalescing (#1656, PR #1660) deferred a test for the
decision-5 claim that eviction under in-flight serve legs stays logical and
composes with reader-pinning. Add `evict_mid_serve_lets_coalesced_readers_finish_then_reclaims`:
two in-flight `export_bao_range_stream` readers over one tagged partial, evicted
mid-serve, gated on a control blob's GC reclaim; both readers must still drain
byte-for-byte to the pre-evict wire, then the partial is reclaimed.

The invariant holds — no bug — but the mechanism is subtler than the earlier
mental model of "GC reclaims only after the last reader": the serve leg takes no
TempTag/own GC root, so the partial is protected solely by the admit-path
`decdn-partial-{hash}` named tag. Evict drops it and the next GC sweep deletes
the blob, flipping `blobs().status()` to `NotFound` immediately. In-flight
readers still complete because each holds its own live iroh `export_bao` handle
and the bytes stay reachable through the open fd until it drops (Unix
unlink-while-open; disk space frees on last close). Reader-pinning is therefore
unchanged by coalescing: N readers survive evict + GC exactly as one does.

Test-only. The full two-observer FillSession serve harness stays deferred; the
cache-level two-reader test is the honest reduction of it.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 12, 2026 15:03
@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@alpergundogdu, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 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: 2156415d-b915-4604-b382-7a4c6b89ab2b

📥 Commits

Reviewing files that changed from the base of the PR and between 476db54 and a7eb127.

📒 Files selected for processing (1)
  • crates/cache/src/engine.rs

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 12, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.56% (was 80.57%, ▼ 0.01%) — 62916/78096 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 91.67% 3533/3854 ▲ +0.15%
History
Commit Total Δ vs base
a2f01bd 80.56% ▼ 0.01%
a7eb127 (HEAD) 80.56% ▼ 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 cache-level regression test in decdn-cache to validate that operator eviction (dropping the B0 partial tag and allowing GC to sweep) composes correctly with multiple concurrent serve-leg readers created via export_bao_range_stream.

Changes:

  • Add evict_mid_serve_lets_coalesced_readers_finish_then_reclaims to prove two in-flight export readers can fully drain byte-for-byte after evict + a GC sweep.
  • Add small async test helpers (drain_serve_leg, wait_reclaimed) to make the test robust against CI timing variance.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/cache/src/engine.rs Resolved
Comment thread crates/cache/src/engine.rs Resolved
Comment thread crates/cache/src/engine.rs Resolved
… test (review)

Address PR #1665 review (Copilot):

- Gate the drain on the TARGET hash flipping to `NotFound` while both serve legs
  are still held, instead of on a separate control blob. This turns the
  documented subtlety — the GC sweep deletes the untagged blob and flips its
  logical status without waiting for in-flight readers — into a direct
  assertion, and still proves a sweep ran after the tag drop. Drops the now
  -unneeded control partial.
- Remove the redundant post-drain `wait_reclaimed` (the store already reported
  `NotFound` while the handles were open) and its overstated comment
  (`BlobStatus::NotFound` is a logical view, not a filesystem-usage check).
- Fix a doc line-break that rendered "already -pulled"; state the summary in
  terms of the logical removal rather than disk reclaim.

Test-only; still passes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu merged commit a3b8617 into main Aug 12, 2026
27 checks passed
@alpergundogdu
alpergundogdu deleted the claude/goofy-payne-1c6cd4 branch August 12, 2026 15:29
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