Bitcoin AI SEND Idempotency with bbolt: Design and Failure Cases
A stateless AI agent can still need durable transaction bookkeeping. Chat history and payment idempotency serve different purposes: the former remembers conversation context, while the latter helps prevent an uncertain request from causing a second payment.
What to store
Use a stable operation ID, a canonical fingerprint of wallet identity, network, destination, and requested total, a state, timestamps, and the original engine response. Never store wallet secrets or AI provider credentials in this ledger.
Suggested state machine
reserved means the request has been atomically claimed before invoking the engine. succeeded means the engine returned a successful transaction result. rejected means a definite failure was received. unknown means the gateway cannot tell whether the engine accepted or broadcast the payment. These states should be written with transactional bbolt updates.
Same ID versus new ID
The same operation ID and same fingerprint must not create a new send. The same ID with different amount or destination should fail with a conflict. A newly authorized payment may have a new ID even if it targets the same address; address equality alone does not make it a duplicate.
Why ten-minute expiry is limited
A short TTL is useful for temporary UI cooldowns and prototype testing. It is not a cryptographic guarantee of exactly-once payment execution. If the engine broadcast a transaction and the HTTP response was lost, deleting the record after 600 seconds could permit a second send. Keep unknown operations unresolved until reconciliation, or rely on a separately verified durable idempotency contract in the engine.
Concurrency and crashes
The reservation must be atomic so two simultaneous requests cannot both pass. Store the reservation before the external call. After a crash, do not automatically treat a reserved operation as failed. Use the original operation ID and engine transaction status to reconcile if supported.
Operational tests
Test repeated same-ID requests, same-ID conflicts, distinct-ID legitimate payments, concurrent sends, restart persistence, and simulated timeouts. A successful Docker build alone does not prove the cooldown or deduplication policy is active.
Related reading
- /blog/bitcoin-ai-send-repeat-requests-vs-duplicate-payments/
- /ask/does-bbolt-guarantee-exactly-once-bitcoin-send/
