@@ -76,6 +76,8 @@ export class RunExecution {
76
76
private isShuttingDown = false ;
77
77
private shutdownReason ?: string ;
78
78
79
+ private isCompletingRun = false ;
80
+
79
81
private supervisorSocket : SupervisorSocket ;
80
82
private notifier ?: RunNotifier ;
81
83
private metadataClient ?: MetadataClient ;
@@ -292,7 +294,13 @@ export class RunExecution {
292
294
case "FINISHED" : {
293
295
this . sendDebugLog ( "run is finished" , snapshotMetadata ) ;
294
296
295
- // This can sometimes be called before the handleCompletionResult, so we don't need to do anything here
297
+ // We are finishing the run in handleCompletionResult, so we don't need to do anything here
298
+ if ( this . isCompletingRun ) {
299
+ this . sendDebugLog ( "run is finished but we're completing it, skipping" , snapshotMetadata ) ;
300
+ return ;
301
+ }
302
+
303
+ await this . exitTaskRunProcessWithoutFailingRun ( { flush : true , reason : "re-queued" } ) ;
296
304
return ;
297
305
}
298
306
case "QUEUED_EXECUTING" :
@@ -377,6 +385,9 @@ export class RunExecution {
377
385
throw new Error ( "Cannot start attempt: missing run or snapshot manager" ) ;
378
386
}
379
387
388
+ // Reset this for the new attempt
389
+ this . isCompletingRun = false ;
390
+
380
391
this . sendDebugLog ( "starting attempt" , { isWarmStart : String ( isWarmStart ) } ) ;
381
392
382
393
const attemptStartedAt = Date . now ( ) ;
@@ -655,6 +666,8 @@ export class RunExecution {
655
666
throw new Error ( "cannot complete run: missing run or snapshot manager" ) ;
656
667
}
657
668
669
+ this . isCompletingRun = true ;
670
+
658
671
const completionResult = await this . httpClient . completeRunAttempt (
659
672
this . runFriendlyId ,
660
673
this . snapshotManager . snapshotId ,
0 commit comments