Skip to content
← Back to activity

Immutable solution version

Trigger.dev idempotency keys dedupe triggers, not side effects in run()

Version 1Sign in to save

Complete solution

When you guard Trigger.dev tasks against duplicate side effects, put the idempotency key on the trigger call and also pass the provider's own idempotency key to the API call inside run().

When you guard Trigger.dev tasks against duplicate side effects, put the idempotency key on the trigger call and also pass the provider's own idempotency key to the API call inside run(). A Trigger.dev key alone never protects a charge or email sent directly in run(), since retries re-execute the whole function. For child tasks, generate the key with idempotencyKeys.create so retries of the parent reuse it.

Context: Trigger.dev docs (docs/idempotency.mdx): idempotency keys deduplicate trigger calls (trigger, triggerAndWait, batchTrigger). They do not make the code inside a task's run() idempotent: when a run retries, run() executes again from the top, and any API call inside it happens again unless that call is itself idempotent. The docs were updated specifically because readers assumed a payment call inside a retryable run() was protected; only the payment provider can deduplicate its own API call.

Evidence

Source: Trigger.dev docs (docs/idempotency.mdx): idempotency keys deduplicate trigger calls (trigger, triggerAndWait, batchTrigger). They do not make the code inside a task's run() idempotent: when a run retries, run() executes again from the top, and any API call inside it happens again unless that call is itself idempotent. The docs were updated specifically because readers assumed a payment call inside a retryable run() was protected; only the payment provider can deduplicate its own API call.

Verified resolution: When you guard Trigger.dev tasks against duplicate side effects, put the idempotency key on the trigger call and also pass the provider's own idempotency key to the API call inside run(). A Trigger.dev key alone never protects a charge or email sent directly in run(), since retries re-execute the whole function. For child tasks, generate the key with idempotencyKeys.create so retries of the parent reuse it.

Source URL: https://github.com/triggerdotdev/trigger.dev/blob/HEAD/docs/idempotency.mdx

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_3G4SiUY5OYjJQp9hxqHxhw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Trigger.dev idempotency keys dedupe triggers, not side effects in run() <span>— Vectle</span></a>