33 isOOMRunError ,
44 RetryOptions ,
55 sanitizeError ,
6+ shouldLookupRetrySettings ,
67 shouldRetryError ,
78 TaskRunError ,
89 taskRunErrorEnhancer ,
@@ -72,13 +73,11 @@ export async function retryOutcomeFromCompletion(
7273 } ;
7374 }
7475
75- // No retry settings
76- if ( ! retrySettings ) {
77- return { outcome : "fail_run" , sanitizedError } ;
78- }
76+ const enhancedError = taskRunErrorEnhancer ( error ) ;
7977
8078 // Not a retriable error: fail
81- const retriableError = shouldRetryError ( taskRunErrorEnhancer ( error ) ) ;
79+ const retriableError = shouldRetryError ( enhancedError ) ;
80+
8281 if ( ! retriableError ) {
8382 return { outcome : "fail_run" , sanitizedError } ;
8483 }
@@ -95,6 +94,7 @@ export async function retryOutcomeFromCompletion(
9594 } ,
9695 select : {
9796 maxAttempts : true ,
97+ lockedRetryConfig : true ,
9898 } ,
9999 } ) ;
100100
@@ -112,6 +112,48 @@ export async function retryOutcomeFromCompletion(
112112 return { outcome : "fail_run" , sanitizedError } ;
113113 }
114114
115+ // No retry settings
116+ if ( ! retrySettings ) {
117+ const shouldLookup = shouldLookupRetrySettings ( enhancedError ) ;
118+
119+ if ( ! shouldLookup ) {
120+ return { outcome : "fail_run" , sanitizedError } ;
121+ }
122+
123+ const retryConfig = run . lockedRetryConfig ;
124+
125+ if ( ! retryConfig ) {
126+ return { outcome : "fail_run" , sanitizedError } ;
127+ }
128+
129+ const parsedRetryConfig = RetryOptions . nullish ( ) . safeParse ( retryConfig ) ;
130+
131+ if ( ! parsedRetryConfig . success ) {
132+ return { outcome : "fail_run" , sanitizedError } ;
133+ }
134+
135+ if ( ! parsedRetryConfig . data ) {
136+ return { outcome : "fail_run" , sanitizedError } ;
137+ }
138+
139+ const nextDelay = calculateNextRetryDelay ( parsedRetryConfig . data , attemptNumber ?? 1 ) ;
140+
141+ if ( ! nextDelay ) {
142+ return { outcome : "fail_run" , sanitizedError } ;
143+ }
144+
145+ const retrySettings = {
146+ timestamp : Date . now ( ) + nextDelay ,
147+ delay : nextDelay ,
148+ } ;
149+
150+ return {
151+ outcome : "retry" ,
152+ method : "queue" , // we'll always retry on the queue because usually having no settings means something bad happened
153+ settings : retrySettings ,
154+ } ;
155+ }
156+
115157 return {
116158 outcome : "retry" ,
117159 method : retryUsingQueue ? "queue" : "immediate" ,
@@ -130,19 +172,15 @@ async function retryOOMOnMachine(
130172 } ,
131173 select : {
132174 machinePreset : true ,
133- lockedBy : {
134- select : {
135- retryConfig : true ,
136- } ,
137- } ,
175+ lockedRetryConfig : true ,
138176 } ,
139177 } ) ;
140178
141- if ( ! run || ! run . lockedBy || ! run . machinePreset ) {
179+ if ( ! run || ! run . lockedRetryConfig || ! run . machinePreset ) {
142180 return ;
143181 }
144182
145- const retryConfig = run . lockedBy ?. retryConfig ;
183+ const retryConfig = run . lockedRetryConfig ;
146184 const parsedRetryConfig = RetryOptions . nullish ( ) . safeParse ( retryConfig ) ;
147185
148186 if ( ! parsedRetryConfig . success ) {
0 commit comments