DEV Community

Cover image for Your AI Agent Completed 4 of 5 Steps. Who Is Responsible for the Damage?
Atul Kumar
Atul Kumar

Posted on Edited on

Your AI Agent Completed 4 of 5 Steps. Who Is Responsible for the Damage?

Why multi-agent workflows need failure recovery, compensating transactions, and reliable execution guarantees

There is something particularly uncomfortable about an AI agent that almost completes its job. Not an agent that crashes immediately. Not one that misunderstands a request or produces an obviously incorrect response. Those failures are relatively easy to recognise.

I am talking about an agent that completes four steps of a five-step workflow, reports progress along the way, and then fails at the exact moment when recovery becomes complicated.

Imagine an AI-powered order management system. A customer places an order. An agent creates the order, another reserves inventory, a payment service processes the transaction, and a shipping agent prepares the delivery. Everything appears to be working.

Then the shipping service times out. The payment has already been processed. Inventory is reserved. The order exists. But the shipping label has not been generated. The orchestration layer retries the operation. Meanwhile, another agent takes ownership of the workflow because the original agent appears unresponsive.

Now two agents are looking at the same incomplete transaction, neither of which has a complete understanding of what already happened. One attempts to process the payment again. The other tries to release the inventory reservation. The shipping service eventually recovers, but the system has already moved into an inconsistent state.

The interesting part is that none of the individual agents necessarily made a bad decision. The order agent did its job. The inventory agent did its job. The payment service processed the payment. The shipping agent encountered a failure.

The problem was not intelligence.

The problem was that the workflow had no reliable way to recover from partial execution.

This is a problem I think deserves considerably more attention as AI agents move from answering questions and generating recommendations to coordinating real business operations. We have spent considerable time discussing how to make agents reason better, retrieve better information, and avoid conflicting decisions. But there is another question that becomes unavoidable when these systems start executing multiple dependent actions:

What happens when the workflow cannot finish, but some of its actions have already taken effect? That is where reliable AI engineering becomes much more interesting.


1. The Dangerous Assumption: A Workflow Either Succeeds or Fails

Traditional application workflows often encourage a simple mental model. An operation starts, executes its steps, and eventually returns success or failure.

For a small operation, this model works reasonably well. Consider a function that validates an email address, checks a field, and writes a record to a database. If something fails before the transaction commits, the database can roll back the changes.

But distributed workflows are different. A single business operation may involve:

  • An order management database.
  • An inventory service.
  • A payment gateway.
  • A shipping provider.
  • A notification service.
  • Multiple AI agents coordinating the process.

These systems do not share one database transaction. A database rollback cannot automatically reverse a payment that has already been accepted by an external payment provider. It cannot guarantee that a shipping label was not generated or that an email was not delivered.

The workflow may have completed some actions permanently, while other actions remain pending. I find this distinction important because AI orchestration frameworks sometimes make multi-step execution look deceptively simple.

A workflow might be represented as:

async def process_order(order):
    await create_order(order)
    await reserve_inventory(order)
    await process_payment(order)
    await schedule_shipping(order)
    await send_confirmation(order)

    return {"status": "completed"}
Enter fullscreen mode Exit fullscreen mode

The code is easy to read. The operational behaviour is not. What happens if schedule_shipping() raises an exception?

What happens if the payment provider accepts the payment, but the response never reaches the application?

What happens if the process crashes after scheduling shipping but before recording that the operation succeeded?

What happens if another worker starts processing the same order?

The function does not answer these questions. Adding a generic retry decorator does not solve them. A reliable workflow needs to understand not just what it intends to do, but what has actually happened.

2. The Five-Step Failure That Changes Everything

Let's examine the order scenario more carefully. Suppose an AI-powered commerce platform coordinates five actions.

Step Operation Result
1 Create customer order Success
2 Reserve inventory Success
3 Process payment Success
4 Schedule shipping Failed
5 Send confirmation Not executed

At first glance, this looks like an ordinary failed workflow. But look at the actual business state. The customer has an order. The inventory is unavailable to other customers. The payment has been collected. The delivery has not been arranged.

