$ fssg build --deterministic --validate |

Design a Dead-Letter Queue for Failed AI Agent Runs

AI Engineering

A failed AI agent run should not disappear into a log file or return to the same retry loop. It should become a recoverable object.

Message systems solved part of this problem long ago with dead-letter queues: after repeated processing failures, a message is isolated for inspection instead of blocking normal traffic forever. Agent systems need the same operational boundary, but copying the queue pattern literally is not enough. An agent run carries more than a message. It carries decisions, tool calls, partial state, permissions, evidence, and possibly an external effect whose outcome is still unknown.

I treat the agent dead-letter queue as a quarantine for incomplete execution, not as a pile of failed prompts.

What belongs in quarantine

A run should leave the normal execution path when automatic recovery can no longer prove that another attempt is safe. Typical triggers include:

  • a retry budget has been exhausted;
  • the same deterministic validation keeps failing;
  • required evidence is missing or stale;
  • the runtime cannot determine whether an external action happened;
  • authorization expired while the run was paused;
  • the workflow definition changed and the stored state no longer maps cleanly to the current version;
  • a human decision is required before execution may continue.

This is narrower than “any exception.” Temporary transport errors may still belong in a bounded retry policy. A policy denial is usually a terminal rejection, not a queue item. An unknown payment, deployment, email, or database mutation must be reconciled before retry, not blindly redriven.

The classification matters because quarantine is a state transition with operational consequences. If every error goes there, the queue becomes noise. If only crashes go there, the dangerous ambiguous cases remain hidden inside retries.

Store a recovery envelope, not a prompt

The smallest useful dead-letter record is not {prompt, error}. It is a recovery envelope:

{
  "run_id": "run_01J...",
  "workflow_version": "sha256:...",
  "failed_step": "publish.release",
  "failure_class": "unknown_external_effect",
  "attempt_id": "attempt_04",
  "effect_id": "release_2026_10_22_1630",
  "input_ref": "artifact://inputs/sha256:...",
  "state_ref": "checkpoint://run_01J.../step-7",
  "evidence_refs": ["trace://...", "receipt://..."],
  "authority_ref": "approval://...",
  "last_observed_at": "2026-10-22T13:31:42Z",
  "resume_policy": "reconcile_then_resume"
}

Each field answers a different recovery question.

run_id identifies the execution. attempt_id identifies one try. effect_id identifies the intended external mutation across retries. workflow_version freezes the semantics that produced the state. References keep large artifacts outside the queue while preserving content identity. The authority reference tells the operator what was permitted, by whom, and for how long. The resume policy prevents an operator from turning every incident into “retry from the failed step.”

This separation follows the same principle I described in Effect IDs Before Retry: execution identity and external-effect identity are not interchangeable. A new attempt may be correct while a new effect identity would create a duplicate action.

Give failures a closed vocabulary

Free-form error text helps a human, but it is a poor control surface. I prefer a small failure taxonomy that drives allowed recovery actions.

Failure class Default action Why
transient_transport bounded retry No evidence of an accepted external effect
deterministic_validation repair input or workflow Repeating the same attempt cannot change the result
policy_denied stop or request new authority Retry must not bypass authorization
unknown_external_effect reconcile The action may already have happened
stale_evidence refresh evidence and re-evaluate The old decision is no longer justified
workflow_incompatible migrate or replay under pinned version Current code may interpret old state differently
human_decision_required explicit review Automation has reached its authority boundary

The vocabulary should be closed enough to test and broad enough to remain stable. Vendor-specific exceptions can be attached as diagnostic detail, but they should not define the recovery contract.

This extends the recovery distinctions in Retry, Resume, Roll Back, or Compensate?. A dead-letter queue is not a sixth recovery method. It is the place where the system holds a run until one of those methods becomes justified.

Redrive must be a new controlled transition

Traditional queue tooling often describes redrive as moving a message back to its source queue. AWS, for example, supports moving unconsumed messages from a dead-letter queue to a destination for processing. That transport operation is useful, but an agent runtime needs a stronger contract.

Before redrive, the system should answer five questions:

  1. What changed? Input, code, policy, evidence, dependency, or operator decision?
  2. Which identity stays stable? The run may resume; the attempt changes; an intended external effect usually keeps its effect ID.
  3. Is the old authority still valid? A repaired run must not inherit expired permission silently.
  4. Where will execution resume? From the failed step, a checkpoint, a compensation branch, or the beginning?
  5. What proves recovery? Name the checks that move the run from quarantined to resolved.

I would encode the answer as a redrive receipt:

redrive_id: redrive_01J...
source_run: run_01J...
change:
  kind: input_repair
  artifact: sha256:...
resume_from: checkpoint_step_6
preserve_effect_ids: true
authority:
  status: revalidated
verification:
  - contract-tests
  - external-state-reconciliation
  - final-artifact-hash

The receipt makes recovery reviewable. It also blocks the most dangerous operator shortcut: clicking “retry” without recording why the next attempt should behave differently.

Temporal documents another useful option: pause a durable workflow on failure, repair the cause, and resume without restarting the whole process. This avoids inventing a separate queue and reconciliation service for every long-running workflow. The architectural choice depends on the execution engine, but the invariant remains: failed work needs durable state and an explicit resume command.

Do not replay unknown side effects

The critical branch is unknown_external_effect.

Suppose an agent called a deployment API, the connection dropped, and no response reached the runtime. The deployment may have failed, succeeded, or still be running. Sending the call again is not recovery. It is a second mutation request.

The safe path is:

quarantine
  -> query target by stable effect_id
  -> if present: import receipt and continue
  -> if absent: authorize retry with the same effect_id
  -> if ambiguous: remain quarantined and escalate

This is why the dead-letter record must preserve target identity, request identity, and the last reliable observation time. Logs alone rarely provide enough structure to prove absence.

Operate the queue as a product surface

A dead-letter queue nobody owns becomes a graveyard. It needs service-level behavior:

  • alerts based on age and failure class, not only queue length;
  • an owner for each quarantined run;
  • searchable run, effect, workflow, and customer-safe identifiers;
  • bulk redrive disabled by default for consequential actions;
  • retention long enough for investigation, with sensitive payloads stored through controlled references;
  • dashboards that distinguish new, investigating, repair-ready, redriving, resolved, and abandoned states;
  • periodic tests that prove a quarantined fixture can still be inspected and recovered.

The queue also needs backpressure. If one workflow version suddenly produces hundreds of identical deterministic failures, the runtime should stop admitting more work under that version rather than filling quarantine indefinitely.

The boundary is similar to the one in Four Clocks Every AI Agent Runtime Must Keep Separate: the age of the failure, the freshness of evidence, the validity of authority, and the state of the external effect are different clocks. One created_at field cannot govern them all.

The practical invariant

My rule is simple:

A failed agent run may leave quarantine only when the system can name what changed, what remains identical, what authority applies, where execution resumes, and how success will be verified.

Without those answers, redrive is just another word for hope.

A dead-letter queue does not make an agent reliable by itself. It creates a place where uncertainty can stop without being erased. That is already a major improvement over endless retries, silent abandonment, and manual recovery from fragments of logs.

Sources

FACET AI CLI Terminal
facet@ai:~$