@@ -93,7 +93,7 @@ func LaunchAndCheckSubTasksState(ctx context.Context, tCtx core.TaskExecutionCon
9393
9494 retryAttemptsArray , err := bitarray .NewCompactArray (count , maxValue )
9595 if err != nil {
96- logger .Errorf (context . Background () , "Failed to create attempts compact array with [count: %v, maxValue: %v]" , count , maxValue )
96+ logger .Errorf (ctx , "Failed to create attempts compact array with [count: %v, maxValue: %v]" , count , maxValue )
9797 return currentState , externalResources , nil
9898 }
9999
@@ -106,6 +106,26 @@ func LaunchAndCheckSubTasksState(ctx context.Context, tCtx core.TaskExecutionCon
106106 currentState .RetryAttempts = retryAttemptsArray
107107 }
108108
109+ // If the current State is newly minted then we must initialize SystemFailures to track how many
110+ // times the subtask failed due to system issues, this is necessary to correctly evaluate
111+ // interruptible subtasks.
112+ if len (currentState .SystemFailures .GetItems ()) == 0 {
113+ count := uint (currentState .GetExecutionArraySize ())
114+ maxValue := bitarray .Item (tCtx .TaskExecutionMetadata ().GetInterruptibleFailureThreshold ())
115+
116+ systemFailuresArray , err := bitarray .NewCompactArray (count , maxValue )
117+ if err != nil {
118+ logger .Errorf (ctx , "Failed to create system failures array with [count: %v, maxValue: %v]" , count , maxValue )
119+ return currentState , externalResources , err
120+ }
121+
122+ for i := 0 ; i < currentState .GetExecutionArraySize (); i ++ {
123+ systemFailuresArray .SetItem (i , 0 )
124+ }
125+
126+ currentState .SystemFailures = systemFailuresArray
127+ }
128+
109129 // initialize log plugin
110130 logPlugin , err := logs .InitializeLogPlugins (& config .LogConfig .Config )
111131 if err != nil {
@@ -146,7 +166,8 @@ func LaunchAndCheckSubTasksState(ctx context.Context, tCtx core.TaskExecutionCon
146166 }
147167
148168 originalIdx := arrayCore .CalculateOriginalIndex (childIdx , newState .GetIndexesToCache ())
149- stCtx , err := NewSubTaskExecutionContext (tCtx , taskTemplate , childIdx , originalIdx , retryAttempt )
169+ systemFailures := currentState .SystemFailures .GetItem (childIdx )
170+ stCtx , err := NewSubTaskExecutionContext (tCtx , taskTemplate , childIdx , originalIdx , retryAttempt , systemFailures )
150171 if err != nil {
151172 return currentState , externalResources , err
152173 }
@@ -188,6 +209,16 @@ func LaunchAndCheckSubTasksState(ctx context.Context, tCtx core.TaskExecutionCon
188209 return currentState , externalResources , perr
189210 }
190211
212+ if phaseInfo .Err () != nil {
213+ messageCollector .Collect (childIdx , phaseInfo .Err ().String ())
214+ }
215+
216+ if phaseInfo .Err () != nil && phaseInfo .Err ().GetKind () == idlCore .ExecutionError_SYSTEM {
217+ newState .SystemFailures .SetItem (childIdx , systemFailures + 1 )
218+ } else {
219+ newState .SystemFailures .SetItem (childIdx , systemFailures )
220+ }
221+
191222 // process subtask phase
192223 actualPhase := phaseInfo .Phase ()
193224 if actualPhase .IsSuccess () {
@@ -294,15 +325,19 @@ func TerminateSubTasks(ctx context.Context, tCtx core.TaskExecutionContext, kube
294325 messageCollector := errorcollector .NewErrorMessageCollector ()
295326 for childIdx , existingPhaseIdx := range currentState .GetArrayStatus ().Detailed .GetItems () {
296327 existingPhase := core .Phases [existingPhaseIdx ]
297- retryAttempt := currentState .RetryAttempts .GetItem (childIdx )
328+ retryAttempt := uint64 (0 )
329+ if childIdx < len (currentState .RetryAttempts .GetItems ()) {
330+ // we can use RetryAttempts if it has been initialized, otherwise stay with default 0
331+ retryAttempt = currentState .RetryAttempts .GetItem (childIdx )
332+ }
298333
299334 // return immediately if subtask has completed or not yet started
300335 if existingPhase .IsTerminal () || existingPhase == core .PhaseUndefined {
301336 continue
302337 }
303338
304339 originalIdx := arrayCore .CalculateOriginalIndex (childIdx , currentState .GetIndexesToCache ())
305- stCtx , err := NewSubTaskExecutionContext (tCtx , taskTemplate , childIdx , originalIdx , retryAttempt )
340+ stCtx , err := NewSubTaskExecutionContext (tCtx , taskTemplate , childIdx , originalIdx , retryAttempt , 0 )
306341 if err != nil {
307342 return err
308343 }
0 commit comments