Skip to content

Reactive mid-fetch top-up for decdn bundle pull #1599

Closed

Description

@yigitdot

The reactive half of the two-tier buyer deposit (ADR 003 § Two-tier deposit) now covers two of the three paid fetch paths:

Path Proactive low-water refill Reactive mid-transfer top-up
decdn fetch (streaming) yes yes (#1497)
daemon node-to-node cache-miss pull yes yes (#1530)
decdn bundle pull yes no

Why it is missing

bundle_pull.rs:683 fetches through the buffered fetch::fetch_blob, which — like the daemon's leg before #1530 — has no paid-frontier resume, so answering a genuine InsufficientDeposit would mean re-downloading and re-paying for the delivered prefix. It gets the proactive refill only, via open_or_reuse (bundle_pull.rs:625-638).

What it needs

The same conversion #1530 did for the node, with the CLI's own machinery rather than the node's:

  • Route the per-blob fetch through the streaming path (fetch_blob_streaming) instead of the buffered fetch_blob, so it already has open_progressive_pull + content_paid_frontier + genuine_exhaustion + the MAX_TOPUP_ATTEMPTS budget.
  • Thread working_deposit, the funder gate (top_up_decision — a bundle pull CAN be a publisher-pays delegate, unlike the node, so this one is load-bearing), and the .partial file handling per blob.

Urgency

Low. A bundle is many small-to-medium blobs sharing one channel, so the proactive refill on reuse covers the common case; the gap is a SINGLE blob in the bundle larger than the remaining deposit.

Prior art: #1530 (crates/node/src/node_origin/resume.rs) and #1497 (crates/cli/src/commands/fetch.rs, the fetch_blob_streaming loop).

Activity

  1. added
    kind:feature
    rust
    area:cli
    prio:low
    on Aug 4, 2026
  2. self-assigned this
    on Aug 5, 2026
  3. alpergundogdu commented on Aug 5, 2026

    @alpergundogdu
    Contributor

    Resolve via a shared client-pull driver, not a third copy

    Flagging a coupling before anyone picks this up: the reactive top-up / resume-at-paid-frontier control loop is currently written twice — inline in crates/cli/src/commands/fetch.rs (#1497) and re-derived in crates/node/src/node_origin/resume.rs (#1530). They share only the leaf primitives in client-pull (content_paid_frontier, genuine_exhaustion, resumable_watermark, the budget constants); the orchestration loop, leg anchoring, top-up/settle-wait/reseed arms are hand-parallel in both.

    Doing this issue the naive way ("what #1530 did, a third time") lands a third copy of that loop, because neither existing one is reusable from the CLI: node_origin::resume::pull_blob is pub(super) and bound to NodeOriginDeps, and fetch_blob_streaming is private + .partial-file-shaped.

    Interaction with #1608. #1608 relocates the node leg into a PeerSource (BlobSource seam) and — per its own text — moves the reactive top-up inside it, swapping the sink to the #1607 range-aware admit path. That's node-only, though: #1607/#1608 don't touch either CLI leg, so this gap does not close as a byproduct of that work.

    Suggested sequencing:

    1. Land refactor(cache): unify blob ingest behind a range-aware cache API with retained partials #1607 (admit foundation).
    2. Build feat(node): unify miss sources behind BlobSource; remove max_blob_size_mb #1608's PeerSource on a shared client-pull driver (Sink + Funder trait + budgets) rather than hand-relocating the resume loop.
    3. This issue + a fetch.rs cleanup become thin call sites on that driver.

    If the driver seam is too much scope for #1608, defer this until #1608 is in — but do not hand-write the PeerSource loop, or the shared extraction gets more expensive and this issue pulls toward a third copy.

    The pure decide() / ResumeAction / ResumeBudgets core already in resume.rs is the extractable seam; the only per-site differences are the sink (disk .partial vs Vec vs admit), the funder (CLI top_up vs node deps.buyer.top_up_channel), and budgets — all parameterizable.

  4. alpergundogdu commented on Aug 13, 2026

    @alpergundogdu
    Contributor

    Resolved. bundle pull was routed through the same fetch::drive_fetch gap-driven core decdn fetch uses (#1633), whose reactive top-up arm (funder.top_up, bounded by max_topups — crates/client-pull/src/driver.rs:452) fires with working_deposit wired in via open_or_reuse. See crates/cli/src/commands/bundle_pull.rs:604 ("bundle pull gets reactive top-up too"). Closing as done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:clikind:featureprio:lowrust

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions