Skip to content

perf(cache): capture serve proof nodes during import, drop the export_bao read-back (#1790 item 4) - #1886

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/1790-item4-capture-during-import
Aug 31, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/1790-item4-capture-during-import

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Item 4 of #1790 (Group C serve-path hot-path audit). Items 7, 5, and 3 are merged; this is the deepest of the remaining items and the natural partner to item 3 — it de-loads the store actor on the fill axis the way item 3 did on the read axis.

Problem

admit_bao_stream imported a verified range via iroh-blobs' import_bao_reader, then re-read the whole range back out through the store actor with export_bao (outboard_pairs) solely to recover the outboard proof nodes for the coupled serve leg. So every admit with a serve leg attached crossed the store actor twice — write, then read-back — and the node's own fills competed with its serves for the one store actor, delaying captured wakeups and widening miss-path inter-chunk gaps.

Fix

import_bao_reader already decodes the wire into BaoContentItems internally but discards them. So drive the decode here instead: run bao_tree's ResponseDecoder directly over the header-less wire, forward each item to the lower-level import_bao handle, and collect the Parent items — which are the proof nodes — in the same pass. One decode, proof captured for free, no read-back.

Bonus: this deletes the feeder channel, the spawned import task, the 8-byte size-prefix injection, and the whole ChannelRecvStream adapter (the decoder reads the trusted total_bytes size from BaoTree directly). The import_bao item queue backpressures, so memory stays O(one item). Net −46 lines.

Behavior preserved:

  • Error classification unchanged — a decode InvalidData is a corrupt-upstream VerifyFailed; a short/truncated feed or store fault is Store.
  • The reader is still handed back on both result arms so the node ingest path can recover a parked typed peer fault.
  • outboard_pairs stays for its other caller (held-range seeding in window.rs, which has no import wire to decode).

Tests

  • admit_bao_stream_captures_proof_into_the_session_during_import (new) — proves the captured proof set equals exactly what the export_bao read-back would have recovered, so a serve leg reads back an identical outboard.
  • admit_bao_stream_rejects_corrupt_bao (existing) — confirms the VerifyFailed classification survives the decoder change.
  • partial_overlap_shares_one_fill_and_serves_r_byte_exact (node, existing) — the end-to-end park-then-resume coalesced serve, byte-exact.
  • Full cache suite (402) + full node suite (~780) green; anvil-e2e compile gate clean; clippy/doc/fmt/pre-commit clean.

#1790 status

7, 5, 3 merged; 4 (this PR) and 1 (#1884) open; 6 closed as already-considered (documented). Remaining: 2+8 (registry re-layout — modest at current scale, per my sizing note) and 9 (architectural, cold-miss only).

🤖 Generated with Claude Code

…_bao read-back (#1790 item 4)

`admit_bao_stream` imported a verified range via iroh-blobs' `import_bao_reader`,
then re-read the whole range back out through the store actor with `export_bao`
(`outboard_pairs`) solely to recover the outboard proof nodes for the coupled
serve leg. That doubled store-actor traffic per admit — the range's bytes crossed
the actor twice — and the node's own fills competed with its serves for the one
store actor, delaying `captured` wakeups and widening miss-path inter-chunk gaps.

`import_bao_reader` already decodes the wire into `BaoContentItem`s internally but
discards them, so drive the decode here instead: run `bao_tree`'s `ResponseDecoder`
directly over the header-less wire, forward each item to the lower-level `import_bao`
handle, and collect the `Parent` items — which ARE the proof nodes — in the SAME
pass. One decode, proof captured for free, no read-back. This also deletes the
feeder channel, the spawn, the 8-byte size-prefix injection, and `ChannelRecvStream`
(the decoder reads the trusted `total_bytes` size from `BaoTree` directly), and the
`import_bao` item queue backpressures so memory stays O(one item).

Error classification is preserved: a decode `InvalidData` is a corrupt-upstream
`VerifyFailed`, a short/truncated feed or store fault is `Store`, and the reader is
still handed back on both arms so the node ingest path can recover a parked typed
peer fault. `outboard_pairs` stays for its other caller (held-range seeding in
`window.rs`, which has no import wire to decode).

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

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 optimizes the cache miss/fill admit path by capturing outboard proof nodes during streamed BAO import, eliminating a redundant post-admit export_bao read-back through the store actor (issue #1790 item 4). This reduces store-actor contention on the fill axis while preserving serve-leg behavior by ensuring identical proof availability for coupled serves.

Changes:

  • Reworks CacheEngine::admit_bao_stream to drive bao_tree’s ResponseDecoder directly and feed decoded BaoContentItems into import_bao, capturing Parent items as proof nodes during the same decode pass.
  • Removes the previous feeder-channel + spawned import task + ChannelRecvStream adapter and the size-prefix injection workaround.
  • Adds a new test validating that proof captured during import matches what export_bao read-back would have produced.

💡 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
@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.40% (was 82.31%, ▲ +0.08%) — 69581/84444 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 92.84% 4605/4960 ▲ +0.46%
History
Commit Total Δ vs base
63c3858 82.39% ▲ +0.07%
3388f06 (HEAD) 82.40% ▲ +0.08%

Copilot review: the new `NonZeroU64` guard turned every `total_bytes == 0` into a
Store error, but iroh-blobs' `import_bao_reader` (the path this replaced) treated
the canonical empty hash as a no-op success. Restore that: `hash == Hash::EMPTY`
with size 0 returns `Ok(reader)` (nothing to decode, import, or protect); a zero
size under any other hash stays a Store fault (an upstream inconsistency between
the signed `total_bytes` and a non-empty content hash — the same class the old
path returned, not a bao verify failure).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu merged commit 632c6b4 into main Aug 31, 2026
24 checks passed
@alpergundogdu
alpergundogdu deleted the claude/1790-item4-capture-during-import branch August 31, 2026 16:00
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