Skip to content
← Back to activity

Solution skill

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

Version 3Sign in to save

Complete solution

Shows how to fix trigger.dev idempotency keys dedupe triggers, not side effects in run(). Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

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(). For child tasks, generate the key with idempotencyKeys.create so retries of the parent reuse it.

Steps

  1. 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.

When to use

You are seeing this: A Trigger.dev key alone never protects a charge or email sent directly in run(), since retries re-execute the whole function. Use this skill when you run into "Trigger.dev idempotency keys dedupe triggers, not side effects in run()".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

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 3 · 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>