Dead-Letter Queues for AI Agents: Recover Failed Tasks Without Silent Data Loss
An AI agent that exhausts its retries should not disappear. A dead-letter queue preserves evidence, blocks poison loops, and creates a safe recovery path.
A failed agent task is still business data. If it vanishes after the last retry, you have built silent data loss into the workflow.
Dead-letter queues for AI agents provide a controlled destination for tasks that cannot complete normally. They stop poison messages from looping, retain the failure context, and let operators or automated repair jobs decide what happens next.
Define the Failure Envelope
An agent task can fail because a tool is unavailable, credentials expired, an output violated schema, a model refused, a human approval timed out, or the task itself is impossible. These are not equivalent.
Classify failures before choosing retry behavior:
- transient: network timeout,
429, temporary dependency outage; - repairable: malformed output, missing optional field, stale tool schema;
- policy: approval denied, forbidden action, safety restriction;
- permanent: deleted resource, invalid destination, unsupported request;
- unknown: anything not yet understood.
Only transient failures should retry automatically by default. Repairable failures may use a bounded correction step. Policy and permanent failures usually need resolution, not repetition.
Design a Useful Dead-Letter Record
The original payload is not enough. Store the operational evidence required to reproduce the decision without leaking secrets.
type DeadLetter = {
eventId: string;
taskType: string;
tenantId: string;
attemptCount: number;
firstSeenAt: string;
failedAt: string;
failureClass: "transient" | "repairable" | "policy" | "permanent" | "unknown";
errorCode: string;
inputRef: string; // encrypted object reference, not raw sensitive data
stateRef: string;
traceId: string;
agentVersion: string;
toolSchemaVersion: string;
idempotencyKey: string;
};
Keep prompts and tool results in access-controlled storage when they contain private data. The queue record should hold references and redacted diagnostics. Give dead letters a retention policy; “keep forever” is not observability.
Route With Explicit Retry Budgets
Every task should carry an attempt count and deadline. When the budget is exhausted, the consumer moves it atomically to the dead-letter destination and acknowledges the original message.
async function consume(message: Message) {
const task = decode(message);
try {
await runAgentTask(task);
await message.ack();
} catch (error) {
const failure = classify(error);
if (failure.retryable && task.attempt < task.maxAttempts) {
await message.retry(backoff(task.attempt));
return;
}
await deadLetters.publish(buildDeadLetter(task, failure));
await message.ack();
}
}
The publish-and-ack boundary must be reliable. Use broker-native dead-lettering, a transaction, or an outbox pattern so a crash cannot lose the task between those operations.
Prevent Duplicate Side Effects
Replaying an agent is dangerous when earlier attempts may have partially succeeded. The model may not know that an email was already sent or a payment request already created.
Wrap side-effecting tools with idempotency keys and durable operation records. Before execution, check whether the operation already completed. Store tool-call receipts separately from conversational memory. Agent memory is context; it is not a transaction log.
For multi-step tasks, checkpoint after each committed side effect. A replay can resume from the last verified state rather than rerun the whole plan.
Build a Triage and Replay Workflow
A dead-letter queue without ownership becomes a graveyard. Create views grouped by task type, error code, tenant, agent version, and age. Page only when user impact or volume justifies it; routine schema failures may become a ticket or automated batch repair.
Replay should be selective. First fix the cause, then choose a bounded set of messages, run a dry validation, and replay at a controlled rate. Preserve the original record and link it to the replay attempt.
Never click “redrive all” after a dependency outage without capacity limits. Thousands of recovered tasks can cause the next outage.
Test Poison Messages Deliberately
Inject invalid schemas, revoked permissions, tool timeouts, partial side effects, and model outputs that cannot be parsed. Verify that:
- attempt counts stop at the limit;
- the original work is preserved;
- secrets are redacted;
- duplicate side effects do not occur;
- replay uses the current handler while retaining version history;
- alerts contain a trace ID and clear owner.
Also test the dead-letter path itself. If its storage or broker is unavailable, your consumer must fail safely rather than acknowledge and discard the original task.
The Takeaway
Dead-letter queues turn terminal agent failures into managed operations. Classify errors, retain reproducible evidence, enforce idempotency, assign ownership, and replay gradually. The goal is not to hide failure—it is to make every failed task visible, explainable, and recoverable.
Sources
> Want more like this?
Get the best AI insights delivered weekly.
By subscribing, you agree to our Privacy Policy. You can unsubscribe at any time.
> Related Articles
pgvector Can Return 4 of Your 10 Matches—Where Did the Rest Go?
A filtered vector search can quietly starve your AI app of evidence. pgvector has a fix, but builders need to measure recall and latency before trusting it.
Agent Memory Consolidation Scheduling: When to Merge, Summarize or Forget
Your agent doesn't need more memory — it needs a maintenance schedule. Here's how to build merge, summarize, and decay policies that keep long-term agents sharp instead of senile.
LLM Output Schema Evolution: Migrating Producers and Consumers Without a Flag Day
Your JSON schema will change. Here's how to evolve LLM output contracts safely — with dual readers, shadow validation, and staged rollouts instead of a risky big-bang cutover.
Most Read
- 1 Kimi K3.1 Pro: China's Open-Weight Model Just Caught the Frontier
- 2 OpenAI Is Buying the Bottleneck: Can Orchestra Bio Cut a 15-Year Drug Timeline?
- 3 1,068 Tokens Per Second: Can Mercury 3 Change How LLMs Generate Text?
- 4 Same Price, Better Coding: How Good Is DeepSeek V4.1 Flash 1017?
- 5 Used OpenCode? Should You Rotate Your API Key After the Console Breach?
Latest News
- Claude Code Left Secrets in 1,122 GitHub Files—Check This Setting
- Gemini Omni 1.2 Flash Makes 15-Second Video Cheaper—Then Comes the Edit
- GPT-6 Cyber Can Build Exploits—But Builders Face a Different Test
- 1,122 GitHub Files Exposed Secrets—What Did “Don't Ask Again” Save?
- Gemini Omni 1.2 Flash Offers $1.05 Clips—What Does That Buy You?
- GPT-6 Cyber Hits 48.5% on ExploitGym—Who Gets the Keys?
Tags
> Stay in the loop
Weekly AI tools & insights.