@@ -120,10 +120,18 @@ export class RunExecution {
120120 }
121121
122122 if ( exitExecution ) {
123- this . shutdown ( "kill" ) ;
123+ this . shutdownExecution ( "kill" ) ;
124124 }
125125 }
126126
127+ public async shutdown ( ) {
128+ if ( this . taskRunProcess ) {
129+ await this . taskRunProcessProvider . handleProcessAbort ( this . taskRunProcess ) ;
130+ }
131+
132+ this . shutdownExecution ( "shutdown" ) ;
133+ }
134+
127135 /**
128136 * Prepares the execution with task run environment variables.
129137 * This should be called before executing, typically after a successful run to prepare for the next one.
@@ -232,7 +240,6 @@ export class RunExecution {
232240 if ( this . currentAttemptNumber && this . currentAttemptNumber !== run . attemptNumber ) {
233241 this . sendDebugLog ( "error: attempt number mismatch" , snapshotMetadata ) ;
234242 // This is a rogue execution, a new one will already have been created elsewhere
235- // TODO: keep this one, kill the process even if it's a keep-alive one
236243 await this . exitTaskRunProcessWithoutFailingRun ( {
237244 flush : false ,
238245 reason : "attempt number mismatch" ,
@@ -250,7 +257,6 @@ export class RunExecution {
250257 if ( deprecated ) {
251258 this . sendDebugLog ( "run execution is deprecated" , { incomingSnapshot : snapshot } ) ;
252259
253- // TODO: keep this one, kill the process even if it's a keep-alive one
254260 await this . exitTaskRunProcessWithoutFailingRun ( {
255261 flush : false ,
256262 reason : "deprecated execution" ,
@@ -469,7 +475,7 @@ export class RunExecution {
469475 if ( startError ) {
470476 this . sendDebugLog ( "failed to start attempt" , { error : startError . message } ) ;
471477
472- this . shutdown ( "failed to start attempt" ) ;
478+ this . shutdownExecution ( "failed to start attempt" ) ;
473479 return ;
474480 }
475481
@@ -480,12 +486,12 @@ export class RunExecution {
480486 if ( executeError ) {
481487 this . sendDebugLog ( "failed to execute run" , { error : executeError . message } ) ;
482488
483- this . shutdown ( "failed to execute run" ) ;
489+ this . shutdownExecution ( "failed to execute run" ) ;
484490 return ;
485491 }
486492
487493 // This is here for safety, but it
488- this . shutdown ( "execute call finished" ) ;
494+ this . shutdownExecution ( "execute call finished" ) ;
489495 }
490496
491497 private async executeRunWrapper ( {
@@ -786,7 +792,7 @@ export class RunExecution {
786792 if ( startError ) {
787793 this . sendDebugLog ( "failed to start attempt for retry" , { error : startError . message } ) ;
788794
789- this . shutdown ( "retryImmediately: failed to start attempt" ) ;
795+ this . shutdownExecution ( "retryImmediately: failed to start attempt" ) ;
790796 return ;
791797 }
792798
@@ -797,7 +803,7 @@ export class RunExecution {
797803 if ( executeError ) {
798804 this . sendDebugLog ( "failed to execute run for retry" , { error : executeError . message } ) ;
799805
800- this . shutdown ( "retryImmediately: failed to execute run" ) ;
806+ this . shutdownExecution ( "retryImmediately: failed to execute run" ) ;
801807 return ;
802808 }
803809 }
@@ -841,7 +847,7 @@ export class RunExecution {
841847 await this . taskRunProcessProvider . suspendProcess ( flush , this . taskRunProcess ) ;
842848
843849 // No services should be left running after this line - let's make sure of it
844- this . shutdown ( `exitTaskRunProcessWithoutFailingRun: ${ reason } ` ) ;
850+ this . shutdownExecution ( `exitTaskRunProcessWithoutFailingRun: ${ reason } ` ) ;
845851 }
846852
847853 /**
@@ -1012,10 +1018,10 @@ export class RunExecution {
10121018 }
10131019
10141020 this . executionAbortController . abort ( ) ;
1015- this . shutdown ( "abortExecution" ) ;
1021+ this . shutdownExecution ( "abortExecution" ) ;
10161022 }
10171023
1018- private shutdown ( reason : string ) {
1024+ private shutdownExecution ( reason : string ) {
10191025 if ( this . isShuttingDown ) {
10201026 this . sendDebugLog ( `[shutdown] ${ reason } (already shutting down)` , {
10211027 firstShutdownReason : this . shutdownReason ,
0 commit comments