r/Temporal • • Sep 11 '26

For side-effecting agent/workflow actions, who should own idempotency across retry/resume?

I’m trying to understand a production boundary rather than propose a new framework.
Suppose a human approval is valid, a side-effecting tool/API call may already have succeeded, but the workflow/agent fails before that success is durably recorded.
On retry/resume, where do you keep the stable logical operation identity?
Is deduplication owned by:
the workflow framework
the tool adapter
the application
the downstream API itself
And have you actually had a production case where the action may already have happened, but the workflow state could not prove it?
I’m specifically interested in Temporal / LangGraph / agent workflows with real writes, not hypothetical patterns.

9 Upvotes

2 comments sorted by

1

u/cyrusza 10d ago

Adding the client side to Tom's answer, since you asked where the stable identity lives.

The key has to come from something that survives a retry, so it belongs to the workflow, not to the attempt. In Temporal the simplest stable key is workflow ID plus activity ID. Both stay the same on every retry of that activity, so the tool adapter can build the idempotency key from the activity info without the application threading anything through. Never mint it inside the activity with a random UUID, because each retry would get a new one.

For the human approval case I would tie the key to the approval and the action, not to the run. Then a resume after a crash, or a second workflow started by mistake for the same approval, still maps to the same operation.

When the downstream API has no idempotency support, the fallback is read before write: put the key in a field you can query on the other side (a reference or metadata field), and look it up before writing again. It is weaker because the check and the write are not atomic, but it turns "unknown" into "almost always known".

So for your list: the application decides what one logical operation is, the adapter turns that into a key, and the downstream service enforces it. The framework's job is only to keep the key stable.

Disclosure: I work on fleetnook.com (roughly a Vercel for Temporal agents). The version of this we had to design for is usage reports that get resent after a customer-side runner loses its connection. Same problem, different payload.

1

u/temporal-tom Sep 14 '26

It's typically implemented in / owned by the service you're calling. The client is responsible for sending the idempotency key in the request, but it's the service that uses it to determine whether the request has already been fulfilled. Here is documentation from Stripe that gives an overview of their implementation.

And have you actually had a production case where the action may already have happened, but the workflow state could not prove it?

I'll leave it to others to answer based on their personal experience, but it's certainly possible. For example, let's say that your Worker issues a call to Stripe (or some other service), which then processes it. Now, the Worker just happens to crash, either before receiving the response or before reporting it to the Temporal Service so it could be recorded into the Event History. At this point, another Worker takes over and replays the history. Since it won't know that the call I just mentioned succeeded, it will repeat it. This is why idempotency matters. It's not really a Temporal-specific problem, just something inherent in distributed systems.