Repository navigation
Description
Problem
Pre-#271, `HttpOrigin::fetch` collected the response body inside its async block, so transport-layer body errors (idle timeout, mid-body connection reset, S3 `ByteStream::collect` failures) flowed through `classify_reqwest_error` / `classify_get_object_error` and were classified `Transient` vs `Permanent`. `retry_fetch` then retried transients up to `cache.origin_retry.max_retries`.
Post-#271, body errors emerge from the streaming pipeline as `io::Error` after `fetch` returned `Ok` and `retry_fetch` already exited. They surface to the engine via the side-channel and become a generic `CacheError::OriginError` (or typed `BlobTooLarge` / `DecompressionFailed` for the relevant cap/decoder cases) — but never participate in transient/permanent retry classification.
The `OriginByteStream` doc at `crates/cache/src/origin/mod.rs` admits this explicitly: "They do not feed `retry_fetch`'s transient/permanent classification."
Operator-visible impact
- HTTP origin behind a flaky load balancer: pre-cache: FilesystemOrigin.fetch reads the entire blob into memory before returning Bytes, preventing streaming delivery to the client for large blobs #271, transient resets retried automatically; post-cache: FilesystemOrigin.fetch reads the entire blob into memory before returning Bytes, preventing streaming delivery to the client for large blobs #271, every reset is a single failure surfaced to the caller. Hit-rate degradation.
- S3 origin with intermittent throttling: `SdkError`-classified-as-Transient at headers phase still retries (correct); body-phase mid-stream throttle/disconnect does not.
- FilesystemOrigin: less impacted (FS is local; `Interrupted`/`TimedOut`/`ResourceBusy` mid-read are rare).
Why not fixed in #271
Restoring mid-stream retry would need engine-level "abort the partially-imported `TempTag`, drop the incoming stream, replay `origin.fetch` from scratch" logic. The first attempt already pushed bytes into iroh-blobs, so the second attempt has to either:
a) Tolerate the half-committed blob and not re-commit (requires de-dupe at the store layer), or
b) Drop the half-committed blob explicitly (no public iroh-blobs API to delete pre-named blobs; depends on #518's GC).
Either way: out of scope for the streaming memory-fix that #271 was filed for.
Acceptance
- Decide policy: retry-on-mid-stream-transient is an opt-in feature with a documented disk-amplification cost (each attempt strands its partial bytes until GC runs).
- Implement a retry wrapper that bypasses `add_stream` on the first attempt, collects the body, and only commits to iroh-blobs once the whole body is verified — bringing back pre-cache: FilesystemOrigin.fetch reads the entire blob into memory before returning Bytes, preventing streaming delivery to the client for large blobs #271 retry semantics for small blobs at the cost of memory.
- Or: implement mid-stream abort + restart with a counter-bounded budget that's smaller than the regular retry budget.
- Tests: HTTP body mid-stream reset now retries up to `max_retries`; assertion on dispatch count.
Related
- cache: FilesystemOrigin.fetch reads the entire blob into memory before returning Bytes, preventing streaming delivery to the client for large blobs #271 (introduced the regression)
- cache: wire iroh-blobs GC into runtime — partial-import bytes (hash-mismatch, mid-stream cap breach) currently leak disk indefinitely #518 (GC integration; needed for option (b) above)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
fix(cache): restore mid-stream retry classification (#519) (#526)
test(cache): pin single-pull coalescing of concurrent misses (#530) (#…