@@ -87,6 +87,7 @@ export const runTask = async ({ run, task, publish, logger }: RunTaskOptions) =>
8787 let taskStartedAt = Date . now ( )
8888 let taskFinishedAt : number | undefined
8989 let taskAbortedAt : number | undefined
90+ let taskTimedOut : boolean = false
9091 let taskMetricsId : number | undefined
9192 let rooTaskId : string | undefined
9293 let isClientDisconnected = false
@@ -196,6 +197,7 @@ export const runTask = async ({ run, task, publish, logger }: RunTaskOptions) =>
196197 timeout : EVALS_TIMEOUT ,
197198 } )
198199 } catch ( _error ) {
200+ taskTimedOut = true
199201 logger . error ( "time limit reached" )
200202
201203 if ( rooTaskId && ! isClientDisconnected ) {
@@ -207,16 +209,16 @@ export const runTask = async ({ run, task, publish, logger }: RunTaskOptions) =>
207209 taskFinishedAt = Date . now ( )
208210 }
209211
210- if ( taskFinishedAt ) {
211- logger . info ( "setting task finished at" )
212- await updateTask ( task . id , { finishedAt : new Date ( ) } )
213- }
214-
215- if ( ! taskFinishedAt && isClientDisconnected ) {
212+ if ( ! taskFinishedAt && ! taskTimedOut ) {
216213 logger . error ( "client disconnected before task finished" )
217214 throw new Error ( "Client disconnected before task completion." )
218215 }
219216
217+ // If the task was aborted unexpectedly or the client disconnected
218+ // unexpectedly, then throw to trigger a retry.
219+ logger . info ( "setting task finished at" )
220+ await updateTask ( task . id , { finishedAt : new Date ( ) } )
221+
220222 if ( rooTaskId && ! isClientDisconnected ) {
221223 logger . info ( "closing task" )
222224 client . sendCommand ( { commandName : TaskCommandName . CloseTask , data : rooTaskId } )
0 commit comments