Repository navigation
Commit a39efeb
committed
fix(batchTrigger): clear idempotency key when previous run failed (closes #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.
Root cause (as @Jaimin2687 identified on the issue):
* `PostgresRunStore.findRunsByIdempotencyKeys` SELECTed 5 columns —
id, createdAt, friendlyId, idempotencyKey, idempotencyKeyExpiresAt.
* `status` was missing, and `IdempotencyKeyRunMatch` did not type it.
* `#prepareRunData` therefore had only time-based expiry to work with
and no way to see that the cached run was CRASHED / SYSTEM_FAILURE /
COMPLETED_WITH_ERRORS / INTERRUPTED / TIMED_OUT / EXPIRED.
Fix (three files, additive):
- internal-packages/run-store/src/types.ts
* `IdempotencyKeyRunMatch` gains a required `status: TaskRunStatus`.
* Comment explains the invariant for the next reader.
- internal-packages/run-store/src/PostgresRunStore.ts
* The hot-path UNION ALL SQL now also selects `"status"`. One token
added per branch, no new rows read, no index change needed —
(runtimeEnvironmentId, taskIdentifier, idempotencyKey) already
uniquely identifies the row.
- apps/webapp/app/v3/services/batchTriggerV3.server.ts
* `#prepareRunData` imports `shouldIdempotencyKeyBeCleared` and ORs
it with the existing time-based 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 is returned
with `isCached: false`.
* Behaviour on cached-but-still-good runs is unchanged.
* Behaviour on cached-and-time-expired runs is unchanged.
- 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.
Reporter: @Jaimin2687 (full RCA in the issue). No in-flight PR for #4819
at time of writing.1 parent 21f1dcc commit a39efeb
4 files changed
Lines changed: 95 additions & 4 deletions
File tree
- apps/webapp/app/v3/services
- internal-packages/run-store/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
| |||
450 | 454 | | |
451 | 455 | | |
452 | 456 | | |
453 | | - | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
454 | 475 | | |
455 | 476 | | |
456 | 477 | | |
| |||
Lines changed: 61 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
117 | 119 | | |
118 | 120 | | |
119 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
120 | 180 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1924 | 1924 | | |
1925 | 1925 | | |
1926 | 1926 | | |
1927 | | - | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
1928 | 1930 | | |
1929 | 1931 | | |
1930 | 1932 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
| |||
0 commit comments