Title: bug: batchTrigger returns stale failed runs instead of re-triggering when idempotency key points to a dead run · Issue #4819 · triggerdotdev/trigger.dev · GitHub
Open Graph Title: bug: batchTrigger returns stale failed runs instead of re-triggering when idempotency key points to a dead run · Issue #4819 · triggerdotdev/trigger.dev
X Title: bug: batchTrigger returns stale failed runs instead of re-triggering when idempotency key points to a dead run · Issue #4819 · triggerdotdev/trigger.dev
Description: Bug Description batchTrigger and single trigger behave differently when an idempotency key points to a run that already failed. With single trigger, if a previous run with the same idempotency key ended up in a terminal failure state (CR...
Open Graph Description: Bug Description batchTrigger and single trigger behave differently when an idempotency key points to a run that already failed. With single trigger, if a previous run with the same idempotency key ...
X Description: Bug Description batchTrigger and single trigger behave differently when an idempotency key points to a run that already failed. With single trigger, if a previous run with the same idempotency key ...
Opengraph URL: https://github.com/triggerdotdev/trigger.dev/issues/4819
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bug: batchTrigger returns stale failed runs instead of re-triggering when idempotency key points to a dead run","articleBody":"## Bug Description\n\n`batchTrigger` and single `trigger` behave differently when an idempotency key points to a run that already failed.\n\nWith single `trigger`, if a previous run with the same idempotency key ended up in a terminal failure state (`CRASHED`, `SYSTEM_FAILURE`, `TIMED_OUT`, `EXPIRED`, `COMPLETED_WITH_ERRORS`, `INTERRUPTED`), it correctly clears the key and creates a fresh run. This works because `IdempotencyKeyConcern.handleExistingRun` calls `shouldIdempotencyKeyBeCleared(status)` before deciding whether to return a cached result.\n\nWith `batchTrigger`, that same check is missing. The batch path in `BatchTriggerV3Service.#prepareRunData` only checks time-based expiration (`idempotencyKeyExpiresAt \u003c now`), so a failed run gets returned as `isCached: true` — silently handing back a dead run that will never produce output.\n\n## Steps to Reproduce\n\n```typescript\n// 1. A task that always fails\nexport const failingTask = task({\n id: \"failing-task\",\n run: async () => { throw new Error(\"boom\"); },\n});\n\n// 2. Batch trigger with idempotency key\nawait tasks.batchTrigger(\"failing-task\", [\n { payload: {}, options: { idempotencyKey: \"key-1\" } },\n]);\n// Wait for the run to reach CRASHED / COMPLETED_WITH_ERRORS...\n\n// 3. Trigger again with the same key\nawait tasks.batchTrigger(\"failing-task\", [\n { payload: {}, options: { idempotencyKey: \"key-1\" } },\n]);\n// Expected: isCached: false (fresh run created)\n// Actual: isCached: true (dead run returned)\n```\n\nCompare with single trigger — this already works correctly:\n```typescript\nawait tasks.trigger(\"failing-task\", {}, { idempotencyKey: \"key-2\" });\n// Wait for failure...\nawait tasks.trigger(\"failing-task\", {}, { idempotencyKey: \"key-2\" });\n// Correctly returns isCached: false and creates a new run\n```\n\n## Root Cause\n\nThe SQL query in `PostgresRunStore.findRunsByIdempotencyKeys` never selects the `status` column, and the `IdempotencyKeyRunMatch` type doesn't include it. So `#prepareRunData` has no way to check whether a matched run is in a clearable failure state — it can only check time-based expiration.\n\nThe single-trigger path works because `IdempotencyKeyConcern.handleExistingRun` fetches the full run record and calls `shouldIdempotencyKeyBeCleared(status)` at [idempotencyKeys.server.ts:463](https://github.com/triggerdotdev/trigger.dev/blob/main/apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts#L463). The batch path at [batchTriggerV3.server.ts:452-469](https://github.com/triggerdotdev/trigger.dev/blob/main/apps/webapp/app/v3/services/batchTriggerV3.server.ts#L452-L469) skips this entirely.\n\n| Check | Single trigger | Batch trigger |\n|---|---|---|\n| Time-based expiry | ✅ `idempotencyKeyExpiresAt \u003c now` | ✅ `idempotencyKeyExpiresAt \u003c now` |\n| Failure status check | ✅ `shouldIdempotencyKeyBeCleared(status)` | ❌ **Missing** |\n\n## Affected Statuses\n\nThese statuses should clear the idempotency key and re-trigger (works for single trigger, broken for batch):\n- `CRASHED`\n- `SYSTEM_FAILURE`\n- `TIMED_OUT`\n- `EXPIRED`\n- `COMPLETED_WITH_ERRORS`\n- `INTERRUPTED`\n\n## Suggested Fix\n\nI already wrote and tested a patch for this. My PR #4818 was auto-closed since I'm not a vouched contributor, but the fix is ready on my fork if you'd like to pull it in or use it as reference:\n\n**Branch:** [`Jaimin2687:fix/batch-trigger-idempotency-key-status-check`](https://github.com/Jaimin2687/trigger.dev/tree/fix/batch-trigger-idempotency-key-status-check)\n\nThe fix is three small changes:\n\n1. **`internal-packages/run-store/src/types.ts`** — Add `status: string` to `IdempotencyKeyRunMatch`\n2. **`internal-packages/run-store/src/PostgresRunStore.ts`** — Add `\"status\"` to the raw SQL SELECT in `findRunsByIdempotencyKeys`\n3. **`apps/webapp/app/v3/services/batchTriggerV3.server.ts`** — Import `shouldIdempotencyKeyBeCleared` and add the guard after the expiry check in `#prepareRunData`, mirroring the single-trigger path\n\nThe branch also includes 21 unit tests and 2 integration tests (testcontainers) covering all `TaskRunStatus` values. Everything passes typecheck, build, format, and lint.\n\n## Environment\n\n- trigger.dev `main` branch (as of Aug 28, 2025)\n- Affects all environments (dev, staging, production)\n- Backend only, no UI impact","author":{"url":"https://github.com/Jaimin2687","@type":"Person","name":"Jaimin2687"},"datePublished":"2026-08-28T13:53:16Z","url":"https://github.com/triggerdotdev/trigger.dev/issues/4819"}
| 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:492bbd68-b6db-6298-d7f7-5cf17bf2789f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A256:D23AD:304ED3E:4172007:6AFAD85A |
| html-safe-nonce | f336fef3c4ed0e7f646f4cab23a83efcf05a74a1a7e5da63c57837eaf7a0fe16 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjU2OkQyM0FEOjMwNEVEM0U6NDE3MjAwNzo2QUZBRDg1QSIsInZpc2l0b3JfaWQiOiIzMjE2NzcwMTY2Nzc5NzMwMDEwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3bef014dd3c444819f79099c58ff3f55794c584485b312f7d6ee071cf7b85adb |
| hovercard-subject-tag | issue:5278895159 |
| 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/4819/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cb4db5a021a503312d59c3551ff5666ca3857e5f2b0e099bda32769f297de76f/triggerdotdev/trigger.dev/issues/4819 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cb4db5a021a503312d59c3551ff5666ca3857e5f2b0e099bda32769f297de76f/triggerdotdev/trigger.dev/issues/4819 |
| og:image:alt | Bug Description batchTrigger and single trigger behave differently when an idempotency key points to a run that already failed. With single trigger, if a previous run with the same idempotency key ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Jaimin2687 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 02f4c00e74911c7cd779fc232c3130cee49eb39fd0ed4bfe3eea3b82c7c18084 |
| 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 | 33c41e9d150e44415272934d676dc63c57d89c3b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width