Why Your Webhook-Triggered AI Automation Duplicates Actions on Retries
By Abhishek Patoliya · 2026-08-13
A workflow that classifies a webhook payload with Claude, decides on an action, and calls a downstream API typically takes anywhere from 3 to 15 seconds depending on the LLM call and any validation retries. Most webhook senders time out and retry well before that — Stripe's default is 10 seconds, Shopify similar. If your automation platform doesn't return a response until the entire pipeline finishes, the sender assumes failure and fires the same event again, sometimes three or four times, and each one runs the full pipeline independently unless something stops it.
The symptom that gives it away
The tell is duplicate downstream actions with identical or near-identical Claude outputs, timestamped seconds apart, all tied to the same source event ID. If you're seeing double-sent confirmation emails or duplicate CRM notes that reference the same order number, check the webhook provider's delivery log before assuming the LLM is non-deterministic — it's very likely the same payload arrived and was processed more than once.
Fix one: acknowledge immediately, process asynchronously
Split the workflow into two: a first webhook-receiving step that does nothing but validate the payload shape and immediately return a 200, and a second step — triggered internally, not by the original webhook — that does the actual LLM call and downstream action. In n8n this means the Webhook node's "Respond" mode should return immediately rather than waiting for the whole workflow to complete, with the heavy processing continuing after the response is sent.
Webhook received
→ validate payload shape (fast, <100ms)
→ return 200 immediately
→ (async continuation) Claude classification + action
This alone eliminates most retries, because the sender gets its fast response and has no reason to resend. It does not eliminate all duplicates — a sender can still fire the same event twice for its own reasons — which is why the second fix matters more.
Fix two: an idempotency key checked before the LLM call, not after
Every inbound webhook payload that matters (Stripe events, Shopify order webhooks, most CRM webhooks) includes a unique event ID. Store processed event IDs in a small table — Postgres, Redis, even a Google Sheet for low volume — and check it as the very first step, before the Claude call runs at all.
const eventId = payload.id;
const alreadyProcessed = await db.query(
"SELECT 1 FROM processed_events WHERE event_id = $1", [eventId]
);
if (alreadyProcessed.rowCount > 0) {
return res.status(200).json({ status: "duplicate, skipped" });
}
// only now: call Claude, take the action, then record the event ID
await db.query("INSERT INTO processed_events (event_id) VALUES ($1)", [eventId]);
Checking before the LLM call matters for cost as much as correctness — a duplicate that's caught after the Claude call still burned the tokens for nothing.
The race condition this doesn't fully close
If two duplicate webhooks arrive within milliseconds of each other, both can pass the "not yet processed" check before either has written its row, and both proceed. This is rare in practice but not impossible under provider retry storms. Closing it fully requires a unique constraint on the event ID column at the database level, so the second insert fails with a constraint violation rather than relying on the read-then-write check alone — check-then-insert is a race, insert-with-unique-constraint is not.
Don't forget the LLM output itself can vary between the "duplicate" calls
If your idempotency check has a gap and the same event does get processed twice, don't assume the two Claude outputs will be identical even for an identical input — sampling variance means a duplicate can produce a differently-worded but functionally similar action. This is a second reason event-ID deduplication has to happen before the LLM call, not by comparing LLM outputs after the fact to detect duplicates; comparing outputs for similarity is unreliable where comparing event IDs is exact.
Idempotency at the downstream action, not just at the event level
Event-ID deduplication stops the same webhook payload from being processed twice, but it doesn't protect against a related failure: your workflow crashes or times out after the Claude call succeeds but before the downstream action completes, and a retry — whether from the webhook sender or your own retry logic — reprocesses an event that's technically new to your dedup table because it never finished recording as processed. The event-ID check alone can't catch this, because the row was never written in the first place.
The fix is making the downstream action itself idempotent wherever the API supports it, independent of your own event tracking. Stripe, for instance, accepts an Idempotency-Key header on charge and refund requests — pass the source webhook's event ID as that key, and Stripe itself guarantees the same charge won't be created twice even if your code calls the endpoint multiple times with identical input.
await stripe.refunds.create(
{ payment_intent: piId, amount: refundAmount },
{ idempotencyKey: `refund-${webhookEventId}` }
);
// Stripe returns the original refund object on a duplicate call
// instead of creating a second refund
Not every API supports this natively. Where it doesn't, generate your own idempotency key from stable inputs — order ID plus action type, for instance — and check for an existing record with that key before calling the API, the same pattern as the event-ID check but scoped to the action rather than the trigger.
Mark the event as "in progress" before the LLM call, not just "done" after
The insert-then-check pattern shown above closes the race between two near-simultaneous duplicates, but it leaves a gap during the actual processing time — if the Claude call takes eight seconds and a duplicate webhook arrives during those eight seconds, the dedup table doesn't have a row yet if you're only inserting after the entire pipeline succeeds. Insert a row with a processing status immediately upon receiving the event, before the LLM call starts, and update it to done only after the downstream action completes.
INSERT INTO processed_events (event_id, status) VALUES ($1, 'processing');
-- now safe to call Claude and the downstream API
UPDATE processed_events SET status = 'done' WHERE event_id = $1;
This also gives you a way to detect and clean up stuck events — anything sitting in processing status for longer than your workflow's maximum expected duration is either still running or crashed mid-flight, and either way it's worth alerting on rather than letting it sit silently.
Test this deliberately, don't wait for a real retry storm to find out
Duplicate-handling logic is exactly the kind of code that looks correct on read-through and only reveals bugs under actual concurrent load, which makes it a poor candidate for "we'll find out if it breaks." Before shipping, manually fire the same webhook payload twice in quick succession — most webhook providers' dashboards let you resend a specific delivery, which is the easiest way to reproduce this — and confirm only one downstream action results. Do this specifically for the case where the two deliveries arrive close enough together to plausibly race, not just spaced a minute apart, since spaced-out duplicates are the easy case your basic check already handles.
Keep that test as a standing regression check, not a one-time verification before launch. Any future change to the workflow — a new node inserted between the webhook trigger and the dedup check, a refactor of the async continuation — can reintroduce the race without anyone intending to, and the failure mode is silent until the day a burst of retries happens to hit the newly reopened gap.
Retries solve duplicate webhook deliveries; a related problem is a downstream API rejecting writes because your automation is sending them too fast — see Throttling Downstream API Writes So Your AI Automation Doesn't Rate-Limit Itself.
Written by Abhishek Patoliya, Senior n8n Developer & Automation Architect, Surat, India. Verified n8n Creator.