How to avoid duplicate email sends with Hail MCP
Description and use
An automation recipe that uses idempotency keys and external state tracking to prevent duplicate email sends when connections drop during AI agent retries.
Problem
An AI agent sends an email, the service accepts it, but the connection drops before the agent receives an answer, leading to possible duplicate emails on retry.
Outcome
Implementing idempotency keys and external state tracking prevents duplicate email sends when connections drop during AI agent retries.
Workflow
- Generate a unique idempotency key before the first send
- Pass the key and message details to Hail’s send_email tool
- Store campaign, lead, message, key, state, Hail email ID, and last attempt time in a database
- If a timeout occurs, mark the operation as unknown and do not requeue
- Before retrying, check Hail’s get_email or saved response for the key
- If the result is still unknown, pause for review instead of creating a new key
- Resume batch processing one message at a time, claiming operations atomically
- Test the lost-response scenario by simulating accept, drop, retry, and verify single acceptance
Evidence
An AI agent sends an email, then the service accepts it, but the connection drops before the agent gets an answer.
Hail’s send_email tool accepts an idempotency_key. If you leave it out, the tool creates a fresh UUID for that invocation.
If the connection drops without a result, mark the operation as unknown. Do not quietly return it to the unsent list.
- Record date: 2026-10-20T21:56:02.469Z