AIGALGOAI-Native Systems

How to design recovery for long-running AI workflows

3 min read

A demo can hide failure. A production workflow cannot. The model may still be generating a sentence when a payment API has already accepted a request, a ticket has already been opened, or a device command has already been queued.

Recovery is the design that makes that situation survivable. It is not a second prompt that says “try again.”

Failure is partial by default

Distributed work fails in pieces. The client times out. The server committed. A retry arrives. A compensating action is only safe if you know what already happened.

Language models make this easier to get wrong. They will happily emit another tool call. They will not, by themselves, know whether the first call wrote a record.

Separate three kinds of work

Not every step in an AI workflow should recover the same way.

Deterministic business actions. Transfers, ledger updates, entitlement changes, and other operations that must not happen twice. These need idempotency keys, a stored outcome, and a reconciliation path.

Advisory steps. Summaries, classifications, and retrieval. Many of these can be repeated. The cost is latency and money, not a duplicated payment.

Human approvals. An approval is bound to a specific action, actor, and payload. Replaying the workflow should not invent a new approval from an old yes.

If those three kinds of work share one retry policy, the policy is wrong for at least one of them.

Record enough state to resume

A recoverable workflow keeps a durable record of:

  • The identity that started the run.
  • The step that last completed.
  • Identifiers returned by downstream systems.
  • Whether a step is unknown, committed, or compensated.
  • The correlation id that joins logs, traces, and the business event.

You cannot reconstruct that from a chat history after the session is gone. Put it in the workflow store the platform already uses for other long-running jobs, or in a store designed for the same job.

Timeouts are not rollbacks

A timeout is a statement of ignorance. It does not mean the other side failed. A recovery design has to treat “unknown” as a first-class state.

Typical options:

  • Ask the downstream system whether the idempotency key already committed.
  • Wait and reconcile from an event or a statement file.
  • Stop and require a person when the action cannot be queried.

Choosing among those options is an architectural decision. Leaving it to the model is not a decision.

Compensating actions need the same controls

If you reverse a previous step, that reversal is another enterprise action. It needs authorization, limits, and an audit record. An agent that can “undo” without those controls has a second write path that policy never reviewed.

What operators should see

When a run stops, an operator should be able to see the last known state, the identifiers involved, and the next legal step: resume, compensate, or close. They should not have to replay a prompt to guess.

The principle

Long-running AI work inherits the failure modes of distributed systems. Design recovery for those failure modes: durable state, idempotency, explicit unknown, and compensating actions that pass through the same controls as the original work. A fluent retry is not recovery.

Related reading