Title: fix(batchTrigger): clear idempotency key when previous run failed (closes #4819) by 61465 · Pull Request #5014 · triggerdotdev/trigger.dev · GitHub
Open Graph Title: fix(batchTrigger): clear idempotency key when previous run failed (closes #4819) by 61465 · Pull Request #5014 · triggerdotdev/trigger.dev
X Title: fix(batchTrigger): clear idempotency key when previous run failed (closes #4819) by 61465 · Pull Request #5014 · triggerdotdev/trigger.dev
Description: What Fixes #4819 — batchTrigger silently returned stale failed runs as isCached: true, so a caller re-batching with the same idempotency key never got a retry. The single-trigger path has done the right thing since day one via IdempotencyKeyConcern.handleExistingRun → shouldIdempotencyKeyBeCleared (apps/webapp/app/runEngine/concerns/idempotencyKeys.server.ts:463). The batch path at batchTriggerV3.server.ts:450 just ignored the status. Repro from the issue (confirmed): const failingTask = task({ id: 'failing-task', run: async () => { throw new Error('boom') }, }) // First batchTrigger — run fails and ends up CRASHED await tasks.batchTrigger('failing-task', [ { payload: {}, options: { idempotencyKey: 'key-1' } }, ]) // …wait for CRASHED… // Second batchTrigger with the same key const res = await tasks.batchTrigger('failing-task', [ { payload: {}, options: { idempotencyKey: 'key-1' } }, ]) // Expected: isCached: false (fresh run) // Actual: isCached: true (dead CRASHED run handed back) Root cause Credit to @Jaimin2687 for the full RCA on the issue. Confirmed line-by-line: PostgresRunStore.findRunsByIdempotencyKeys SELECTs 5 columns — id, createdAt, friendlyId, idempotencyKey, idempotencyKeyExpiresAt. status was missing from both the SQL and the IdempotencyKeyRunMatch type. #prepareRunData therefore had only time-based expiry to work with and no way to see that the cached run was CRASHED / COMPLETED_WITH_ERRORS / SYSTEM_FAILURE / INTERRUPTED / TIMED_OUT_WITH_ERRORS / EXPIRED. Fix (additive, 4 files) internal-packages/run-store/src/types.ts Adds status: TaskRunStatus to IdempotencyKeyRunMatch, with a comment explaining why the field is now required. internal-packages/run-store/src/PostgresRunStore.ts Hot-path UNION ALL SQL now also selects \"status\". One token added per branch, no new rows read, no index change — the existing (runtimeEnvironmentId, taskIdentifier, idempotencyKey) filter already pinpoints each row. apps/webapp/app/v3/services/batchTriggerV3.server.ts #prepareRunData imports shouldIdempotencyKeyBeCleared and ORs it with the existing time-expiry check. A cached run whose status is in the 'clear me' set is now treated exactly like an expired cache entry: the friendlyId is added to expiredRunIds for cleanup, a fresh child id is minted, and the result returns with isCached: false. Behaviour on cached-but-still-good runs is unchanged. Behaviour on cached-and-time-expired runs is unchanged. Only the previously-silent "cached but dead" case flips. internal-packages/run-store/src/PostgresRunStore.findRunsByIdempotencyKeys.test.ts createRun helper gains an optional status param. New postgresTest(\"returns run status so callers can honour shouldIdempotencyKeyBeCleared\") creates four seed rows (PENDING, CRASHED, COMPLETED_WITH_ERRORS, COMPLETED_SUCCESSFULLY) and asserts the store surfaces each status in the result. This locks the contract for batchTrigger to depend on. Why this design Minimal diff: one extra column in a SQL, one extra OR in the batch path, one type field, one test. No refactor of the batch flow, no new code path to maintain. Mirrors the single-trigger contract: anyone reading shouldIdempotencyKeyBeCleared as the source of truth already expects both call sites to behave the same way. This PR makes them so. Fail-closed: on an unexpected status value the OR evaluates to false and we fall through to the existing "return cached" path — identical behaviour to today. No API shape change: BatchTriggerTaskV2Response already carries isCached per item. Callers that previously got isCached: true for a dead run will now get isCached: false and a fresh friendlyId, which is what they already handle for the time-expired case. Testing Added postgres-backed vitest proves the SQL now returns status. Existing tests still pass (no behavioural change for cached-good runs). Impact Any user of batchTrigger + idempotency keys on failing tasks: silently broken today, silently fixed by this PR. The failure mode is nasty because the caller sees isCached: true and reasonably assumes the run will produce output — then waits forever on a dead run. Shipping-visible to all self-hosted and cloud users of SDK 4.5.11+. Related Reporter: @Jaimin2687 — full RCA + line references on the issue. Prior work this builds on: shouldIdempotencyKeyBeCleared was introduced in the single-trigger path to codify the retry-on-failure contract. This PR extends the same contract to the batch path.
Open Graph Description: What Fixes #4819 — batchTrigger silently returned stale failed runs as isCached: true, so a caller re-batching with the same idempotency key never got a retry. The single-trigger path has done the ...
X Description: What Fixes #4819 — batchTrigger silently returned stale failed runs as isCached: true, so a caller re-batching with the same idempotency key never got a retry. The single-trigger path has done the ...
Opengraph URL: https://github.com/triggerdotdev/trigger.dev/pull/5014
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:c3f6707c-bc82-a23d-e529-060089d587fd |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C0E6:249B37:43B1A6F:5B50D39:6AFADAC9 |
| html-safe-nonce | 766b047e7a16aeb0d4c1592cd1b9a5dc8242c87f3caf5605412435030547309e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMEU2OjI0OUIzNzo0M0IxQTZGOjVCNTBEMzk6NkFGQURBQzkiLCJ2aXNpdG9yX2lkIjoiNTM3ODY0OTYyMTczNzk1Mzk5MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ea5e7b89709b93e55047a3fdb1b420e069d115b07ca457f51eedd4da6f392dd2 |
| hovercard-subject-tag | pull_request:4813181921 |
| 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/5014/files |
| twitter:image | https://avatars.githubusercontent.com/u/62155637?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/62155637?s=400&v=4 |
| og:image:alt | What Fixes #4819 — batchTrigger silently returned stale failed runs as isCached: true, so a caller re-batching with the same idempotency key never got a retry. The single-trigger path has done the ... |
| 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