This page covers outbound durability (
DurableDelivery / OutboundQueue). For inbound durability — which is now on by default for all gateway/bot runs — see Inbound Journal and Inbound DLQ.Durable Delivery vs Outbound Resilience. Durable Delivery is the heavy option — a SQLite outbox that survives crashes and lets you
send_durable() explicitly. The lighter Outbound Resilience is now on by default in every bot adapter and retries transient failures without changing any code. Use Outbound Resilience for typical “don’t drop replies on a 429” scenarios; reach for Durable Delivery when you also need to survive process crashes.Quick Start
1
Easiest path — DurableAdapterMixin
Add three lines to any existing adapter and every
send_durable() call is crash-safe:2
Configure manually with DurableDelivery
For full control, wire up
OutboundQueue and DurableDelivery directly:How It Works
Each message moves through statuses:pending → sending → sent (or failed / permanent_failure).
State Machine
The outbox tracks six statuses:pending, sending, recovered, sent, failed, and permanent_failure.
On restart, stale sending entries transition to recovered instead of pending. This preserves the information that the send was in-flight when the crash occurred.
recovered entries are retryable like pending, but when a reconciler is supplied to drain(), they are offered to it first — allowing adapters that can check the platform to confirm delivery and avoid re-sending an already-delivered message (effectively-once). Without a reconciler, recovered entries are re-sent as normal (at-least-once, unchanged behaviour).
Status-update writes (
mark_sent, mark_failed, _claim_entry) now call conn.commit(). Without this, a terminal status could be lost on a crash, causing an already-delivered message to be redelivered. This is a reliability fix — no API change is required.Effectively-Once Delivery
Adapters that can confirm whether a prior send actually landed can upgrade durable delivery from at-least-once to effectively-once.1
Declare the capability
Set
reconciles_unknown_send=True on PlatformCapabilities:2
Implement was_delivered
Add an async method that checks the platform for a prior send:
3
Call drain_pending() at startup
DurableDelivery auto-wires the reconciler from the adapter’s capability — no extra configuration required:Choosing the Right Primitive
Configuration Options
OutboundQueue
SQLite-backed outbox. All parameters after path are keyword-only.
On first open, older
outbox.sqlite files are auto-migrated to add a lane_key column, backfilled to target. No user action required — existing outbox files continue to work.OutboundQueue.drain() signature
OutboundQueue.enqueue() signature
enqueue() accepts an optional keyword-only lane_key for per-conversation grouping. It defaults to target, so messages to the same chat share a lane under ordering="strict".
DurableDelivery
Wraps an OutboundQueue and an adapter to provide a simple .send() / .drain_pending() API.
DurableAdapterMixin.setup_durable_delivery()
Call once in your adapter’s __init__ to wire up the outbox.
deliver_with_retry()
Bounded retry without persistence — on a recoverable failure, the delay is the server-mandated wait (server_retry_after(err)) when present, otherwise compute_backoff(policy, attempt).
server_retry_after()
Extracts a server-mandated wait (seconds) from an error or response. Used internally by deliver_with_retry, ConnectionMonitor.record_error, and OutboundQueue.drain to honour explicit throttle signals over the policy backoff.
Returns
None when no hint is present — callers fall back to the policy backoff.
deliver_chunked()
Splits a long message at paragraph boundaries and sends each chunk separately. Returns the number of chunks sent.
BackoffPolicy
Controls retry timing for both deliver_with_retry and OutboundQueue.drain.
Idempotency & Drain on Startup
Idempotency Keys
Every message has anidempotency_key — a UUID generated automatically if you omit it. Reusing the same key for the same logical message prevents double-sends across retries.
send() is called again with the same key, the outbox skips the enqueue (SQLite UNIQUE constraint) and marks the existing row sent.
Drain on Startup
Calldrain_pending() once at adapter startup to replay anything that was queued before the last crash:
max_attempts. The retry gate is max(compute_backoff(policy, attempts + 1), server_retry_after(stored_err)) — the platform’s mandated wait survives across process restarts.
The hint is recovered from the stored error string, not the live exception. Only hints that survive
str(err) (python-telegram-bot RetryAfter repr, HTTP headers folded into the error message, text-form “retry after N”) are honoured on drain.Best Practices
Set reconciles_unknown_send=True only if you can answer the question reliably
Set reconciles_unknown_send=True only if you can answer the question reliably
A flaky
was_delivered that returns False for an already-delivered message will cause a duplicate send. A reconciler that raises falls back to at-least-once re-send (safe, but logged at WARNING). Only opt in when your platform provides a reliable message-status API.Don't rely on supports_idempotency_token alone for dedupe
Don't rely on supports_idempotency_token alone for dedupe
supports_idempotency_token=True is informational only — the outbox does not currently forward the token on resend. Adapters relying on provider-side deduplication should also set reconciles_unknown_send=True to get effectively-once delivery.Always set platform= for accurate error classification
Always set platform= for accurate error classification
The
is_recoverable_error() function checks platform-specific patterns (e.g., Telegram’s HTTP 409 conflict, rate-limit “retry after” responses) when a platform name is provided. Without it, only generic patterns are checked and some transient errors may be misclassified as permanent.Use a stable idempotency_key derived from the inbound message
Use a stable idempotency_key derived from the inbound message
When bridging a webhook to an outbound reply, derive the key from the inbound message ID. This ensures webhook redeliveries don’t produce duplicate outbound sends.
Keep the outbox on persistent local disk
Keep the outbox on persistent local disk
Store the outbox on a persistent, local filesystem path — not
/tmp and not a Docker tmpfs. The default suggestion is ~/.praisonai/state/outbox.sqlite.Call drain_pending() exactly once per adapter start
Call drain_pending() exactly once per adapter start
Multiple concurrent drainers fight over the same rows via SQLite’s
status = 'sending' claim mechanism. A 5-minute claim timeout releases stale claims, but concurrent drainers still produce redundant work and log noise.Proactive Path
The proactive path (BotOS.deliver) shares the reply-path rate limiter — but does not support idempotency deduplication. For durable, deduped sends use the reply-path outbox (delivery.send).
Use
delivery.send(...) when you need durability across restarts, workers, or deduplication. Use BotOS.deliver(...) for simple agent-initiated sends where rate-limiting is enough.Related
Outbound Ordering
Per-conversation FIFO ordering on this outbox — keep messages to a chat in order under retries
Dead Target Registry
Suppress permanently-dead channels — the permanent-failure complement to durable retry
Inbound Journal
Inbound counterpart — deduplicate webhook redeliveries and recover in-flight messages
Inbound DLQ
Dead-letter queue for failed inbound message processing
Delivery Config
Configure outbound resilience for all six bot channels
Bot Streaming Replies
Live-edit streaming UX for bot responses
Messaging Bots
Top-level guide to building bots with PraisonAI

