Skip to content

Cross-session task queues with RedDB

Use RedDB's built-in queue to distribute agent tasks, acknowledge completed work, and plan for retries across sessions.

On this page

Keep the work outside the agent session

An agent session can end before its work is finished. A queue gives the next worker a place to find outstanding tasks, without relying on the previous session’s context window. RedDB has a built-in queue with consumer groups, acknowledgments, retries, and a dead-letter queue.

This example uses RedDB’s native queue commands through its HTTP query endpoint. It demonstrates enqueueing, reading, and acknowledging a task; a production agent still needs its own checkpoint and idempotency strategy.

Start a local database

For a local demonstration, start RedDB with the HTTP endpoint on loopback:

bash
red server --http-bind 127.0.0.1:5000 --path ./agent-tasks.rdb --dev

--dev disables authentication. Use it only on a trusted local machine; configure authentication for any shared deployment.

In a second terminal, define a helper to send native RedDB queries. This example requires curl and jq:

bash
query() {
  curl -fsS http://127.0.0.1:5000/query \
    -H 'content-type: application/json' \
    --data "$(jq -cn --arg query "$1" '{query: $query}')"
}

Create the queue

Create a work queue with a dead-letter queue and a consumer group:

bash
query 'CREATE QUEUE agent_tasks WITH DLQ agent_tasks_failed MAX_ATTEMPTS 3'
query 'QUEUE GROUP CREATE agent_tasks workers'

Workers in the same group receive work from the queue. A failed task can be retried and, after the configured attempt limit, sent to the dead-letter queue. Choose the retry and timeout settings that fit your workload.

Add and read a task

Put an identifier in the queue and read one message for a worker:

bash
query "QUEUE PUSH agent_tasks 'issue-145'"
query 'QUEUE READ agent_tasks GROUP workers CONSUMER worker1 COUNT 1'

The read response contains a message_id, payload, and delivery information. Keep the message ID: it identifies the delivery you acknowledge after the work is complete. The identifier in the payload can point to the task’s instructions and checkpoint in your own persistent task store.

Acknowledge only after the work is complete

After processing a message, acknowledge it using the actual message_id returned by QUEUE READ:

bash
# Replace 1028 with the message_id from your read response.
query "QUEUE ACK agent_tasks GROUP workers '1028'"

This tuple-based ACK works in the tested RedDB 1.26.8 release, but the engine logs a deprecation warning in favor of a delivery ID. The tested HTTP read response did not expose that ID, so check your release’s current queue contract before building a production integration around this example.

Do not acknowledge before the task and its required side effects have completed. If a worker stops before acknowledging, the queue can redeliver the message. Design the task handler for at-least-once delivery: retries can execute work more than once.

Checkpoints and idempotency are application responsibilities

A queue message is not an agent’s complete memory. To resume a long-running task, persist the progress the next session needs: for example, the task identifier, completed steps, and references to saved results. Read that checkpoint when processing a redelivered task.

A checkpoint alone does not prevent duplicate external side effects. For actions such as posting a comment or charging an API, use a stable idempotency key with the system receiving the action when it supports one. If it does not, design and test a reconciliation strategy before retrying automatically.

Graceful shutdown can save progress before the worker exits. A crash can interrupt any step, so test that path separately, including a crash after the side effect but before the acknowledgment.

What to verify before production

Run your own recovery drill with your deployed RedDB version and configuration: stop a worker before acknowledgment, observe the message’s retry behavior, restart a worker, and confirm it can read the checkpoint safely. Exercise the dead-letter path and monitor failed work. Queue persistence and recovery also depend on the storage and deployment configuration you choose.

For the full command reference, including retry delays and consumer-group operations, see the RedDB queues documentation.

Get the next dispatch.

New essays on multi-model storage, RAG, agents, security. No spam.

No spam. Unsubscribe anytime.