The system is not simply unsuccessful. It is partially committed. That difference matters. If we retry the entire workflow, we risk creating another order, reserving inventory twice, or charging the customer again.

If we abandon the workflow, the customer may lose money while the inventory remains unavailable. If we reverse everything, we may need to refund the payment and release inventory, but we must first establish whether any of those operations can safely be reversed.

This is why I prefer thinking about workflows in terms of execution state rather than a single success or failure flag. A useful execution record might look like this:

{
  "workflow_id": "order-84721",
  "status": "PARTIALLY_COMPLETED",
  "steps": {
    "create_order": {
      "status": "SUCCEEDED"
    },
    "reserve_inventory": {
      "status": "SUCCEEDED"
    },
    "process_payment": {
      "status": "SUCCEEDED",
      "payment_reference": "pay-91281"
    },
    "schedule_shipping": {
      "status": "FAILED",
      "error": "Provider timeout"
    },
    "send_confirmation": {
      "status": "NOT_STARTED"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

This gives the orchestration layer something much more useful than a generic exception. It knows which operations have been completed, which have failed, and which have not started. However, there is an important caveat.

A status record is not proof that an external operation did or did not happen. A timeout after a payment request could mean the payment failed, or it could mean the payment succeeded and the response was lost. That uncertainty is one of the hardest parts of distributed execution.

3. Why Retrying Is Not the Same as Recovering

Retries are one of the first mechanisms engineers introduce when an external service becomes unreliable. A request fails. The system waits. It tries again. For transient failures, this is useful. But retries become dangerous when an operation has side effects. Consider a payment request.

async def charge_customer(amount, payment_method):
    response = await payment_provider.charge(
        amount=amount,
        payment_method=payment_method
    )

    return response
Enter fullscreen mode Exit fullscreen mode

Imagine the payment provider successfully charges the customer. Before the response reaches our application, the network connection drops. Our application sees a timeout.

It has no immediate way of knowing whether the payment happened. If it sends the same request again without additional safeguards, the customer might be charged twice. This is not an AI reasoning problem. It is a distributed systems problem.

The agent may have correctly interpreted the request, selected the right payment method, and decided that payment should be processed. The failure occurs because the system cannot safely distinguish an unsuccessful operation from an operation whose result is unknown.

I think this is where teams need to be careful about using retries as a universal recovery strategy. A retry should not mean:

"Execute the same instruction again."

It should mean: "Establish whether the previous attempt took effect, then decide whether another attempt is safe." That requires operation identity, durable state, and reconciliation.

Introduce idempotency keys

One practical solution is to assign a stable idempotency key to each logical operation. For example:

import uuid

def create_payment_request(order_id, amount):
    operation_id = f"payment:{order_id}"

    return {
        "operation_id": operation_id,
        "amount": amount,
        "idempotency_key": operation_id
    }
Enter fullscreen mode Exit fullscreen mode

The payment provider or an application-owned payment adapter can use this key to recognise repeated requests representing the same logical payment. A simplified implementation might look like:

async def process_payment(order_id, amount):
    operation_id = f"payment:{order_id}"

    existing = await payment_store.get(operation_id)

    if existing and existing["status"] == "SUCCEEDED":
        return existing

    result = await payment_provider.charge(
        amount=amount,
        idempotency_key=operation_id
    )

    await payment_store.save({
        "operation_id": operation_id,
        "status": "SUCCEEDED",
        "provider_reference": result.reference
    })

    return result
Enter fullscreen mode Exit fullscreen mode

This illustrates the approach, but a production implementation needs more. In particular, it must handle concurrent requests, uncertain provider responses, key-retention policies, and atomic persistence of operation state.

A local lookup alone does not prevent two workers from sending the same request simultaneously. The important principle is that the same logical operation should not accidentally become multiple independent business actions.

Idempotency protects the workflow from repeated delivery. It does not automatically protect it from every kind of partial failure.

That brings us to a more fundamental design pattern.

4. The Saga Pattern: Recovering Without a Global Rollback

In distributed systems, one widely used approach to managing long-running business transactions is the Saga pattern. Instead of treating an entire workflow as one atomic database transaction, a Saga breaks it into smaller transactions.

Each transaction commits independently. When a later step fails, the workflow can execute compensating transactions for earlier completed steps. For our order example:

Forward operation Possible compensation
Create order Cancel order
Reserve inventory Release reservation
Process payment Refund payment
Schedule shipping Cancel shipment, if supported
Send confirmation Send correction or cancellation notice

This is a powerful idea, but it is important to understand what compensation actually means. A compensating transaction is not a database rollback. If a payment has been processed, a refund does not erase the original payment. It creates another financial operation that offsets it.

If a customer has already received an email, the system cannot make that email disappear. It can send a correction. If a package has already left a warehouse, cancelling the shipment may no longer be possible. Compensation is a business operation designed to restore an acceptable state.

It is not necessarily a perfect reversal of history.

A simple Saga implementation

We can model the workflow explicitly.

async def execute_order_saga(order):
    completed = []

    try:
        await create_order(order)
        completed.append("order")

        await reserve_inventory(order)
        completed.append("inventory")

        await process_payment(order)
        completed.append("payment")

        await schedule_shipping(order)
        completed.append("shipping")

        await send_confirmation(order)

        return {
            "status": "COMPLETED"
        }

    except Exception as error:
        recovery = await compensate(
            order,
            completed
        )

        return {
            "status": "FAILED",
            "error": str(error),
            "completed_steps": completed,
            "compensation": recovery
        }
Enter fullscreen mode Exit fullscreen mode

The compensation logic might look like:

async def compensate(order, completed):
    results = []

    if "payment" in completed:
        results. append(
            await refund_payment(order)
        )

    if "inventory" in completed:
        results. append(
            await release_inventory(order)
        )

    if "order" in completed:
        results. append(
            await cancel_order(order)
        )

    return results
Enter fullscreen mode Exit fullscreen mode

This is a useful conceptual starting point. However, there is a serious problem with this implementation.

What happens if the application crashes while executing the compensation? The in-memory completed list disappears. The system may have already refunded the customer, but failed before recording the refund result.

When the workflow restarts, it could attempt the refund again. We have simply moved the original reliability problem into the recovery mechanism. That is why a Saga must be durable. Every meaningful state transition needs to be recorded so that another worker can continue recovery after a crash.

5. A Workflow Needs a Durable Execution History

One of the mistakes I would avoid is treating an agent's conversational memory as the source of truth for workflow execution. An agent might remember that it successfully processed a payment. But memory is not an execution ledger. The process may have restarted. Another agent may have taken ownership. The external payment provider may have updated its state.

The system needs a durable record that exists independently of the agent. I would separate three responsibilities:

The agent decides what should happen.

The orchestrator determines which operation is allowed to execute next.

The execution ledger records what actually happened.

A simplified workflow state machine might be:

             PENDING
                |
                v
           EXECUTING
                |
       +--------+--------+
       |                 |
       v                 v
   COMPLETED         RECOVERY_REQUIRED
                         |
                         v
                    COMPENSATING
                         |
                 +-------+-------+
                 |               |
                 v               v
            COMPENSATED    MANUAL_REVIEW
Enter fullscreen mode Exit fullscreen mode

The important part is that recovery is a first-class workflow state. It should not be an exception handler that exists only in the memory of the process that encountered the failure. A durable execution record could contain:

CREATE TABLE workflow_steps (
    workflow_id TEXT NOT NULL,
    step_id TEXT NOT NULL,
    operation_id TEXT NOT NULL,
    status TEXT NOT NULL,
    attempt_count INTEGER DEFAULT 0,
    idempotency_key TEXT NOT NULL,
    external_reference TEXT,
    last_error TEXT,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (workflow_id, step_id),
    UNIQUE (operation_id)
);
Enter fullscreen mode Exit fullscreen mode

For production systems, I would also maintain an append-only execution history. For example:

CREATE TABLE workflow_events (
    event_id TEXT PRIMARY KEY,
    workflow_id TEXT NOT NULL,
    operation_id TEXT NOT NULL,
    event_type TEXT NOT NULL,
    event_payload JSON,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Enter fullscreen mode Exit fullscreen mode

The first table represents the current state. The second records how the workflow reached that state. This distinction becomes particularly useful when investigating failures.

Suppose an agent claims that a payment succeeded, but the ledger shows that the payment operation was submitted and never received a confirmed result. Instead of trusting the agent's previous message, the recovery process can investigate the operation using its stable identifier and the payment provider's reference.

The execution history becomes the basis for recovery, auditing, and accountability.

6. The Problem of Unknown Outcomes

There is one failure scenario that deserves special attention. Suppose the shipping agent sends a request to generate a shipping label. The provider processes it. The response never arrives. The agent times out. Should the system retry?

Not immediately. The operation is now in an ambiguous state. It may have succeeded externally, even though the local application does not know that. I would represent this explicitly:

PENDING
   |
   v
SUBMITTED
   |
   +-------------------+
   |                   |
   v                   v
CONFIRMED           UNKNOWN
                       |
                       v
                  RECONCILING
                       |
                +------+------+
                |             |
                v             v
             SUCCESS        FAILED
Enter fullscreen mode Exit fullscreen mode

The UNKNOWN state is important. Without it, many applications collapse uncertain outcomes into ordinary failures. That creates unnecessary retries and duplicate side effects. A better recovery sequence is:

  1. Persist the operation identifier before making the external request.
  2. Submit the request with an idempotency key where supported.
  3. If the request times out, mark the outcome as unknown.
  4. Query the provider using the operation or external reference.
  5. If the operation succeeded, record success.
  6. If it definitely failed, decide whether retrying is safe.
  7. If the result cannot be established, escalate rather than blindly repeating the operation.

This process is especially important for payments, financial transfers, reservations, shipment creation, and other externally visible operations. The system should distinguish between:

  • An operation that failed.
  • An operation that succeeded.
  • An operation that might have succeeded but whose outcome is not yet known.

That third category is where many duplicate-execution problems begin.

7. Exactly-Once Execution Is Not a Magic Guarantee

AI agent frameworks and distributed workflow systems sometimes use language that makes execution guarantees sound simpler than they are. Terms like exactly-once execution can be misleading if we do not specify what is being guaranteed.

Consider a workflow that sends an external payment request. The application may guarantee that it processes a particular internal event once. But the network can fail after the provider has accepted the payment. The application cannot infer the external outcome merely from its local processing history.

In practice, I prefer designing around:

  • At least once message delivery.
  • Idempotent operation handling.
  • Durable execution records.
  • External operation reconciliation.
  • Explicit handling of unknown outcomes.

At least once delivery means an event may be delivered more than once. That is not necessarily a problem if processing is designed to be idempotent. For example:

async def handle_payment_event(event):
    operation_id = event["operation_id"]

    claimed = await claim_operation(operation_id)

    if not claimed:
        return {
            "status": "ALREADY_PROCESSED"
        }

    await apply_payment_result(event)

    return {
        "status": "APPLIED"
    }
Enter fullscreen mode Exit fullscreen mode

The important detail is that claim_operation() must be implemented with an atomic database operation or another reliable coordination mechanism. A normal check followed by an insert is not enough.

Two workers could both check that the operation does not exist, and then both proceed. A unique constraint, conditional insert, or atomic claim operation can prevent this race.

Even then, the system must account for crashes between claiming an operation and completing its side effect. This is why idempotency, durable state, and reconciliation need to work together. No single mechanism solves the entire problem.

8. Multi-Agent Workflows Introduce an Additional Problem: Ownership

So far, we have discussed a workflow controlled by one orchestrator. Multi-agent systems make recovery more complicated. Imagine that the original payment agent becomes unresponsive after submitting a payment request.

The orchestrator detects a timeout and assigns the operation to another agent. The second agent sees an incomplete payment step and decides to execute it. But the original agent may still be running. Now both agents believe they own the same work. This is a form of split-brain execution. The problem is not simply that two agents have the same information. They have competing authority to perform the same operation.

I would address this by separating task assignment from execution authority. An agent may be assigned a task, but it should not automatically receive unrestricted permission to execute every external action associated with that task. The orchestrator should maintain ownership and enforce it at the execution boundary.

For example, a workflow operation could include:

{
  "workflow_id": "order-84721",
  "operation_id": "payment:order-84721",
  "owner": "payment-agent-02",
  "lease_version": 8,
  "lease_expires_at": "2026-11-20T10:15:00Z",
  "status": "EXECUTING"
}
Enter fullscreen mode Exit fullscreen mode

The lease_version acts as a fencing token.

When ownership changes, the version increases. The execution layer checks that an agent's request carries the current version before accepting an operation. A stale worker holding version 7 cannot perform an operation that requires version 8. A simplified database update could look like:

UPDATE workflow_steps
SET status = 'EXECUTING',
    owner = 'payment-agent-02',
    lease_version = lease_version + 1
WHERE workflow_id = 'order-84721'
  AND step_id = 'process_payment'
  AND lease_version = 7;
Enter fullscreen mode Exit fullscreen mode

In a real implementation, lease expiry, ownership acquisition, and fencing checks need to be handled atomically.

Also, a fencing token only protects resources that actually validate it. An external payment provider may not understand your internal lease version, so the payment adapter must combine ownership checks with provider-side idempotency and reconciliation.

This distinction is important.

Changing the agent that owns a task does not mean the previous agent's external actions have disappeared.

Ownership transfer is a coordination operation, not a reset button.

9. What Should Happen When Compensation Also Fails?

This is where the architecture becomes more realistic. Suppose shipping fails and the system begins compensation. The payment refund is successful. But the inventory release fails because the inventory service is unavailable.

Now the workflow has moved into another partially completed state. The customer has been refunded, but the inventory remains reserved. A naive implementation might simply mark the entire workflow as compensated. That would be incorrect. The system needs to track compensation at the individual operation level. For example:

Compensation action Status
Refund payment Completed
Release inventory Retry pending
Cancel order Completed
Notify customer Pending

This is why compensation should have its own execution history. It should not be represented by a single boolean field such as rolled_back = true.

A better model might look like:

{
  "workflow_id": "order-84721",
  "status": "COMPENSATION_IN_PROGRESS",
  "compensations": {
    "refund_payment": {
      "status": "SUCCEEDED"
    },
    "release_inventory": {
      "status": "RETRY_PENDING"
    },
    "cancel_order": {
      "status": "SUCCEEDED"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

The recovery worker can continue with the unfinished compensation without repeating the successful refund. However, even this requires careful design.

What if the inventory reservation expired naturally before the release operation ran? What if another process has already released it?

What if the customer support team manually intervened? Recovery logic must check the current business state before applying another action. The purpose of compensation is to restore an acceptable outcome, not to execute a predetermined list of reverse operations regardless of what has changed.

Some failures should require human intervention

I do not think every failure should be handled autonomously. Consider these situations:

  • A payment provider reports an ambiguous transaction result.
  • A refund request is rejected.
  • A shipment has already left the warehouse.
  • Inventory is no longer available.
  • Two external systems report conflicting transaction references.

In these cases, automatically guessing the correct action can create a larger problem. A reliable system should support a MANUAL_REVIEW_REQUIRED state. The human operator should receive:

  • The workflow identifier.
  • The completed operations.
  • The failed operations.
  • The external references.
  • The compensation attempts.
  • The current ownership and execution history.
  • The specific decision requiring intervention.

This is not a failure of autonomous AI. It is a recognition that some business decisions require authority and information that the system does not possess. The best autonomous system is not the one that never asks for help. It is the one that knows when continuing automatically would be unsafe.

10. A More Reliable Architecture for AI-Orchestrated Workflows

If I were designing this architecture, I would avoid allowing individual agents to directly control every external side effect. Instead, I would use a workflow orchestrator with a durable execution ledger. The agents would propose and coordinate actions, while the orchestrator would control their execution. Here is the conceptual architecture:

                 USER REQUEST
                      |
                      v
               AI ORCHESTRATOR
                      |
          +-----------+-----------+
          |           |           |
          v           v           v
       ORDER       PAYMENT     SHIPPING
       AGENT        AGENT       AGENT
          |           |           |
          +-----------+-----------+
                      |
                      v
              EXECUTION GATEWAY
                      |
          +-----------+-----------+
          |           |           |
          v           v           v
       ORDER       PAYMENT     SHIPPING
      SERVICE      PROVIDER     SERVICE
          |           |           |
          +-----------+-----------+
                      |
                      v
             DURABLE EXECUTION
                   LEDGER
                      |
             +--------+--------+
             |                 |
             v                 v
       RECOVERY WORKER     AUDIT HISTORY
             |
       +-----+------+
       |            |
       v            v
    RETRY       COMPENSATE
       |            |
       +------+-----+
              |
              v
         HUMAN REVIEW
         WHEN NEEDED
Enter fullscreen mode Exit fullscreen mode

The architecture has several important boundaries.

The AI orchestrator understands the business workflow and determines the next appropriate step.

The execution gateway validates whether the proposed operation is allowed and whether its prerequisites remain valid.

The durable ledger records operation state and execution history.

The recovery worker handles retries, reconciliation, and compensation.

Human review handles situations where the system cannot establish a safe next action.

This architecture does not require every team to build a large distributed orchestration platform. A small application can begin with a database-backed workflow state machine and a background worker. The important part is establishing the right execution boundaries before the system starts handling more consequential operations.

11. Putting the Design Together: A Durable Workflow Example

Let's bring the concepts together with a simplified Python implementation. The following example demonstrates a workflow that persists step state, identifies logical operations, and delegates uncertain outcomes to recovery rather than blindly retrying. It is an architectural illustration. A production implementation would need atomic database operations, provider-specific idempotency, durable event publication, authentication, and concurrency control.

from enum import Enum
from dataclasses import dataclass
from typing import Optional


class StepStatus(str, Enum):
    PENDING = "PENDING"
    EXECUTING = "EXECUTING"
    SUCCEEDED = "SUCCEEDED"
    FAILED = "FAILED"
    UNKNOWN = "UNKNOWN"
    COMPENSATING = "COMPENSATING"
    COMPENSATED = "COMPENSATED"
    MANUAL_REVIEW = "MANUAL_REVIEW"


@dataclass
class WorkflowStep:
    name: str
    operation_id: str
    status: StepStatus = StepStatus.PENDING
    external_reference: Optional[str] = None


async def execute_step(step, handler, ledger):

    existing = await ledger.get(step.operation_id)

    if existing and existing.status == StepStatus.SUCCEEDED:
        return existing

    await ledger.mark_executing(step.operation_id)

    try:
        result = await handler(
            idempotency_key=step.operation_id
        )

        await ledger.mark_succeeded(
            operation_id=step.operation_id,
            external_reference=result.reference
        )

        return result

    except TimeoutError:

        await ledger.mark_unknown(
            step.operation_id
        )

        return {
            "status": "UNKNOWN",
            "operation_id": step.operation_id
        }

    except Exception as error:

        await ledger.mark_failed(
            step.operation_id,
            str(error)
        )

        raise
Enter fullscreen mode Exit fullscreen mode

Notice the most important decision in this example. A timeout does not immediately trigger another execution. It changes the operation state to UNKNOWN. A separate recovery process can then investigate the external system.

For example:

async def reconcile_operation(operation, provider, ledger):

    result = await provider.lookup(
        operation.operation_id
    )

    if result.status == "SUCCEEDED":

        await ledger.mark_succeeded(
            operation.operation_id,
            result.reference
        )

    elif result.status == "FAILED":

        await ledger.mark_failed(
            operation.operation_id,
            result.error
        )

    elif result.status == "NOT_FOUND":

        await ledger.mark_retry_pending(
            operation.operation_id
        )

    else:

        await ledger.mark_manual_review(
            operation.operation_id
        )
Enter fullscreen mode Exit fullscreen mode

The NOT_FOUND case deserves care.

A provider lookup may be eventually consistent. An operation that is not visible yet is not necessarily an operation that never happened. A production implementation should account for provider-specific consistency guarantees, query windows, and idempotency-key retention before deciding that a retry is safe. The key design decision is that execution and recovery are separate responsibilities.

An agent does not need to remain alive throughout the entire recovery process. The workflow can survive the agent, the worker, and even the application process that originally started it. That is the value of durable execution.

12. What Should Teams Measure?

A system can appear reliable while hiding significant recovery problems.

For example, a workflow might report a 99.5% completion rate.

But that number alone does not tell us how many customers were charged twice, how many refunds remained pending, or how many workflows required manual intervention.

I would measure recovery quality separately from ordinary execution success.

Here are some useful metrics:

Metric What it reveals
Partial execution rate How frequently workflows stop after some steps succeed
Unknown outcome rate How often external results cannot be established immediately
Duplicate side-effect rate Whether retries or concurrent workers create repeated actions
Compensation success rate How reliably failed workflows restore acceptable business state
Recovery time How long workflows remain incomplete
Manual intervention rate How often autonomous recovery reaches its limits
Orphaned operation count How many operations remain unresolved beyond an agreed threshold
Ownership conflict rate How often multiple workers attempt to control the same workflow

One metric I would pay particular attention to is the unresolved partial-execution rate.

It measures workflows that have completed some side effects but have not reached either a valid final state or a verified compensated state within the recovery objective. That is more informative than simply counting exceptions.

For financial workflows, I would also track duplicate charges, outstanding refunds, and payment reconciliation discrepancies independently.

A workflow can eventually report success while still having caused an earlier business error. We need metrics that expose those failures rather than hiding them behind the final status.

13. A Practical Starting Point for Small Teams

It is tempting to look at all these components and conclude that reliable AI workflows require a sophisticated orchestration platform. They do not necessarily need one. In fact, I would recommend starting smaller.

If a team is building its first multi-agent workflow, I would prioritise the following steps.

First, assign a stable operation ID to every external side effect.

Do not rely on an agent's conversation ID or a temporary request ID. The same logical payment or reservation should retain its identity across retries and ownership changes.

Second, persist every completed operation.

Do not keep the critical workflow state only in memory. If a worker crashes, another worker must be able to establish what happened.

Third, make side effects idempotent wherever possible.

Use provider-supported idempotency keys, database uniqueness constraints, and atomic claims.

Fourth, distinguish failure from uncertainty.

A timeout is not proof that an operation failed. Introduce an explicit unknown state and reconcile before retrying.

Fifth, implement compensation for the most important business actions.

You do not need a sophisticated compensation engine on day one. Start with the operations that could create financial loss or leave business resources locked.

Sixth, make recovery observable.

Give operators a clear view of partial execution, failed compensation, unresolved external operations, and ownership conflicts.

Finally, define when the system must stop and request human intervention.

These steps provide a foundation that can evolve as the number of agents, external services, and business operations increases.

The objective is not to eliminate every possible failure. It is to make sure failures do not silently become business damage.


14. The Bigger Problem: Who Is Accountable for an Agent's Actions?

There is one question I keep returning to when thinking about autonomous systems.

When an AI agent makes a recommendation, the consequences may be limited to the quality of the information it provides. When an AI agent executes a workflow, the consequences become much more tangible. A payment can be processed. Inventory can be reserved. A contract can be submitted. A customer can receive an incorrect notification.

At that point, asking whether the agent made a correct decision is no longer enough. We need to know:

  • Who authorised the operation?
  • Which version of the workflow executed it?
  • Which agent held execution ownership?
  • Was the operation submitted more than once?
  • Did the external system accept the request?
  • Was the outcome verified?
  • If the workflow failed, which compensations were completed?
  • Who decided that the system should stop and request human intervention?

These questions are not just about audit logs. They are about accountability. I believe the next generation of AI systems will need a much stronger separation between intelligence and execution authority.

An agent should be able to reason about a business operation without automatically receiving permission to perform every action it proposes. A workflow should be able to survive an agent failure without losing its execution history.

A replacement agent should be able to continue a task without unknowingly repeating what the previous agent already completed. And a recovery mechanism should be able to establish whether an action happened before attempting to reverse or repeat it.

This is where I see the distinction between an impressive AI demonstration and a reliable production system. A demonstration can show an agent completing five steps successfully.

A production system must also explain what happens when the fourth step fails; the first three have already changed the external state, and the original agent is no longer available. That is a very different engineering challenge.


15. The Workflow Is the Unit of Reliability

We often evaluate AI agents individually. We measure response quality, reasoning accuracy, tool selection, latency, and task completion. These measurements are useful, but they do not fully describe the reliability of a multi-agent application.

An individual agent can behave correctly while the overall workflow produces an incorrect business outcome. Two agents can execute perfectly according to their individual instructions and still create an inconsistent result.

A payment agent can correctly process a transaction, while a shipping agent fails to arrange delivery.

A replacement worker can correctly retry a task while accidentally repeating an external side effect. The system needs a reliability model that covers the complete lifecycle of an operation.

That lifecycle includes:

  1. Proposal.
  2. Authorisation.
  3. Execution.
  4. Confirmation.
  5. Reconciliation.
  6. Compensation, when required.
  7. Final verification.

The AI agent is one participant in this lifecycle.

It is not the lifecycle itself.

I would argue that this is one of the most important architectural shifts required as AI systems become increasingly autonomous.

We need to stop treating an agent's final response as proof that the business operation succeeded.

We need durable evidence of what actually happened.

And we need recovery mechanisms that continue working even when the agent that initiated the operation disappears.

Final Thoughts

The most dangerous AI workflow is not necessarily the one that fails immediately.

It may be the one that succeeds just far enough to make recovery difficult.

When an AI agent completes four of five steps, the system cannot simply forget the first four because the fifth one failed.

The payment still happened. The inventory may still be reserved. The order still exists.

Those actions have consequences outside the agent's reasoning process.

Retries, compensating transactions, durable execution records, idempotency, and reconciliation are not optional architectural decorations when an AI workflow controls real business operations.

They are the mechanisms that make autonomous execution manageable.

I keep coming back to a simple engineering principle:

An AI agent should not be considered reliable merely because it knows what to do. It should be considered reliable when the system can establish what it actually did, recover when something goes wrong, and prevent an incomplete workflow from becoming an irreversible business mistake.

The next time an AI workflow reports that four out of five steps succeeded, I would not start by asking why the fifth step failed.

I would ask a much more important question:

Does the system know exactly what happened during the first four?

Top comments (4)

Collapse
 
hitensethiya profile image
Hiten Sethiya •

who owns the partial state is the real question here. if each agent only knows its own step then a retry from the second agent is basically a brand new order, does the orchestrator keep a ledger of which side effects already happened so the compensating step knows what to undo

Collapse
 
katul1512 profile image
Atul Kumar •

Exactly. The orchestrator needs to own the workflow state, not leave individual agents responsible for remembering what happened across the entire process. I'd maintain a durable execution ledger that records each operation, its status, idempotency key, external reference, and any associated compensation. When another agent takes over, it should resume from that ledger rather than treat the task as a new order. The compensating step should also verify the actual external state before reversing anything, because a timeout doesn't necessarily mean the original action failed. Agents can own individual tasks, but the orchestrator must own the lifecycle and consistency of the overall workflow.

Collapse
 
hitensethiya profile image
Hiten Sethiya •

checking the real external state before compensating is the bit people forget, a timeout and a failure look the same from inside the agent. does the ledger write happen before the external call or after, because if its after a crash in between leaves a side effect nobody recorded

Thread Thread
 
katul1512 profile image
Atul Kumar •

That's exactly the gap I'd want the execution ledger to handle. I'd write the operation intent to the ledger before making the external call, with a stable operation ID and idempotency key, but keep its status as PENDING or SUBMITTED, not completed. The tricky part is that a crash can happen on either side of the external call. We might record the intent and crash before sending it, or the provider might execute the operation, and our process might crash before recording the response.

So the ledger alone cannot tell us what actually happened. On recovery, I'd reconcile against the external provider using the same idempotency key or provider reference before retrying or compensating. If the outcome is still unclear, keep it as UNKNOWN rather than risk repeating a side effect. The ledger tells us what we intended and what we observed; the external system remains the source of truth for whether the operation actually happened.