Title: fix: batch trigger returns stale failed runs when idempotency key points to a dead run by Jaimin2687 · Pull Request #4818 · triggerdotdev/trigger.dev · GitHub
Open Graph Title: fix: batch trigger returns stale failed runs when idempotency key points to a dead run by Jaimin2687 · Pull Request #4818 · triggerdotdev/trigger.dev
X Title: fix: batch trigger returns stale failed runs when idempotency key points to a dead run by Jaimin2687 · Pull Request #4818 · triggerdotdev/trigger.dev
Description: What happened I noticed that 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 (CRASHED, SYSTEM_FAILURE, TIMED_OUT, EXPIRED, COMPLETED_WITH_ERRORS, INTERRUPTED), the SDK 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. With batchTrigger, that check was missing entirely. The batch path in BatchTriggerV3Service.#prepareRunData only checked time-based expiration (idempotencyKeyExpiresAt < now), so a failed run would get returned as isCached: true — silently handing back a dead run that will never produce output. The root cause turned out to be pretty simple: the SQL query backing findRunsByIdempotencyKeys never selected the status column, and the IdempotencyKeyRunMatch type didn't include it. So even if someone wanted to add the check, the data wasn't there. What this PR does Three small changes: Added status to the query and its return type — IdempotencyKeyRunMatch in run-store/src/types.ts now includes status: string, and the raw SQL in PostgresRunStore.findRunsByIdempotencyKeys selects it. Added the missing status check in the batch path — After the existing expiry check in #prepareRunData, there's now a shouldIdempotencyKeyBeCleared(cachedRun.status) guard that mirrors what the single-trigger path already does. If the cached run is in a failure state, we add it to expiredRunIds (so the key gets cleared) and mint a new run ID. Added the import — shouldIdempotencyKeyBeCleared was already exported from taskStatus.ts, just not imported in the batch service. ✅ Checklist I have followed every step in the contributing guide The PR title follows the convention I ran and tested the code works Testing Unit tests — Added 21 tests in batchTriggerIdempotencyStatusCheck.test.ts that cover every TaskRunStatus value against shouldIdempotencyKeyBeCleared: All 6 failure statuses correctly return true (key should be cleared, run re-triggered) All 11 non-failure statuses correctly return false (run stays cached) Explicit edge cases for COMPLETED_SUCCESSFULLY (valid cache), CANCELED (user-intentional), RETRYING_AFTER_FAILURE (still in progress), and EXPIRED Integration tests — Extended the existing PostgresRunStore.findRunsByIdempotencyKeys.test.ts with testcontainers: Added status assertions to the existing test (catches future regressions if someone removes the column) New test: creates runs in all 6 failure statuses and verifies the query returns the correct status for each New test: verifies COMPLETED_SUCCESSFULLY status is returned correctly Build verification: pnpm run typecheck --filter webapp ✅ pnpm run build --filter @internal/run-store ✅ pnpm run format ✅ pnpm run lint:fix ✅ (0 warnings, 0 errors) How to reproduce the bug manually: // 1. A task that always fails export const failingTask = task({ id: "failing-task", run: async () => { throw new Error("boom"); }, }); // 2. Batch trigger with idempotency key await tasks.batchTrigger("failing-task", [ { payload: {}, options: { idempotencyKey: "key-1" } }, ]); // Wait for the run to fail... // 3. Trigger again — before this fix, you get the dead run back await tasks.batchTrigger("failing-task", [ { payload: {}, options: { idempotencyKey: "key-1" } }, ]); // BEFORE: isCached: true (dead run returned) // AFTER: isCached: false (fresh run created) Changelog Batch triggers with idempotency keys now correctly re-trigger when a previous run failed, matching the existing single-trigger behavior. Previously, calling batchTrigger with an idempotency key that pointed to a crashed or failed run would silently return the dead run instead of starting a new one. Screenshots N/A — backend-only change, no UI impact. 💯
Open Graph Description: What happened I noticed that 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 ide...
X Description: What happened I noticed that 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 ide...
Opengraph URL: https://github.com/triggerdotdev/trigger.dev/pull/4818
X: @github
Domain: github.com
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:e120793c-24bd-4a86-f1d5-105f37367852 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A2AC:79AE7:44E7913:5C832E0:6AFADCDE |
| html-safe-nonce | d4ba584be3e002e1ced914d90b9971b4edcfd31ada4bc321a29ef8c4bb951a67 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMkFDOjc5QUU3OjQ0RTc5MTM6NUM4MzJFMDo2QUZBRENERSIsInZpc2l0b3JfaWQiOiI1OTg0Njk4MDgxNjIwOTc0ODE0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 347891fe3dc32e025190b6c22357ae2b80f9fe7c702f7fb4c4359f607f8c320f |
| hovercard-subject-tag | pull_request:4385231068 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/triggerdotdev/trigger.dev/pull/4818/files |
| twitter:image | https://avatars.githubusercontent.com/u/132206640?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/132206640?s=400&v=4 |
| og:image:alt | What happened I noticed that 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 ide... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9d9bd51a568909a83d1abb9d6f74d68f0c87ca85fe3a56d3f5d70d8b89add9f2 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| 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 |
Links:
Viewport: width=device-width