Repository navigation
fix(cache): separate DMCA eviction from wrong-hash rejection; reclaim disk via tag deletion - #874
Conversation
… disk via tag deletion The cache conflated two mechanisms in `crates/cache/src/engine.rs`: deliberate operator eviction (DMCA/corruption takedown, persisted to `evicted.log`) and rejection of wrong-hash garbage from a failed pull-through. This caused a cluster of coupled bugs: - #853 (censorship): on hash-mismatch both the streaming and drain paths called `evict(actual)`, permanently blacklisting the correctly-computed hash. Under BLAKE3 content-addressing those bytes ARE valid content for `actual`, so a malicious upstream answering a pull for H with a victim blob's bytes could durably censor that legitimate blob on any node that pulls through it. - #837: the drain path commits via `add_bytes` (a persistent named tag) and never deleted it on mismatch — wrong-hash bytes stayed GC-protected forever. - #860: `evict()` never deleted the blob's named tag, so the GC sweep could never reclaim deliberately-evicted bytes (the documented reclaim was false). - #835: reframed — the captured-error partial is already dropped (GC-eligible) and, being hash-verified, is benign to serve under content-addressing. Fix: reserve `evicted.log` for deliberate eviction only. Add a `drop_named_tags_for(hash)` helper that lists iroh-blobs tags and deletes those matching a hash. `evict()` now calls it so a DMCA evict's disk is reclaimed on the next GC sweep. Wrong-hash bytes are merely made GC-eligible (drop the temp tag on the streaming path / delete the named tag on the drain path), never logically evicted. Tag-delete failures are best-effort: serving stays durably blocked, the failure bumps a new `tag_drop_failures` counter and logs a warn, and is not auto-retried. Tests: add streaming/drain non-censorship and GC-reclaim regressions plus an evict→GC reclaim test for both commit paths; update two tests whose assertions encoded the overturned posture. Docs: correct the evict/reclaim ADR appendix and engine doc-comments (reclaim is conditional on GC being enabled). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request updates the cache engine's eviction and mismatch handling to ensure proper disk reclamation and prevent censorship. Specifically, CacheEngine::evict now deletes a blob's protecting named tags to make it eligible for garbage collection, and hash mismatches on both streaming and drain paths no longer logically evict the mismatched hash (preventing a censorship vector). A compilation error was identified in the new drop_named_tags_for helper where the return value of tags.delete is incorrectly added to a u64 counter.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
This PR fixes a set of coupled cache correctness issues by clearly separating operator-driven eviction (DMCA/corruption takedown persisted in evicted.log) from wrong-hash pull-through rejection, and by ensuring disk can be reclaimed via named-tag deletion so iroh-blobs GC can actually collect bytes.
Changes:
- Introduces tag deletion for operator evictions (
evict()now drops protecting named tags so GC can reclaim bytes). - Stops using logical eviction (
evicted.log) for wrong-hash bytes; instead makes them GC-eligible (drop temp tag on streaming path / delete named tag on drain path). - Adds regression tests and a new metric (
decdn_cache_tag_drop_failures_total) to surface best-effort tag deletion failures.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
crates/cache/src/engine.rs |
Implements best-effort named-tag deletion for evict() and removes logical-evict behavior from hash-mismatch paths. |
crates/cache/src/metrics.rs |
Adds tag_drop_failures counter to track failures to delete protecting tags. |
crates/cache/tests/pull_through.rs |
Adds regressions for non-censorship on mismatch, drain-path tag cleanup, and evict GC-eligibility for both caching paths. |
adr/appendix-blob-cache-eviction.md |
Updates eviction policy documentation and adds the new metric to the observability table. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 85.93% (was 85.94%, ▼ 0.01%) — 34325/39946 lines
History
|
…tag delete succeeds) Review follow-up: the evict() doc-comment, the Inner.evicted field doc, and the ADR appendix asserted reclaim "on the next GC sweep" without noting it is also gated on the best-effort tag deletion succeeding. Spell out both conditions (GC enabled AND tag delete succeeded) and that a failure is surfaced via `tag_drop_failures` while serving stays blocked. Docs-only; no behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Context
The cache conflated two distinct mechanisms in
crates/cache/src/engine.rs: deliberate operator eviction (DMCA/corruption takedown, persisted toevicted.log) and rejection of wrong-hash garbage from a failed pull-through. Reusing the stickyevict()machinery for wrong-hash bytes — andevict()never freeing disk — produced a cluster of coupled bugs. Fixed as one PR because they live in the same three code paths and cross-reference each other.Bugs fixed
self.evict(actual), permanently adding the correctly-computed hash toevicted.log(sticky, no unevict). Under BLAKE3 content-addressing those bytes are the authorized content foractual, so a malicious upstream answering a pull forHwith a victim blob's bytes makes the puller permanently blacklist that legitimate blob — durable, cheap censorship on any node that pulls through it.add_bytes(a persistent named tag) and never deleted it on mismatch, so wrong-hash bytes stayed GC-protected forever (unbounded disk growth under a hostile origin).evict()never deleted the blob's named tag, so the GC sweep could never reclaim deliberately-evicted bytes — contradicting the docs' "reclaimed on the next GC sweep".Approach
Reserve
evicted.logfor deliberate eviction only:drop_named_tags_for(hash)helper — lists iroh-blobs tags, deletes those matching the hash (names are opaque/store-assigned, so matched by hash).evict()calls it after persisting the takedown, so a DMCA evict's disk is reclaimed on the next GC sweep (when GC is enabled).decdn_cache_tag_drop_failures_totalcounter + logs a warn, and is not auto-retried.Tests
New regressions (each verified to fail on pre-fix code):
streaming_mismatch_does_not_censor_actual_hash,drain_mismatch_tag_deleted_lets_gc_reclaim,evict_makes_blob_gc_eligible,evict_makes_streaming_cached_blob_gc_eligible. Updatedhash_mismatch_is_rejected_and_not_cachedandgc_reclaims_partial_import_byteswhose assertions encoded the overturned posture.cargo nextest run -p decdn-cache— 186 passed; clippy--all-targetsclean; fmt clean; workspace builds.Review
Incorporates a multi-agent review pass (code/tests/comments/silent-failures): added the failure metric, corrected an unconditional-reclaim doc overstatement (reclaim is gated on GC being enabled), fixed misleading "until retried/restart" wording, and documented the narrow evict-vs-repull reclaim race.
Known follow-up (out of scope)
get()does not re-checkis_evictedafter a pull, so anevict()racing an in-flight same-hash pull can briefly serve just-evicted bytes and/or re-create a protecting tag. Pre-existing and on the hot path — documented here, worth a separate issue.Closes #853
Closes #837
Closes #860
Closes #835
🤖 Generated with Claude Code