> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentium.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Durable queue delivery

> Deliver wake hints through BullMQ while a durable store owns task state and recovery.

`DurableAgentQueue` and `DurableAgentWorker` use a separate `agentium-durable` queue. Redis carries a versioned hint with tenant/task IDs and an immutable definition digest. The [durable task store](/durable/overview) remains authoritative.

## Wire the host boundaries

This typed host factory requires a supervisor with an initialized shared durable store, producer/worker admission callbacks, and an explicitly replay-aware driver. Install `@agentium/core@4.0.0`, `@agentium/queue@4.0.0`, `bullmq`, and `ioredis` as described in the [queue quickstart](/queue/overview). Calling the factory opens Redis-backed producer/worker resources.

```typescript theme={null}
import type { DurableTaskSupervisor } from "@agentium/core";
import {
  DurableAgentQueue, DurableAgentWorker,
  type DurableDriverRegistration, type DurableQueueConfig, type DurableWorkerConfig,
} from "@agentium/queue";

export function createDurableDelivery(options: {
  connection: DurableQueueConfig["connection"];
  supervisor: DurableTaskSupervisor;
  admitTask: DurableQueueConfig["admit"];
  recheckCurrentGrants: DurableWorkerConfig["admit"];
  execute: DurableDriverRegistration["execute"];
}) {
  const queue = new DurableAgentQueue({
    connection: options.connection,
    supervisor: options.supervisor,
    admit: options.admitTask,
  });
  const worker = new DurableAgentWorker({
    connection: options.connection,
    supervisor: options.supervisor,
    admit: options.recheckCurrentGrants,
    drivers: [{ id: "save-document", version: 1, recoverable: true, execute: options.execute }],
  });
  return { queue, worker };
}
```

A submitted task must reference the same driver ID and version. `execute` receives the durable execution context; `recoverable: true` is the host's assertion that this implementation uses stable actions and handles reconciliation, not a switch that adds recovery to arbitrary code.

Producer admission runs before persistence. Worker admission runs before and after claiming the task. Versioned drivers must support stable action IDs and reconciliation; wrapping an ordinary Agent function does not make it recoverable.

## Recover delivery failures

Persistence precedes enqueue. If enqueue fails, retry the same immutable task definition or call `wake({ tenantId, taskId })`. Wake after approval or reconciliation as well. Duplicate delivery is fenced by the store; unknown effects block handler execution.

`cancel()` persists cancellation and wakes a worker. It does not immediately terminate external work. The host retries wake when delivery fails and runs a recovery sweep for persisted tasks without a delivery hint. The package does not start a hidden store scanner.

Stop workers and close producers as part of host shutdown. `stop()` drains owned work; effects still require their connector's reconciliation contract.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.