Skip to content

fix(cache): quarantine a held blob when its serve trips a stored hash mismatch - #2002

Merged
thiras merged 3 commits into
mainfrom
worktree-1984-held-corruption-quarantine
Sep 14, 2026
Merged

thiras merged 3 commits into
mainfrom
worktree-1984-held-corruption-quarantine

Conversation

@thiras

@thiras thiras commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1984

Summary

The issue's verification comment showed that serve legs never emit unverified bytes. iroh-blobs export_bao runs traverse_ranges_validated, so a rotten or tampered group aborts the serve before it is billed. The real gap: the node never acted on that mismatch. The hash stayed served and announced, and every buyer tripped it again until an operator ran evict. That is a permanent takedown, which is the wrong recovery for a legitimate hash.

This PR adds a serve-trip quarantine and no periodic scrub. A sampled scrub would re-derive a signal the validated serve export already gives more freshly (spec-discipline gate 5). It would also add a knob and idle disk IO.

  • Trigger. export_bao_range_stream or outboard_pairs hits one of:

    • LeafHashMismatch or ParentHashMismatch
    • Io(UnexpectedEof), a short file

    A complete blob always quarantines. A partial blob quarantines only when the failing chunk groups lie inside its present ranges; an absent sparse range reads back as zeros or EOF, so it is not proof of corruption.

  • Withdrawal. refuses() includes the quarantine. The hash is withheld from serve, probe, DHT announce, the origin-held index, and re-acquisition. ServeAudit::Unavailable { evicted } is renamed { withdrawn } and covers the quarantine, so dispatch answers EvictedSinceProbe and never runs a paid miss-path fill for it.

  • Release. The quarantine drops the protecting tags (also for pinned hashes) so GC reclaims the entry.

    • protect_partial and the streaming commit skip the tag for a quarantined hash.
    • Each origin rescan drops the tags of a still-held quarantined entry again. That covers a fill that raced the quarantine and retries a failed tag drop.
  • Lift. The quarantine lifts once the store reports NotFound. The check runs in has, serve_audit, pull_through_range, and each origin rescan. A pull-through then re-admits a verified copy.

  • Observability.

    • New counter decdn_cache_held_corruption_quarantined_total, with a registry row and the fresh-registry exposure test.
    • A distinct warn when GC is disabled.
    • A debug log when the lift's status check fails.
  • Docs.

    • ADR 038 and the engine doc comments no longer claim held content is never re-hashed.
    • ADR 040 describes the quarantine.
    • evict is no longer described as corruption recovery in the CLI help, the admin RPC, protocol EvictedSinceProbe, or ADR 011.

Review follow-ups (pr-review-toolkit)

Fixed in 1e905bd:

  • Critical: a quarantined hash fell through dispatch into the paid fill, which re-tagged the corrupt entry and wedged the quarantine.
  • A quarantined hash was refused as NotFound after a signed probe.
  • A truncated data file (Io) did not quarantine.
  • A failed tag drop was never retried.
  • A partial-blob false positive was possible.
  • Test gaps and doc accuracy.

Deferred, not in this PR:

  • A typed CacheError::StoredCorruption so callers such as seed_held_outboard can log a quarantine distinctly (today it is CacheError::Store + the engine warn).
  • A gauge of currently quarantined hashes.
  • inspect/evict --dry-run reporting quarantine.
  • With fs_rescan_interval_sec = 0, a reclaimed origin-held hash re-enters the DHT set only when a lookup lifts it.

Out of scope: the ADR 003 voucher claim (#1985). The issue's items 2 and 3 lose their motivation per the verification comment.

Test plan

  • crates/cache/tests/held_corruption.rs (8 tests), which tamper with the live store:
    • leaf mismatch: quarantine, refuses, has false, serve_audit withdrawn, gone from iter_hashes, get refused, idempotent counter, not evicted
    • outboard_pairs trip
    • parent mismatch via .obao4
    • truncated data file
    • an absent blob does not quarantine
    • a partial blob: an absent range does not quarantine, corruption in a present range does
    • a pinned hash is GC-reclaimed, serve_audit lifts, and a re-pull serves
    • the rescan-only lift
  • Mutation check: forcing the partial guard to always quarantine fails the partial test.
  • cargo nextest run -p decdn-cache -p decdn-node -p decdn-common -p decdn-protocol: 2156 passed
  • clippy -D warnings --all-targets, cargo doc -D warnings, pre-commit

Suggest retitling #1984 per the verification comment: "cache: no post-admission scrub; rotten blobs stay advertised until a serve trips".

🤖 Generated with Claude Code

https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j

… mismatch (#1984)

Every serve export already validates held bytes against the content root
(iroh-blobs traverse_ranges_validated), so a rotten or tampered chunk group
aborts the serve and is never billed. The node never acted on that mismatch:
the hash stayed served and announced until a permanent operator evict.

A LeafHashMismatch/ParentHashMismatch from export_bao_range_stream or
outboard_pairs now quarantines the hash in memory. refuses() withholds it
from serve, announce, and re-acquisition; its tags drop (pin included) so GC
reclaims the entry; the quarantine lifts once the store no longer holds the
hash (lazily on has/serve_audit/pull_through_range and on each origin
rescan), and a pull-through re-admits a verified copy.

Adds decdn_cache_held_corruption_quarantined_total and corrects ADR 038 /
engine docs that claimed held content is never re-hashed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
@thiras thiras self-assigned this Sep 14, 2026
@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.75% (was 82.75%, ● 0.00%) — 77118/93194 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 93.01% 4911/5280 ▼ 0.03%
crates/cache/src/ranged_store.rs 100.00% 140/140 ● 0.00%
crates/common/src/admin.rs 93.86% 107/114 ● 0.00%
crates/node/src/handlers/client/dispatch.rs 82.16% 479/583 ● 0.00%
crates/node/src/handlers/client/serve_encoder.rs 90.63% 445/491 ● 0.00%
crates/node/src/handlers/client/window.rs 70.52% 299/424 ▼ 4.54%
crates/node/src/metrics.rs 94.68% 889/939 ▲ +0.02%
crates/protocol/src/client.rs 97.53% 1064/1091 ● 0.00%
History
Commit Total Δ vs base
75c73b9 82.76% ▲ +0.02%
1e905bd 82.75% ▲ +0.01%
661430b (HEAD) 82.75% ● 0.00%

…l re-protection

Review follow-ups on the #1984 quarantine:

- ServeAudit::Unavailable { evicted } becomes { withdrawn } and covers a
  quarantine, so dispatch answers EvictedSinceProbe instead of running the paid
  miss-path fill, which re-tagged the corrupt entry and wedged the quarantine.
- protect_partial and the streaming commit skip the tag for a quarantined hash;
  each origin rescan re-drops the tags of a still-held quarantined entry, which
  also retries a failed tag drop.
- A short read over a complete blob quarantines. A partial blob quarantines only
  when the failing groups lie inside its present ranges, so a sparse absent range
  never withdraws healthy content.
- Log when GC is disabled and when the lift's status check fails.
- Docs: stop naming evict as corruption recovery (CLI help, admin RPC, protocol
  EvictedSinceProbe, ADR 011); fix pin wording, validation scope, lazy lift, and
  ASD-STE100 splits in ADR 038/040.
- Tests: parent mismatch via .obao4, truncation, partial present/absent ranges,
  serve_audit withdrawn + lift, rescan bulk lift.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
@thiras
thiras marked this pull request as ready for review September 14, 2026 08:50
Copilot AI lite review requested due to automatic review settings September 14, 2026 08:50

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.

🟡 Changes recommended

Unresolved moderate findings remain in partial-blob quarantine classification and paid miss-path validation; documentation nits also remain.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds serve-triggered quarantine for held blobs whose validated serving detects stored corruption, allowing GC-based recovery and later re-admission.

Changes:

  • Adds quarantine lifecycle, withdrawal gates, tag release/retry logic, and recovery checks.
  • Adds corruption metrics and coverage for mismatches, truncation, partial ranges, and GC recovery.
  • Updates protocol semantics, operator documentation, ADRs, and changelog.

Final review comments identify three moderate findings in engine.rs (votes: 3, 1, 1), one moderate finding in dispatch.rs (1 vote), and documentation nits in engine.rs, protocol/src/client.rs, and adr/040-cache-policy.md (1, 2, and 1 votes respectively).

File summaries
File Reviewed change
crates/protocol/src/client.rs Documents quarantine withdrawal response semantics.
crates/node/src/metrics.rs Exposes the quarantine metric.
crates/node/src/handlers/client/serve_encoder.rs Updates serve refusal documentation.
crates/node/src/handlers/client/dispatch.rs Handles withdrawn hashes during miss fills.
crates/common/src/cli/node.rs Updates eviction help text.
crates/common/src/admin.rs Updates administrative eviction documentation.
crates/cache/tests/held_corruption.rs Tests corruption detection, quarantine, truncation, partial ranges, and recovery.
crates/cache/src/ranged_store.rs Applies quarantine refusal behavior.
crates/cache/src/metrics.rs Adds the quarantine counter.
crates/cache/src/engine.rs Implements quarantine detection, lifecycle, tag handling, and lifting.
CHANGELOG.md Records the quarantine behavior.
adr/appendix-observability.md Documents the new metric.
adr/040-cache-policy.md Specifies the cache quarantine policy.
adr/038-bao-verified-range-streaming.md Documents validated range streaming.
adr/011-content-takedown.md Clarifies withdrawal and takedown semantics.
Review details

Suppressed comments (5)

adr/040-cache-policy.md:341

  • This ADR overstates the short-read trigger for partial blobs. The implementation deliberately does not quarantine a partial blob on UnexpectedEof, because an absent sparse range can produce the same error; only a complete blob always quarantines, and partial mismatches are quarantined only when their failing groups are present. Please state that exception here so the policy matches quarantine_on_mismatch.
content root. A hash mismatch or a short read over held content means that the
stored copy changed after admission, from disk rot or tampering. The engine
then quarantines the hash. The node stops serving, announcing, and
re-acquiring the hash. A stream request for it answers `EvictedSinceProbe`.

crates/cache/src/engine.rs:625

  • This documentation now contradicts the dispatch behavior introduced in this PR: dispatch rejects every withdrawn audit before entering the fill path, so a fill cannot undo an operator eviction. Please describe re-acquisition only for a quarantine after GC has reclaimed the entry; otherwise callers reading this public enum may assume an evicted hash can be restored by a normal fill.
        /// miss path must not fill a withdrawn hash. A fill of an evicted hash
        /// undoes the takedown. A fill of a quarantined hash lands on the
        /// corrupt entry and pays for bytes it can never serve.

crates/cache/src/engine.rs:2765

  • A partial blob can have a real short read in a range it does hold—for example, truncating its data file and serving that present range. UnexpectedEof is mapped to ChunkRanges::all(), so the containment check necessarily overlaps the absent ranges and leaves the hash unquarantined; later serves of the still-present ranges repeat the failure. Keep the absent-sparse-range false-positive guard, but pass the requested/failing range (or its location) into this classification so an EOF in a present range is quarantined; add a regression for a truncated partial range.
    /// so any of the three errors quarantines it. A partial blob is
    /// quarantined only when the failing chunk groups lie inside its present
    /// ranges; a short read never quarantines a partial blob. Every other

crates/cache/src/engine.rs:4408

  • This quarantine hook only handles errors emitted by export_bao. The paid cache-miss serve path uses CoherentFrameProducer/encode_ranges_validated over NodeRangedStore::read, so a held range corrupted after seed_held_outboard can abort that serve without entering quarantine_on_mismatch; the next request can repeat the same failure. Route that validation failure through the quarantine path (or use the same exporting path for the miss serve).
                            Some(EncodedItem::Error(cause)) => {
                                engine.quarantine_on_mismatch(hash, &cause).await;

crates/node/src/handlers/client/dispatch.rs:621

  • This only checks the initial serve_audit snapshot. In the miss path, window opens the paid pull leg before seed_held_outboard, whose outboard_pairs call can quarantine a corrupt held range. A partial blob with a missing requested span therefore still proceeds into the fill, then gets withdrawn during seeding. Validate held ranges before opening the pull or re-check refuses at that boundary so a quarantined hash cannot start a paid fill.
            if audit.is_withdrawn() {
  • Files reviewed: 15/15 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 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/protocol/src/client.rs Resolved
…ll after seeding withdraws the hash

Copilot review follow-ups on #2002:

- ParentHashMismatch names a node whose chunk_range() is already in 1 KiB
  chunks; the extra << chunk_log widened it 16x, so a real parent mismatch on a
  partial blob overlapped absent ranges and went unquarantined.
- A short read now counts over the requested export range, so an EOF inside a
  partial blob's present ranges quarantines instead of never counting.
- The serve-miss window paths check refuses() right after seed_held_outboard
  and skip spawning the paid pull (upstream or origin egress) when seeding
  quarantined the hash; the owner fails the session, releases leases, and frees
  the floor reservation.
- Docs: EvictedSinceProbe summary says "withdrew"; ADR 040 states the partial
  exceptions; ServeAudit::withdrawn wording is conditional.
- Tests: parent mismatch inside a partial's present ranges; short read over a
  partial's present range.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
@thiras

thiras commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Response to the Copilot review's suppressed findings (all in 661430b unless noted):

  1. ADR 040 short-read trigger for partials. Fixed. The ADR now states the partial exceptions: a mismatch must lie inside the present ranges, and a short read counts only when the whole requested export range is present.

  2. ServeAudit::withdrawn doc (engine.rs:625). Reworded to the conditional ("would undo…"). It now says a quarantined hash becomes fillable only after GC reclaims it, and an evicted hash never does.

  3. EOF in a present range of a partial. Fixed. The classifier now takes the requested export range, and Io(UnexpectedEof) quarantines a partial when that whole range is present. Regression: a_short_read_over_a_partial_blobs_present_range_quarantines.

  4. Paid pull starts before seed_held_outboard can quarantine (dispatch.rs:621 / window.rs). Fixed. Both serve-miss paths (peer and own-origin) check refuses(hash) right after seeding. When the hash is refused, the owner:

    • does not spawn the pull leg;
    • fails the session;
    • releases its leases;
    • frees the floor reservation.

    This mirrors the existing spawn-failure teardown. Seeding stays after the response. Moving it before step 6b would change the claim/response ordering (perf(node): last-out serve-miss observer joins the pull, freeing a finished owner #1664) for a one-shot, bounded case.

  5. Miss-path encoder corruption bypasses quarantine (engine.rs:4408). Not changed.

    • seed_held_outboard runs outboard_pairs over every present range at the start of each serve-miss. That export validates the leaves as well as the parents, so a held range that is already corrupt quarantines there. With (4), no pull is spawned either.
    • The gap left is bytes that go bad on disk during one in-flight serve, after its seed. encode_ranges_validated still refuses to emit them, so nothing unverified is billed.
    • The next request re-seeds and quarantines, so the failure cannot repeat. Routing node-crate encoder errors back into the engine would add a cross-crate error path for that one-serve window.

@thiras
thiras merged commit 7ee656c into main Sep 14, 2026
25 checks passed
@thiras
thiras deleted the worktree-1984-held-corruption-quarantine branch September 14, 2026 09: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

Development

Successfully merging this pull request may close these issues.

cache: corrupt-at-rest blobs keep earning paid serves — no post-admission integrity audit

2 participants