My 3-layer agent session locking fix stopped it from quietly wrecking customer records
Описание и применение
Внедрение трёхуровневой защиты (блокировка, ключи идемпотентности и упорядоченное сохранение состояния) предотвратило некорректное изменение данных внешних систем при повторных попытках и параллельных вызовах инструментов.
Задача
Agent workflows that mutate external systems (HubSpot, Zendesk, etc.) can corrupt data when retries or parallel tool calls occur, even if a per-entity lock is used.
Результат
The 3‑layer defense eliminated silent data corruption, ensuring that retries do not create duplicate external changes and that parallel tool calls do not overwrite each other.
Рабочий процесс
- Acquire per‑entity advisory lock
- Generate idempotency key at workflow boundary
- Store idempotency key before external request
- Reserve mutation in PostgreSQL table
- Execute external mutation if not already attempted
- Persist state with version check
- Release lock
Доказательства
I learned this the ugly way at 2:13 a.m. when an n8n workflow reopened a closed Zendesk ticket, reassigned the account owner in HubSpot, and then did both again when the webhook retried.
If your agent can write to HubSpot, Zendesk, Salesforce, Stripe, or your own internal APIs, a lock alone is not enough.
I split tools into two classes: read-only and mutating. Then I allowed concurrency only for read-only calls.
- Дата записи: 2026-10-19T07:56:15.157Z