-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: batch trigger returns stale failed runs when idempotency key points to a dead run #4818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Jaimin2687
wants to merge
1
commit into
triggerdotdev:main
from
Jaimin2687:fix/batch-trigger-idempotency-key-status-check
+177
−4
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
apps/webapp/test/batchTriggerIdempotencyStatusCheck.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import type { TaskRunStatus } from "@trigger.dev/database"; | ||
| import { shouldIdempotencyKeyBeCleared } from "~/v3/taskStatus"; | ||
|
|
||
| /** | ||
| * Tests the shouldIdempotencyKeyBeCleared function which is now used by both the | ||
| * single-trigger path (IdempotencyKeyConcern.handleExistingRun) and the batch-trigger | ||
| * path (BatchTriggerV3Service.#prepareRunData). | ||
| * | ||
| * Before the fix, the batch path did not call this function at all — it only | ||
| * checked time-based expiration, silently returning dead runs as cached hits. | ||
| * | ||
| * These tests validate: | ||
| * 1. All failure statuses that should trigger re-triggering | ||
| * 2. All non-failure statuses that should preserve the cached run | ||
| * 3. Edge cases around status classification | ||
| */ | ||
| describe("shouldIdempotencyKeyBeCleared — batch trigger parity", () => { | ||
| // ─── Statuses that MUST clear the idempotency key ────────────────── | ||
| // These are the statuses where the single-trigger path (and now the | ||
| // batch-trigger path) clears the key and creates a fresh run. | ||
|
|
||
| const clearableStatuses: TaskRunStatus[] = [ | ||
| "CRASHED", | ||
| "SYSTEM_FAILURE", | ||
| "TIMED_OUT", | ||
| "EXPIRED", | ||
| "COMPLETED_WITH_ERRORS", | ||
| "INTERRUPTED", | ||
| ]; | ||
|
|
||
| it.each(clearableStatuses)( | ||
| "returns true for %s — dead runs must not be returned as cached hits in batch triggers", | ||
| (status) => { | ||
| expect(shouldIdempotencyKeyBeCleared(status)).toBe(true); | ||
| } | ||
| ); | ||
|
|
||
| // ─── Statuses that MUST NOT clear the idempotency key ────────────── | ||
| // These runs are either still in progress, successfully completed, | ||
| // or canceled by the user. Returning them as cached is correct. | ||
|
|
||
| const nonClearableStatuses: TaskRunStatus[] = [ | ||
| "PENDING", | ||
| "PENDING_VERSION", | ||
| "WAITING_FOR_DEPLOY", | ||
| "DEQUEUED", | ||
| "EXECUTING", | ||
| "WAITING_TO_RESUME", | ||
| "RETRYING_AFTER_FAILURE", | ||
| "PAUSED", | ||
| "DELAYED", | ||
| "COMPLETED_SUCCESSFULLY", | ||
| "CANCELED", | ||
| ]; | ||
|
|
||
| it.each(nonClearableStatuses)( | ||
| "returns false for %s — these runs should be returned as cached hits", | ||
| (status) => { | ||
| expect(shouldIdempotencyKeyBeCleared(status)).toBe(false); | ||
| } | ||
| ); | ||
|
|
||
| // ─── Specific edge cases ─────────────────────────────────────────── | ||
|
|
||
| it("COMPLETED_SUCCESSFULLY should NOT be cleared — it is a valid cached result", () => { | ||
| expect(shouldIdempotencyKeyBeCleared("COMPLETED_SUCCESSFULLY")).toBe(false); | ||
| }); | ||
|
|
||
| it("CANCELED should NOT be cleared — user-initiated cancellation is intentional", () => { | ||
| expect(shouldIdempotencyKeyBeCleared("CANCELED")).toBe(false); | ||
| }); | ||
|
|
||
| it("EXPIRED should be cleared — expired runs should be re-triggerable via batch", () => { | ||
| expect(shouldIdempotencyKeyBeCleared("EXPIRED")).toBe(true); | ||
| }); | ||
|
|
||
| it("RETRYING_AFTER_FAILURE should NOT be cleared — the run is still in progress", () => { | ||
| expect(shouldIdempotencyKeyBeCleared("RETRYING_AFTER_FAILURE")).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Missing server release note for user-facing fix
This user-facing behavior change to batch triggers ships only server code under
apps/webappandinternal-packages, with no.server-changes/note added. The repository guidelines require a.server-changes/entry for user-facing server-only changes, so this fix will be absent from release notes.Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.