A/CAlienCodeStart a project

Agents are relearning distributed systems the hard way

An agent that retries a failed tool call can refund a customer twice. Idempotency, sagas and compensation are decades-old answers to exactly the problems agents now have in production.

  • agents
  • distributed-systems

A customer asks for a refund. The agent calls the payments API, the call times out, and the agent does what it was told to do when a tool fails: it tries again. Both calls succeeded. The customer is refunded twice, and nothing in the agent’s logs looks like an error.

This is not an AI problem. It is one of the oldest problems in distributed systems: a caller that cannot tell whether a remote action happened. Payment processors, banks and logistics platforms solved it decades ago. Many agent frameworks are only now running into it, because they were built by people optimizing for what the model says, not for what the system does.

As soon as an agent can take actions, it is a distributed system with an unusually unpredictable client. The good news is that the patterns for making such systems safe are well understood, and they apply almost unchanged.

Same problems, new caller

A tool-calling agent is a client that issues requests to other services over a network. Every classic failure mode applies: requests time out after succeeding, services fail halfway through a sequence, two workers act on the same record, messages arrive twice or out of order. What the agent adds is that the client itself is non-deterministic. Run the same task twice and it may take a different path, call tools in a different order or decide to retry when a human would not.

That combination is why the risk lands on the business rather than on the engineering team: duplicated payments, half-finished orders, emails sent twice, records overwritten. These are the failures auditors and customers notice.

As soon as an agent can act, it is a distributed system with an unpredictable client.

Five patterns that transfer directly

Agent failureDistributed-systems answerIn practice
Retry repeats a side effect (double refund)Idempotency keysEvery action carries a key derived from the task; the service ignores repeats
Workflow fails halfway (order created, payment not taken)Sagas with compensationEach step defines its undo; failure triggers the undo chain, not a shrug
Timeout leaves the outcome unknownQuery before retryCheck the system of record for the action before trying it again
Two agents update the same recordOptimistic concurrencyWrites include the version read; stale writes are rejected and re-planned
Nobody can reconstruct what happenedDurable workflow logEvery decision and tool call recorded in order, replayable for audit
Fig. 1 — agent failure modes and the patterns that already solve thempatterns, not products

Idempotency is the first control to demand

If your agents can move money, send messages or change records, every such tool should accept an idempotency key, and the key should come from the business task (this refund for this order), not from the individual attempt. Then a retry, whether triggered by a timeout, a model that changes its mind or a crashed worker, is harmless. Most payment APIs already support this; the work is making sure the agent layer uses it.

Sagas make failure a designed path

Multi-step agents fail mid-sequence far more often than single calls. A saga treats the sequence as a series of local steps, each with a compensating action: cancel the reservation, void the invoice, send the correction. The agent may decide which steps to take, but the undo logic should be ordinary, tested code.11Durable workflow engines, long used for exactly this, are a natural home for agent orchestration: they persist state between steps and survive crashes.

What is genuinely new

Two things do differ from classic distributed systems, and both argue for more rigor, not less.

  • The client can be talked into things. A normal service never decides to call an API because a document told it to. An agent can. Which actions it may take, and with what limits, has to be enforced outside the model.
  • Plans are not reproducible. You cannot replay an agent by re-running it, because it may choose differently. Replay means re-reading the recorded log of what it decided and did, which is why that log is not optional.

Why this is a leadership issue

It is tempting to treat all of this as an implementation detail for engineers. It is not, for two reasons.

First, staffing. Many agent projects are run by teams with strong machine-learning or product skills and little experience of transactional systems. That is a reasonable starting team for a prototype that drafts answers. It is the wrong team, on its own, for a system that issues refunds. The fix is organizational: pair the agent team with engineers who have built payment, order or ledger systems, and give them a say in the design of every tool that changes state.

Second, release criteria. If “the agent gets the right answer on our test set” is the only bar for production, these failures will ship. Leaders can add a simple gate: no agent may call a state-changing tool in production until the team has demonstrated duplicate-safe retries, a tested undo path and a complete action log. It costs a few weeks and prevents the incidents that end up in front of customers and auditors.

What to ask your team

  1. Which tools can change money, messages or records, and do they all take idempotency keys?
  2. What happens when an agent fails at step four of seven? Show me the undo path.
  3. When a tool call times out, does the agent check before retrying?
  4. Can two agents act on the same customer at once, and what prevents conflicts?
  5. Could we reconstruct, months later, every decision and action for a given task?

These are not exotic questions. Any team that has built payment or order-management systems will recognize them. If the team building your agents cannot answer them, pair them with one that can before the agent touches production data.

Your agents are moving from answering questions to taking actions in payments, orders, customer records or communications.

In a Strategy & Architecture Audit we review the action layer for idempotency, compensation, concurrency and auditability, and list the fixes in order of risk.

Start a project

Danilo Panaro Engineer and CEO

Danilo Panaro is an engineer and the CEO of AlienCode. He writes about building AI and software systems that hold up in production, and about the business decisions behind them.

jr3.it

All posts
The AI Act deadline moved. Your customers’ deadline didn’t.Why your pilot’s ROI won’t survive rollout