@@ -64,9 +64,13 @@ export class FinalizeTaskRunService extends BaseService {
6464 completedAt,
6565 } ) ;
6666
67+ // I moved the error update here for two reasons:
68+ // - A single update is more efficient than two
69+ // - If the status updates to a final status, realtime will receive that status and then shut down the stream
70+ // before the error is updated, which would cause the error to be lost
6771 const run = await this . _prisma . taskRun . update ( {
6872 where : { id } ,
69- data : { status, expiredAt, completedAt } ,
73+ data : { status, expiredAt, completedAt, error : error ? sanitizeError ( error ) : undefined } ,
7074 ...( include ? { include } : { } ) ,
7175 } ) ;
7276
@@ -78,10 +82,6 @@ export class FinalizeTaskRunService extends BaseService {
7882 await this . finalizeAttempt ( { attemptStatus, error, run } ) ;
7983 }
8084
81- if ( error ) {
82- await this . finalizeRunError ( run , error ) ;
83- }
84-
8585 try {
8686 await this . #finalizeBatch( run ) ;
8787 } catch ( finalizeBatchError ) {
@@ -211,15 +211,6 @@ export class FinalizeTaskRunService extends BaseService {
211211 }
212212 }
213213
214- async finalizeRunError ( run : TaskRun , error : TaskRunError ) {
215- await this . _prisma . taskRun . update ( {
216- where : { id : run . id } ,
217- data : {
218- error : sanitizeError ( error ) ,
219- } ,
220- } ) ;
221- }
222-
223214 async finalizeAttempt ( {
224215 attemptStatus,
225216 error,
0 commit comments