Skip to content

node: audit-only download-receipt write is awaited on the paid-delivery hot path #803

Closed

Description

@thiras

Follow-up to #248 / PR #790. Related: #802 (unbounded receipt-log growth).

Problem

The download receipt log is explicitly documented as "audit-only / non-fatal" — a write failure is swallowed (logged, delivery continues). But the write is awaited inside the voucher-accept path before VoucherAck is sent, and all delivery streams across all channels serialize through a single process-wide Mutex<File>. So while a failed write is non-fatal, a slow or full disk stalls the awaited flush(), which stalls voucher acknowledgement and therefore active paid delivery — converting an "audit-only" artifact into a delivery-latency dependency.

Evidence

  • crates/node/src/handlers/client.rs:839 — tokio::task::spawn_blocking(move || receipt_log.append(&receipt)).await is awaited in the accept arm before the redeem hint and VoucherAck.
  • crates/node/src/receipt_log.rs:272-285 — append takes a single shared Mutex<File> and does buffered write_all + flush with no timeout.
  • Combined with node: download receipt log grows unbounded — no rotation, retention, or size cap #802 (a full disk is a realistic end-state), this is a plausible delivery-stall trigger.

The in-code comment justifies awaiting on ordering/shutdown grounds but does not address disk degradation back-pressuring delivery.

Suggested fix

Decouple the audit write from the ack path (e.g. a bounded fire-and-forget channel with drop-on-overflow), or otherwise bound it so receipt-log I/O can never back-pressure paid delivery while preserving the ordering/shutdown guarantees the current comment relies on.

Filed during a repository review; verified not already tracked.

Activity

  1. added
    prio:medium
    rust
    on Jun 3, 2026
  2. github-actions commented on Jun 3, 2026

    @github-actions

    🎯 Triage report

    The receipt-log append is awaited synchronously on the voucher-accept hot path before VoucherAck is sent, and all delivery streams share a single process-wide Mutex<File>. Despite the write failure being swallowed, slow or full-disk I/O (the realistic end-state of #802) can stall the flush and therefore stall paid delivery — violating the "audit-only / non-fatal" contract. The fix is an async decoupling (bounded channel + background writer), not just error-handling.

    📊 Assessment

    Dimension Value Reasoning
    Type Bug Latent design flaw: an invariant ("non-fatal") is contradicted by the implementation
    Labels technical, medium, rust (existing) — bug added The receipt-log/ack coupling is a correctness/latency bug under disk pressure
    Coding agent Suitable Precise scope: decouple receipt_log.append from the VoucherAck path in client.rs:839 via a bounded fire-and-forget channel; success criterion is that disk-stall can never delay VoucherAck

    🔗 Similar issues

    💡 Notes and suggestions

    Root cause pinpointing

    • crates/node/src/handlers/client.rs:839: the spawn_blocking(...).await is inside the voucher-accept arm, before the VoucherAck send. Moving the .await to after the ack, or dropping it entirely in favour of a fire-and-forget channel, removes the back-pressure path.
    • crates/node/src/receipt_log.rs:272-285: the single Mutex<File> causes all concurrent delivery streams to serialize on disk I/O — even a momentary flush stall serializes the entire node.

    Recommended approach

    1. Replace the direct spawn_blocking call with a tokio::sync::mpsc::channel (bounded, ~1 k entries) feeding a dedicated background task that does the actual append.
    2. On channel-full, drop the receipt and emit a counter/log line (preserving the non-fatal contract, but now truly non-blocking).
    3. On shutdown, drain the channel before closing the file (preserving the ordering guarantee cited in the existing comment).
    4. The Mutex<File> can then be confined to that single background task, eliminating contention on the hot path.

    Sub-tasks

    • Add ReceiptLogSender (mpsc sender) to the node handler context
    • Spawn background ReceiptLogWriter task at runtime bring-up (runtime/mod.rs)
    • Replace spawn_blocking(...).await in client.rs:839 with a non-blocking channel send
    • Add drop-on-overflow metric/log
    • Graceful shutdown: flush channel before exiting
    • Unit test: verify VoucherAck is sent even when the receipt channel is full

    Interaction with #802: fixing the decoupling here (803) reduces urgency slightly but does not eliminate #802 — an overflowing channel will silently drop audit records, which may be unacceptable for dispute resolution. Resolving both is recommended.

    Generated by Agentic Triage for issue #803 · sonnet46 463.5K · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  3. added
    kind:bug
    on Jun 3, 2026
  4. self-assigned this
    on Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bugprio:mediumrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions