@@ -299,14 +299,17 @@ export class TaskRunner {
299299 */
300300 private executeOneTask = async ( task : Task ) : Promise < Task | undefined > => {
301301 const { workerID } = this . options ;
302+ // Safe: caller (executeTask) already validated these via isValidTask()
303+ const taskId = task . taskId as string ;
304+ const workflowInstanceId = task . workflowInstanceId as string ;
302305 const startTime = Date . now ( ) ;
303306
304307 // Publish TaskExecutionStarted event
305308 await this . eventDispatcher . publishTaskExecutionStarted ( {
306309 taskType : this . worker . taskDefName ,
307- taskId : task . taskId ! ,
310+ taskId,
308311 workerId : workerID ,
309- workflowInstanceId : task . workflowInstanceId ,
312+ workflowInstanceId,
310313 timestamp : new Date ( ) ,
311314 } ) ;
312315
@@ -326,8 +329,8 @@ export class TaskRunner {
326329 if ( isTaskInProgress ( result ) ) {
327330 const contextLogs = context . getLogs ( ) ;
328331 const nextTask = await this . updateTaskWithRetry ( task , {
329- workflowInstanceId : task . workflowInstanceId ,
330- taskId : task . taskId ,
332+ workflowInstanceId,
333+ taskId,
331334 status : "IN_PROGRESS" ,
332335 callbackAfterSeconds : result . callbackAfterSeconds ,
333336 outputData :
@@ -338,15 +341,15 @@ export class TaskRunner {
338341 // Publish completion event for IN_PROGRESS
339342 await this . eventDispatcher . publishTaskExecutionCompleted ( {
340343 taskType : this . worker . taskDefName ,
341- taskId : task . taskId ! ,
344+ taskId,
342345 workerId : workerID ,
343- workflowInstanceId : task . workflowInstanceId ,
346+ workflowInstanceId,
344347 durationMs,
345348 timestamp : new Date ( ) ,
346349 } ) ;
347350
348351 this . logger . debug (
349- `Task ${ task . taskId } returned IN_PROGRESS, callback after ${ result . callbackAfterSeconds } s`
352+ `Task ${ taskId } returned IN_PROGRESS, callback after ${ result . callbackAfterSeconds } s`
350353 ) ;
351354 return nextTask ;
352355 }
@@ -383,20 +386,20 @@ export class TaskRunner {
383386 // Publish TaskExecutionCompleted event
384387 await this . eventDispatcher . publishTaskExecutionCompleted ( {
385388 taskType : this . worker . taskDefName ,
386- taskId : task . taskId ! ,
389+ taskId,
387390 workerId : workerID ,
388- workflowInstanceId : task . workflowInstanceId ,
391+ workflowInstanceId,
389392 durationMs,
390393 outputSizeBytes,
391394 timestamp : new Date ( ) ,
392395 } ) ;
393396
394397 const nextTask = await this . updateTaskWithRetry ( task , {
395398 ...merged ,
396- workflowInstanceId : task . workflowInstanceId ,
397- taskId : task . taskId ,
399+ workflowInstanceId,
400+ taskId,
398401 } ) ;
399- this . logger . debug ( `Task has executed successfully ${ task . taskId } ` ) ;
402+ this . logger . debug ( `Task has executed successfully ${ taskId } ` ) ;
400403 return nextTask ;
401404 } catch ( error : unknown ) {
402405 const durationMs = Date . now ( ) - startTime ;
@@ -405,9 +408,9 @@ export class TaskRunner {
405408 // Publish TaskExecutionFailure event
406409 await this . eventDispatcher . publishTaskExecutionFailure ( {
407410 taskType : this . worker . taskDefName ,
408- taskId : task . taskId ! ,
411+ taskId,
409412 workerId : workerID ,
410- workflowInstanceId : task . workflowInstanceId ,
413+ workflowInstanceId,
411414 cause : err ,
412415 durationMs,
413416 timestamp : new Date ( ) ,
@@ -419,7 +422,7 @@ export class TaskRunner {
419422
420423 if ( isNonRetryable ) {
421424 this . logger . error (
422- `Task ${ task . taskId } failed with terminal error (no retry): ${ err . message } `
425+ `Task ${ taskId } failed with terminal error (no retry): ${ err . message } `
423426 ) ;
424427 }
425428
@@ -428,21 +431,21 @@ export class TaskRunner {
428431 {
429432 log : `${ err . name } : ${ err . message } ${ err . stack ? "\n" + err . stack : "" } ` ,
430433 createdTime : Date . now ( ) ,
431- taskId : task . taskId ,
434+ taskId,
432435 } ,
433436 ] ;
434437
435438 const nextTask = await this . updateTaskWithRetry ( task , {
436- workflowInstanceId : task . workflowInstanceId ,
437- taskId : task . taskId ,
439+ workflowInstanceId,
440+ taskId,
438441 reasonForIncompletion :
439442 ( error as Record < string , string > ) ?. message ?? DEFAULT_ERROR_MESSAGE ,
440443 status,
441444 outputData : { } ,
442445 logs : errorLogs ,
443446 } ) ;
444447 this . errorHandler ( err , task ) ;
445- this . logger . error ( `Error executing ${ task . taskId } ` , error ) ;
448+ this . logger . error ( `Error executing ${ taskId } ` , error ) ;
446449
447450 // Even on failure, chain to next task — the failure was for THIS task
448451 return nextTask ;
0 commit comments