> For the complete documentation index, see [llms.txt](https://docs.zaia.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zaia.app/inbox/chat-history/recovering-queued-responses.md).

# Recovering Queued Responses

Zaia automatically retries failed Agent response generation on **WhatsApp** and **Instagram**.

This protects conversations from transient processing failures and service interruptions.

The mechanism combines fast queue processing with durable recovery tracking.

***

### When automatic recovery applies

Recovery applies when the chat owner sends a message through WhatsApp or Instagram.

It does not apply when the chat has an active human-support ticket.

Zaia creates or updates a durable recovery record when it receives the message.

It then queues the chat for Agent response generation.

{% hint style="info" %}
Recovery is automatic. No workspace configuration is required.
{% endhint %}

***

### Retry behavior

When generation starts, Zaia acknowledges the queued item and records the attempt.

If a retryable error occurs, Zaia waits 30 seconds before retrying.

Zaia performs one automatic retry. A response therefore has at most two attempts.

After the limit, Zaia preserves the final error and marks recovery as failed.

***

### Errors eligible for retry

Most transient generation errors trigger the automatic retry.

Zaia does not retry these errors:

* `NotFound`
* `PreconditionFailed`
* `BadImplementation`
* LLM provider errors that do not require an alert

### Cleanup before retry

Before retrying, Zaia removes artifacts from the failed attempt.

* It deletes the response placeholder from the chat.
* It marks the previous execution as a failed attempt.
* It ends stale running executions as failed.

This prevents orphaned placeholders, duplicate primary executions, and incorrect usage counts.

### Durable recovery

Zaia uses an in-memory queue for immediate coordination.

It also stores recovery state in the database. This lets retries survive restarts and deployments.

A recovery uses these states:

* **Pending** — waiting to run or retry.
* **Processing** — response generation is in progress.
* **Completed** — the Agent generated the response.
* **Failed** — the retry budget was exhausted.

Zaia locks recovery by chat and thread. Only one recovery can process that conversation window.

If a recovery remains processing for 30 minutes, a scheduler attempts to recover it.

{% hint style="warning" %}
Recovery cannot restore messages that fail before initial persistence.
{% endhint %}
