From 8d59130b48951213f38fb60d8f7cc32f0a91270e Mon Sep 17 00:00:00 2001 From: isshaddad Date: Wed, 20 May 2026 08:16:51 -0400 Subject: [PATCH] fix(core): retry TASK_MIDDLEWARE_ERROR under the task's retry policy --- .changeset/retry-middleware-errors.md | 5 +++++ packages/core/src/v3/errors.ts | 1 + packages/core/test/errors.test.ts | 6 ++++++ 3 files changed, 12 insertions(+) create mode 100644 .changeset/retry-middleware-errors.md diff --git a/.changeset/retry-middleware-errors.md b/.changeset/retry-middleware-errors.md new file mode 100644 index 0000000000..2267b4d724 --- /dev/null +++ b/.changeset/retry-middleware-errors.md @@ -0,0 +1,5 @@ +--- +"@trigger.dev/core": patch +--- + +Retry `TASK_MIDDLEWARE_ERROR` under the task's retry policy instead of failing the run on the first attempt. The error was already classified as retryable by `shouldRetryError`, but `shouldLookupRetrySettings` did not include it, so the retry flow fell through to `fail_run`. Fixes #3231. diff --git a/packages/core/src/v3/errors.ts b/packages/core/src/v3/errors.ts index d32e32f91c..f7f2ad0dd9 100644 --- a/packages/core/src/v3/errors.ts +++ b/packages/core/src/v3/errors.ts @@ -427,6 +427,7 @@ export function shouldLookupRetrySettings(error: TaskRunError): boolean { case "TASK_PROCESS_SIGTERM": case "TASK_PROCESS_SIGSEGV": case "TASK_RUN_UNCAUGHT_EXCEPTION": + case "TASK_MIDDLEWARE_ERROR": return true; default: diff --git a/packages/core/test/errors.test.ts b/packages/core/test/errors.test.ts index 9a94366d84..4bcf89d7e9 100644 --- a/packages/core/test/errors.test.ts +++ b/packages/core/test/errors.test.ts @@ -263,6 +263,12 @@ describe("shouldRetryError + shouldLookupRetrySettings", () => { expect(shouldLookupRetrySettings(err)).toBe(true); }); + it("retries TASK_MIDDLEWARE_ERROR using the task's retry settings", () => { + const err = internal("TASK_MIDDLEWARE_ERROR"); + expect(shouldRetryError(err)).toBe(true); + expect(shouldLookupRetrySettings(err)).toBe(true); + }); + it("still does not retry SIGKILL timeout", () => { expect(shouldRetryError(internal("TASK_PROCESS_SIGKILL_TIMEOUT"))).toBe(false); });