Title: Idempotency keys only dedupe task.trigger() calls — the docs list "avoiding double-charging customers" as a use case, but a payment call made directly inside run() gets no protection · Issue #4627 · triggerdotdev/trigger.dev · GitHub
Open Graph Title: Idempotency keys only dedupe task.trigger() calls — the docs list "avoiding double-charging customers" as a use case, but a payment call made directly inside run() gets no protection · Issue #4627 · triggerdotdev/trigger.dev
X Title: Idempotency keys only dedupe task.trigger() calls — the docs list "avoiding double-charging customers" as a use case, but a payment call made directly inside run() gets no protection · Issue #4627 · triggerdotdev/trigger.dev
Description: Hi — really like how deliberately this project has thought about retries (per-task config, exponential backoff, staging/prod on by default with dev opt-out documented plainly). This is about a gap in the idempotency system itself, from r...
Open Graph Description: Hi — really like how deliberately this project has thought about retries (per-task config, exponential backoff, staging/prod on by default with dev opt-out documented plainly). This is about a gap ...
X Description: Hi — really like how deliberately this project has thought about retries (per-task config, exponential backoff, staging/prod on by default with dev opt-out documented plainly). This is about a gap ...
Opengraph URL: https://github.com/triggerdotdev/trigger.dev/issues/4627
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Idempotency keys only dedupe task.trigger() calls — the docs list \"avoiding double-charging customers\" as a use case, but a payment call made directly inside run() gets no protection","articleBody":"Hi — really like how deliberately this project has thought about retries (per-task config, exponential backoff, staging/prod on by default with dev opt-out documented plainly). This is about a gap in the idempotency system itself, from reading `docs/idempotency.mdx` and `packages/trigger-sdk/src/v3/idempotencyKeys.ts` against `69f396f`. No runtime testing — happy to be corrected if this is handled somewhere I didn't find.\n\n### The shape\n\n`docs/idempotency.mdx` lists this as a use case (line 35):\n\n> **Avoiding double-charging customers** - Prevent duplicate payment processing during retries\n\nBut every code example in the same doc — including the one directly under that bullet — only shows idempotency protecting `childTask.trigger()`:\n\n```ts\nconst idempotencyKey = await idempotencyKeys.create(\"my-task-key\");\nawait childTask.trigger({ foo: \"bar\" }, { idempotencyKey });\n```\n\nAnd `idempotencyKeys.ts` confirms this is the entire surface:\n\n```ts\nexport const idempotencyKeys = {\n create: createIdempotencyKey,\n reset: resetIdempotencyKey,\n};\n```\n\nThere is no primitive that makes an arbitrary side effect idempotent — only `task.trigger()`/`triggerAndWait()` calls consume an idempotency key. A payment call made directly inside `run()`, rather than moved into a child task, gets no protection from this system at all.\n\n### Why that's a real gap, not just a docs nit\n\nRetries are on by default outside dev (`docs/errors-retrying.mdx`: *\"By default when you create your project using the CLI init command we disabled retrying in the DEV environment\"* — implying prod/staging retry by default), and the docs' own canonical retry example is:\n\n```ts\nexport const myTask = task({\n id: \"my-task\",\n retry: { maxAttempts: 4 },\n run: async (payload) => {\n const idempotencyKey = await idempotencyKeys.create(\"my-task-key\");\n await childTask.trigger({ foo: \"bar\" }, { idempotencyKey });\n throw new Error(\"Something went wrong\"); // triggers a retry of THIS task\n },\n});\n```\n\nA developer who read \"avoiding double-charging customers\" as a supported use case, and naturally reached for the pattern shown immediately below it, would write:\n\n```ts\nrun: async (payload) => {\n await stripe.refunds.create({ payment_intent: payload.piId, amount: payload.amount });\n await sendConfirmationEmail(payload); // throws for an unrelated reason\n}\n```\n\nThe email step failing retries the whole task (per the configured `maxAttempts`), and the refund call — having no idempotency key of its own — runs again on the retry. The task-level idempotency key never touches it, because nothing in this task calls `trigger()`.\n\n### Suggested fix\n\nTwo independent options, not mutually exclusive:\n\n1. Narrow the doc claim precisely: state that idempotency keys dedupe **task triggers**, not arbitrary code inside `run()`, and that the correct pattern for \"avoid double-charging\" is to always wrap the payment call in a child task triggered with a key — never call a payment API directly inside a retryable `run()`.\n2. Or close the actual gap: a general-purpose helper — something like `idempotencyKeys.run(key, fn)` — that persists the result of an arbitrary async operation keyed the same way `trigger()` already is, so a direct API call inside `run()` can opt into the same protection without being restructured into a child task.\n\nEither would stop the doc's own payments use case from silently not applying to the code shown right next to it.\n","author":{"url":"https://github.com/aurumflux20","@type":"Person","name":"aurumflux20"},"datePublished":"2026-08-15T00:25:13Z","url":"https://github.com/triggerdotdev/trigger.dev/issues/4627"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8f4c663d-eda5-4bf2-12af-29f0f5abfe0f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8674:141D8D:733304C:996A4B3:6AFADAC2 |
| html-safe-nonce | 2144ebfb2cd0be29e158580d8fa6d9037319493b88603622cbf2814e2979da7d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Njc0OjE0MUQ4RDo3MzMzMDRDOjk5NkE0QjM6NkFGQURBQzIiLCJ2aXNpdG9yX2lkIjoiNjk1NTM4NDIzOTgyMjY1ODI0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3c38b566bdf9efc87f27140f70d0df53ee9f272016073d455aa633f3bdffbd47 |
| hovercard-subject-tag | issue:5156687015 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/triggerdotdev/trigger.dev/4627/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3403f17b9a87dff4057e40c95abd8aa95472b29081af19735e3396ee32389bed/triggerdotdev/trigger.dev/issues/4627 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3403f17b9a87dff4057e40c95abd8aa95472b29081af19735e3396ee32389bed/triggerdotdev/trigger.dev/issues/4627 |
| og:image:alt | Hi — really like how deliberately this project has thought about retries (per-task config, exponential backoff, staging/prod on by default with dev opt-out documented plainly). This is about a gap ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aurumflux20 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9d9bd51a568909a83d1abb9d6f74d68f0c87ca85fe3a56d3f5d70d8b89add9f2 |
| turbo-cache-control | no-preview |
| go-import | github.com/triggerdotdev/trigger.dev git https://github.com/triggerdotdev/trigger.dev.git |
| octolytics-dimension-user_id | 95297378 |
| octolytics-dimension-user_login | triggerdotdev |
| octolytics-dimension-repository_id | 572570113 |
| octolytics-dimension-repository_nwo | triggerdotdev/trigger.dev |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 572570113 |
| octolytics-dimension-repository_network_root_nwo | triggerdotdev/trigger.dev |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4a7ae932999cc6d511008dbf980ff9efad2a31f7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width