Skip to content
Michael Saelee

Idempotency for voice agents that retry

By . Published . 6 minute read. In AI engineering.

A retried tool call reaches the order system as a brand-new request, so payload checks miss it. Keying each order to its call keeps it to one order.

Make an order tool safe to retry

  1. 1

    Find the id that lasts the whole call

    Use the conversation id, which stays the same across every retry in one call and changes with the next call.

  2. 2

    Send it as the idempotency key

    Pass the id in Shopify's X-Shopify-Idempotency-Key header on the request that creates the draft order.

  3. 3

    Let the agent read the answer

    Give the order tool a response schema, so a success reaches the agent as a success.

  4. 4

    Make the other writes safe

    Put a unique key and an insert-or-update on the call log, so a retried write updates the row it already made.

  5. 5

    Check it after every deploy

    Deploy workflows whole, confirm the header is still sent, and flag any call with three or more order-tool calls.

Why do voice agents send the same order twice?

A voice agent calls its tools while the conversation is still going. In this system the agent creates an order by calling a workflow that writes a Shopify draft order. When the workflow does not answer within about 60 seconds, the agent treats the call as failed and calls the tool again. The second request is not a copy of the first: the agent rebuilds it from the conversation, so the headers, the timestamp and small details of the body differ. To the order system it is a new order.

When a success looks like a failure

A slow workflow was not the only cause. The order tool had no response schema, so the agent received an empty answer even when the order had been created, read it as a failure and tried again. One call produced four draft orders that way.

Between December 2025 and January 2026, more than 10 duplicate draft orders were created across at least six calls, and staff had to find and void each one by hand. One caller gave up on the call after the agent said it was creating the order five times or more.

Why did a lock in the workflow not fix it?

The first fix was a lock kept in Redis: the workflow would mark an order as in progress and turn away a second request for it. Built inside n8n, the lock had four separate bugs. The first version of the check blocked every new order as a repeat. The corrected check never matched, so every repeat went through. The cache write failed on a missing setting. And a cache error flowed into the workflow's reply, so the agent heard a failure and retried. The lock was dropped.

The lock tried to decide whether a request was a repeat. The system already had a better fact to go on: which call the order belonged to.

How does keying the order to the call work?

Each call has a conversation id that stays the same for as long as the call lasts, across every retry, and changes with the next call. The workflow sends that id as Shopify's idempotency key when it creates the draft order. Shopify keeps the key for 24 hours: the first request creates the draft order, and any repeat with the same key gets the original order back. However often the agent calls the tool, the call has one order, and the customer gets one invoice link.

Two fixes that go with it

The key travels in the X-Shopify-Idempotency-Key header of the request that creates the draft order. The order tool also gained a response schema, so the agent reads a success as a success and stops retrying it.

Other writes get the same treatment. The call log has a unique key and an insert that updates the row when it already exists, so a retried write cannot add a second row.

How do you keep the fix from coming undone?

Check for it after every change. In this system a partial update to a workflow replaces a step's whole set of settings, and twice in the following two weeks such an update wiped working configuration: once in address validation, once in the SAP customer lookup. Workflows are now deployed whole. The project's monitoring checklist then covers the order step still sending the idempotency header, any call that calls the order tool three times or more, and any conversation with two draft orders.

Each item on that checklist is there because the failure it catches already happened once.

The decision behind it

Decision record

How an order stays single

Problem

Retried tool calls from the voice agent created duplicate Shopify draft orders, and staff had to find and void each one by hand.

Constraints
  • The agent must stay free to retry a slow tool.
  • A caller must never end up with two orders for one request.
  • Staff should not have to look for duplicates at all.
Options
  • Remove duplicates by comparing payloads. Simple, but a retry's payload differs, so it misses them.
  • A lock in Redis inside the workflow. Tried first; it had four separate bugs and was dropped.
  • Shopify's idempotency key, set to the conversation id. No new infrastructure and a 24-hour window; it protects the Shopify write only.
Decision

Key every draft order to the conversation id of its call through Shopify's idempotency header, give the order tool a response schema, and deploy workflows whole.

What I would change

Answer the agent's tool call at once and finish the order in the background, so a slow workflow no longer looks like a failure. It is on the project's list of upgrades.

Tools used

Tools used
Company or areaTools
Voice agentElevenLabs Conversational AI
Workflow automationn8n
Commerce and ERPShopify GraphQL Admin API, SAP Business One Service Layer
DataPostgreSQL, Redis

Questions people ask

Does this need a special database?

No. The key is the conversation id, and Shopify holds each key for 24 hours, so the order system does the check itself. Other writes need their own key: the call log uses a unique constraint and an insert that updates the existing row.

What if the caller really wants two orders?

Within one call, a second order request returns the first order, because the key is the call. A second order then takes a new call. That keeps the common case safe and leaves the rare one to a new conversation, where nothing can be mistaken for a retry.

Why not give the tool more time?

More time narrows the window without closing it. The order workflow runs several steps in a row, a customer lookup in SAP, address validation and the Shopify write, and together they can pass the agent's limit of about 60 seconds. A key makes a retry harmless however late it comes.

Figures and sources

Measured

  • Four draft orders from one call, before the order tool had a response schema

    From The phone-order project's bug records

  • 10+ duplicate draft orders across at least six calls, December 2025 to January 2026

    From The phone-order project's bug records

  • 5,000+ calls logged by the voice system

    From The phone-order write-up

How it is built

  • One order per call after the fix, however often the tool is called

    From The phone-order write-up

  • 24 hours that Shopify keeps an idempotency key

    From The phone-order project's records

Sources

  1. Draft orders in the Shopify Admin API (accessed )
  2. Idempotent requests (accessed )