Repository navigation
Description
Summary
decdn fetch buffers the entire blob in RAM and writes it to --output all-at-once at the end. If the fetch is interrupted, nothing usable lands on disk and re-running re-fetches (and re-pays for) the whole blob from byte 0. This tracks making the CLI fetch stream validated bytes to disk incrementally and resume an interrupted download, re-paying only for the un-fetched tail.
The cryptographic machinery for this already exists — this is contained to the CLI plus a small surface in client-pull; no protocol change.
Current behavior
fetch_blobreturns the whole blob as aVec<u8>; the client-pull receive loop accumulates every chunk into an in-memoryBytesMutuntilStreamEnd(crates/client-pull/src/lib.rs:624,:647).- Verification runs on the complete buffer via bao (
decode_verified_range,crates/client-pull/src/lib.rs:688). write_blob_atomicthen does onewrite_all→ fsync → atomic rename into--output(crates/cli/src/commands/fetch.rs:571).- The CLI always passes
byte_offset = 0(crates/cli/src/commands/fetch.rs:369), so there is no resume.
Why it's tractable
Delivery uses bao verified-streaming: each 16 KiB chunk group is verified against the content root as it decodes, not a single whole-blob re-hash at the end. So:
- Every validated chunk group is independently trustworthy → safe to flush to disk the moment it verifies (also drops peak memory from O(blob size) to O(chunk group)).
- A range fetched at any
byte_offset > 0self-verifies against the root.client-pullalready exposesbyte_offset(stream_fetch_tracked,crates/client-pull/src/lib.rs:360/:367), and the node-side cache already imports BAO-verified partial blobs on the range-pull path (crates/cache/src/engine.rs:1681,import_bao_bytes, ADR 037/038).
Proposed work (CLI-side)
- Stream verified chunk groups to disk instead of buffering — write each bao-decoded
Leafto a<output>.partialtemp file as it verifies, rather than appending toBytesMut. - On resume, read the existing
.partiallength and pass it asbyte_offset, re-paying only for the remainder. - Promote
.partial→ final path onStreamEnd(keep the existing atomic rename).
Design decisions (settled)
- Resume offset alignment: round the resume offset down to the last fully-verified 16 KiB chunk-group boundary; truncate
.partialto that boundary before resuming. - Trusting a
.partialfrom a prior process: re-verify the on-disk prefix by recomputing its bao outboard before resuming (option (a)). Safe, and still far cheaper than re-downloading. (bao makes the resumed tail self-verify against the root, but not the on-disk prefix — hence the re-verify.) - Node reachability on resume: re-run discovery / target-node resolution (
crates/cli/src/commands/fetch.rs:291) and open/reuse a channel to whoever we land on. A different node can serve the tail since content is content-addressed.
Scope
Contained to crates/cli/src/commands/fetch.rs plus a small surface in crates/client-pull. No wire-protocol change.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
altanoruc commentedon Jul 17, 2026
Triage note for a later automated run: self-contained and mostly prescriptive (stream verified chunk groups to
<output>.partial, resume viabyte_offset, promote onStreamEnd), but one open correctness decision blocks decision-free dispatch. On resume, the newly-fetched range self-verifies against the root — but the existing.partialprefix already on disk is never re-verified against this hash. A stale, truncated, or wrong-hash.partialwould be promoted to the final path as if valid. Pin the resume-safety rule before dispatch: re-verify the on-disk prefix against the root before trusting it, vs. a sidecar recording the (hash, verified-length) the.partialbelongs to and refusing resume on mismatch.altanoruc commentedon Jul 17, 2026
Automated implementation triage found a remaining cryptographic decision, so no PR was opened. Recomputing a BAO outboard over an N-byte .partial authenticates an N-byte prefix tree, not the requested whole-blob root. The resumed BAO range independently authenticates only the tail, so the existing APIs cannot verify the retained prefix against the whole root before requesting only the tail. Please choose one safe design: persist a full-tree proof/outboard sidecar; re-fetch a proof-bearing prefix range; authenticate local prefix subtree hashes against commitments from the resumed-tail proof during receipt; or defer whole-root verification until prefix plus tail are complete. The latter two conflict with the current before-resuming wording.