Repository navigation
fix(cli): don't re-pay for an already-complete chunk-aligned partial - #1622
Conversation
A complete `.partial` whose blob size is an exact multiple of the 16 KiB chunk-group size makes `resume_offset` snap to `byte_offset == total_bytes` (it rounds down to a group boundary and there is no ragged final group to land below it). The node's range gate refuses `byte_offset >= total_bytes` with `RangeNotSatisfiable`, which collapses to the same wire `NotFound` a foreign/absent partial draws. `fetch_blob_streaming` read that as a stale partial, rewound to zero, and `set_len(0)` truncated the complete, already-paid file — re-fetching and re-paying for the whole blob. Only exact-multiple-of-16-KiB sizes hit it; a ragged final group resumes fine. Before rewinding, hash the on-disk `.partial` against the target: if it is already the blob, sync and promote it for free (0 bytes, 0 pay); only a genuine miss falls through to the rewind. The whole-file hash resolves exactly the "past the end" vs "don't have it" ambiguity the restart path could not otherwise tell apart. Placed in the restart branch (not before the open) so it fires only on this rare ambiguous refusal and adds no hashing to an ordinary incomplete resume, whose open succeeds and never reaches it. `decdn fetch` benefits now; `decdn bundle pull` inherits the fix once it shares `fetch_blob_streaming`. Adds journey 5 to the resume e2e: a complete partial for a chunk-group-aligned blob must finish with zero further payment. Co-Authored-By: Claude Opus 4.8 <[email protected]>
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (2)
WalkthroughThe fetch command now detects complete partial files after ambiguous resume refusals, verifies their hash, and promotes them without refetching. The end-to-end test covers an aligned blob whose complete partial file requires a zero-offset completion. ChangesAligned partial fetch
Estimated code review effort: 3 (Moderate) | ~20 minutes Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
Coverage reportTotal: 80.30% (was 80.33%, ▼ 0.03%) — 57160/71180 lines
History
|
There was a problem hiding this comment.
Pull request overview
Fixes a paid-pull resume edge case in the CLI streaming fetch path (fetch_blob_streaming) where a .partial file that is already complete and chunk-group-aligned could be misclassified as stale, truncated, and re-downloaded (re-paying for already-held bytes). The fix adds a targeted whole-file hash verification only on the rare ambiguous NotFound restart path, and the e2e suite gains a regression journey to ensure zero additional billing for this scenario.
Changes:
- In
fetch_blob_streaming, when a resumed open fails with an ambiguous “stale partial” signal, verify whether the on-disk.partialalready hashes to the target; if so, sync and promote without rewinding or paying. - Add an anvil-backed e2e regression (“journey 5”) covering the exact-multiple-of-chunk-group complete-partial case and asserting zero additional billed bytes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/cli/src/commands/fetch.rs | Adds a restart-branch whole-file verification to avoid truncating/promoting re-fetch for already-complete, aligned .partial files. |
| crates/e2e/tests/cli_fetch_resume.rs | Adds a new end-to-end journey to reproduce and prevent the aligned-size re-pay bug by asserting 0 additional billed bytes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…edStore The resume journeys seeded a raw .partial (old model); the gap-driven fetch resumes only from its sidecar record. Add ClientRangedStore::seed_checkpointed_prefix (test-util) and rewrite the journeys to construct a real checkpointed on-disk state: resume-saves, corrupt-caught-by-finalize-sweep, foreign-no-wedge, and the #1622 complete-partial free-finish, all under new-model semantics. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ver (P3-client of #1621) (#1631) * feat(client-pull): BlobSource + Funder + Pacer axes for the gap-driven driver Defines the substrate-agnostic driver axes (#1608): BlobSource (dumb raw-bao source), Funder (injected top-up seam), Pacer/BudgetPacer (pure draw/top-up/wait decision). Scripted test doubles + pure BudgetPacer unit tests. No PeerSource or driver yet. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): PeerSource BlobSource + bounded byte_len pull requests open_progressive_pull now threads byte_len into StreamRequest so a middle gap [offset,len) can be requested (wire already carried the field). PeerSource wraps the paid progressive pull behind BlobSource (Reader=PullReader, finish drains to the voucher watermark). Existing callers pass byte_len=0 (to-end, unchanged). Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): ClientRangedStore streaming ingest for the gap driver Consumes a gap's raw bao stream into positioned .partial + accumulating .obao4 at O(chunk-group) memory, checkpointing present-ranges durably (fsync-before-record) so a mid-gap fault resumes without re-paying the received prefix. Evolves decode_to_sink: Leaf written positioned, Parent persisted to the outboard. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(client-pull): gap-driven drive() — pull and pay for only missing_ranges drive(store, source, pacer, funder, ...) fills each gap of missing_ranges(R) via a paced PeerSource pull streamed through ingest_stream, folding the resume/ top-up/settle-wait/reseed loop behind the Pacer+Funder axes. Held ranges are read locally, never pulled, never re-paid. Money-assertion test: opened ranges == the gaps exactly. Co-Authored-By: Claude Opus 4.8 <[email protected]> * feat(cli): route decdn fetch through the gap-driven driver over ClientRangedStore decdn fetch now pulls only missing_ranges(R): the single-cursor stream loop is replaced by drive() over a ClientRangedStore + PeerSource + BudgetPacer + a CLI Funder. Channel context is shared (interior-mutable) so the driver's top-up/reseed and the source's pull see one state. Whole-file resume re-hash dropped (the store bao-verifies every byte + valid_ranges sweep). Held ranges never re-paid. Co-Authored-By: Claude Opus 4.8 <[email protected]> * docs(client-pull): correct ingest checkpoint re-pay-window doc; dedup settle-wait constants The mid-gap-fault re-pay window is up to one 4 MiB checkpoint interval (~4 default voucher intervals) x MAX_RESUME_ATTEMPTS, not "under one interval" — checkpointed bytes are still never re-paid. Relocate MAX_TOPUP_SETTLE_WAITS/TOPUP_SETTLE_BACKOFF to client-pull so drive() and bundle pull's legacy loop share one definition. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(client-pull): don't force a 15s settle-wait after every top-up BudgetPacer returned Wait whenever awaiting_settle, and fill_gap set it after every top-up, so the driver slept the full settle budget (30x500ms) before retrying. Retry the open immediately after a top-up; the bounded settle-wait now fires only when a re-open actually fails resume_may_be_stale, matching the legacy CLI loop. Co-Authored-By: Claude Opus 4.8 <[email protected]> * test(e2e): adapt cli_fetch_resume to the new sidecar-based ClientRangedStore The resume journeys seeded a raw .partial (old model); the gap-driven fetch resumes only from its sidecar record. Add ClientRangedStore::seed_checkpointed_prefix (test-util) and rewrite the journeys to construct a real checkpointed on-disk state: resume-saves, corrupt-caught-by-finalize-sweep, foreign-no-wedge, and the #1622 complete-partial free-finish, all under new-model semantics. Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(client-pull): bill the credit-window tail — payment-aware completion + paid-frontier resume The node delivers the whole blob within its credit window (ADR 003/037), so ingest_stream checkpoints bytes the vouchers haven't paid for yet. BudgetPacer returned Done on delivered>=requested, stopping before the delivered-but-unpaid tail was billed (under-pay). Done now requires PAID(wire) >= the range's wire cost; an unpaid tail tops up and re-opens at content_paid_frontier(leg_start, total, paid_wire) to re-deliver and bill it, terminating when paid catches up. A fresh/cross-invocation resume (paid_wire==0) still resumes from the disk frontier with no re-pay. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
Problem
A money bug in the CLI paid-pull resume loop (
fetch_blob_streaming), affectingdecdn fetch— anddecdn bundle pullonce it shares that path.When a
.partialis exactly complete and the blob'stotal_bytesis an exact multiple of the 16 KiB chunk-group size, a resume re-fetches and re-pays for the entire blob it already holds:resume_offset(existing_len)rounds down to a chunk-group boundary. For an exact-multiple size there is no ragged final group, sobyte_offset == total_bytes.byte_offset >= total_byteswithRangeNotSatisfiable, which deliberately collapses toNotFoundon the wire (indistinguishable from a foreign/absent blob).NotFoundas a stale partial, rewinds tobyte_offset = 0, andset_len(0)truncates the complete, already-paid file — then re-fetches and re-pays for the whole blob.Non-exact-multiple sizes are fine: they resume near the end and pay only for the trailing partial group.
Fix
In the restart branch, before rewinding to zero, hash the on-disk
.partialagainst the target hashH. If it is the blob,syncand promote it for free (0 bytes, 0 pay); only a genuine miss falls through to the rewind. The whole-file hash resolves exactly the "your offset is past the end" vs "I don't have this blob" ambiguity the restart path could not otherwise distinguish.Placement note
The reviewer suggested checking before opening the pull. This PR places the check inside the restart branch instead. A pre-open check would hash the whole
.partialon every resume, including ordinary incomplete ones — doubling hashing cost on large-file resumes (e.g. a 700 MB resume would hash ~1.2 GB). The restart-branch placement fires only on the rare ambiguousNotFound; an ordinary incomplete resume's open succeeds and never reaches it, so it adds zero hashing to the common path. The only trade is one already-failed (no-money) round-trip in the rare complete-partial case.Test
Adds journey 5 to
cli_fetch_resume.rs: a complete.partialfor a chunk-group-aligned blob must finish with zero further payment.billed 131520 extra bytes for a blob already fully on disk (the aligned-size re-pay bug)— the full wire cost of re-fetching the 128 KiB aligned blob.Verification
cli_fetch_resume(anvil-backed): RED → GREEN, journeys 1–4 unchangedcargo clippy -p decdn-cliand-p decdn-e2e --features anvil-e2e --tests: cleancargo fmt --check: cleandecdn-cli+decdn-client-pull): pass🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests