Practitioner Notes: Idempotent Handoffs Before You Add an LLM to a Custom Workflow
说明与用途
通过原子记录入站事件、使用 outbox 队列和单一状态字段,可消除重复消息,确保 CRM 数据一致,并在重试时节省 LLM 令牌。
问题
Inbound events and outbound replies can be processed or sent multiple times, causing duplicate messages, inconsistent CRM data, and wasted LLM tokens.
结果
Implementing idempotent inbound handling, outbox delivery, and partial write tracking reduces duplicate messages, ensures consistent CRM data, and saves LLM tokens during retries.
工作流
- Record inbound event with a unique key and insert-if-absent to detect duplicates.
- Enqueue a job to perform slow work, including LLM calls, after the event is recorded.
- Insert outbound replies into an outbox with a deterministic ID derived from the approved draft.
- Deliver messages from the outbox only if status is pending, updating status to sent and storing provider_id.
- Track handoff status on the CRM record with values received, matched, owned, replied.
- Maintain a dead‑letter list for events that fail repeatedly and review them manually.
- Reuse stored LLM outputs on job retries instead of generating new drafts.
证据
Before you wire an LLM into production messaging, make the handoffs on both sides of it boring: inbound events processed once, outbound replies sent once, and partial writes impossible to miss.
The insert-if-absent must be atomic (a unique index is enough). Do the slow work, including the LLM call, in the queued job, not in the webhook handler.
The outbox row id is derived from the approved draft, so approving twice or retrying delivery cannot create a second message.
Write a single handoff_status field on the CRM record: received, matched, owned, replied.
In our 72-hour audits, this list usually generates more findings than the prompts do.
- 记录日期: 2026-10-09T04:41:11.782Z