Skip to content

fix(cache): separate DMCA eviction from wrong-hash rejection; reclaim disk via tag deletion - #874

Merged
thiras merged 2 commits into
mainfrom
fix/cache-wronghash-eviction-cluster
Jun 10, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/cache-wronghash-eviction-cluster

Conversation

@thiras

@thiras thiras commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Context

The cache conflated two distinct 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. Reusing the sticky evict() machinery for wrong-hash bytes — and evict() 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

Approach

Reserve evicted.log for deliberate eviction only:

  • New 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).
  • 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 decdn_cache_tag_drop_failures_total counter + 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. Updated hash_mismatch_is_rejected_and_not_cached and gc_reclaims_partial_import_bytes whose assertions encoded the overturned posture.

cargo nextest run -p decdn-cache — 186 passed; clippy --all-targets clean; 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-check is_evicted after a pull, so an evict() 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

… 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]>
Copilot AI review requested due to automatic review settings June 10, 2026 19:01

@gemini-code-assist gemini-code-assist Bot 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.

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.

Comment thread crates/cache/src/engine.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.

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.

Comment thread crates/cache/src/engine.rs Resolved
Comment thread crates/cache/src/engine.rs Resolved
Comment thread adr/appendix-blob-cache-eviction.md Resolved
@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 85.93% (was 85.94%, ▼ 0.01%) — 34325/39946 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 92.54% 1712/1850 ▼ 0.42%
History
Commit Total Δ vs base
e7d626e 85.93% ▼ 0.01%
bd28cb5 (HEAD) 85.93% ▼ 0.01%

…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]>
@thiras
thiras merged commit 04f7a6c into main Jun 10, 2026
20 checks passed
@thiras
thiras deleted the fix/cache-wronghash-eviction-cluster branch June 10, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants