You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
node: audit-only download-receipt write is awaited on the paid-delivery hot path #803
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 beforeVoucherAck 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.
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.
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
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
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.
On channel-full, drop the receipt and emit a counter/log line (preserving the non-fatal contract, but now truly non-blocking).
On shutdown, drain the channel before closing the file (preserving the ordering guarantee cited in the existing comment).
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.
Activity
github-actions commentedon Jun 3, 2026
🎯 Triage report
The receipt-log
appendis awaited synchronously on the voucher-accept hot path beforeVoucherAckis sent, and all delivery streams share a single process-wideMutex<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
technical,medium,rust(existing) —bugaddedreceipt_log.appendfrom theVoucherAckpath inclient.rs:839via a bounded fire-and-forget channel; success criterion is that disk-stall can never delayVoucherAck🔗 Similar issues
💡 Notes and suggestions
Root cause pinpointing
crates/node/src/handlers/client.rs:839: thespawn_blocking(...).awaitis inside the voucher-accept arm, before theVoucherAcksend. Moving the.awaitto 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 singleMutex<File>causes all concurrent delivery streams to serialize on disk I/O — even a momentary flush stall serializes the entire node.Recommended approach
spawn_blockingcall with atokio::sync::mpsc::channel(bounded, ~1 k entries) feeding a dedicated background task that does the actualappend.Mutex<File>can then be confined to that single background task, eliminating contention on the hot path.Sub-tasks
ReceiptLogSender(mpsc sender) to the node handler contextReceiptLogWritertask at runtime bring-up (runtime/mod.rs)spawn_blocking(...).awaitinclient.rs:839with a non-blocking channel sendVoucherAckis sent even when the receipt channel is fullInteraction 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.
Add this agentic workflows to your repo
To install this agentic workflow, run
fix(node): decouple download-receipt writes from the paid-delivery ho…
perf(node): move download-receipt formatting off the voucher hot path (…