@@ -228,6 +228,20 @@ function cancelledCompletion(message: string): AsyncToolCompletion {
228228 }
229229}
230230
231+ function reportCancelledTool (
232+ toolCall : { id : string ; name : string } ,
233+ message : string ,
234+ data : Record < string , unknown > = { cancelled : true }
235+ ) : void {
236+ markToolComplete ( toolCall . id , toolCall . name , 499 , message , data ) . catch ( ( err ) => {
237+ logger . error ( 'markToolComplete failed (cancelled)' , {
238+ toolCallId : toolCall . id ,
239+ toolName : toolCall . name ,
240+ error : err instanceof Error ? err . message : String ( err ) ,
241+ } )
242+ } )
243+ }
244+
231245async function maybeWriteOutputToTable (
232246 toolName : string ,
233247 params : Record < string , unknown > | undefined ,
@@ -472,14 +486,7 @@ export async function executeToolAndReport(
472486 result : { cancelled : true } ,
473487 error : 'Request aborted before tool execution' ,
474488 } ) . catch ( ( ) => { } )
475- markToolComplete ( toolCall . id , toolCall . name , 499 , 'Request aborted before tool execution' , {
476- cancelled : true ,
477- } ) . catch ( ( err ) => {
478- logger . error ( 'markToolComplete failed (aborted before execute)' , {
479- toolCallId : toolCall . id ,
480- error : err instanceof Error ? err . message : String ( err ) ,
481- } )
482- } )
489+ reportCancelledTool ( toolCall , 'Request aborted before tool execution' )
483490 return cancelledCompletion ( 'Request aborted before tool execution' )
484491 }
485492
@@ -504,6 +511,7 @@ export async function executeToolAndReport(
504511 result : { cancelled : true } ,
505512 error : 'Request aborted during tool execution' ,
506513 } ) . catch ( ( ) => { } )
514+ reportCancelledTool ( toolCall , 'Request aborted during tool execution' )
507515 return cancelledCompletion ( 'Request aborted during tool execution' )
508516 }
509517 result = await maybeWriteOutputToFile ( toolCall . name , toolCall . params , result , execContext )
@@ -517,6 +525,7 @@ export async function executeToolAndReport(
517525 result : { cancelled : true } ,
518526 error : 'Request aborted during tool post-processing' ,
519527 } ) . catch ( ( ) => { } )
528+ reportCancelledTool ( toolCall , 'Request aborted during tool post-processing' )
520529 return cancelledCompletion ( 'Request aborted during tool post-processing' )
521530 }
522531 result = await maybeWriteOutputToTable ( toolCall . name , toolCall . params , result , execContext )
@@ -530,6 +539,7 @@ export async function executeToolAndReport(
530539 result : { cancelled : true } ,
531540 error : 'Request aborted during tool post-processing' ,
532541 } ) . catch ( ( ) => { } )
542+ reportCancelledTool ( toolCall , 'Request aborted during tool post-processing' )
533543 return cancelledCompletion ( 'Request aborted during tool post-processing' )
534544 }
535545 result = await maybeWriteReadCsvToTable ( toolCall . name , toolCall . params , result , execContext )
@@ -543,6 +553,7 @@ export async function executeToolAndReport(
543553 result : { cancelled : true } ,
544554 error : 'Request aborted during tool post-processing' ,
545555 } ) . catch ( ( ) => { } )
556+ reportCancelledTool ( toolCall , 'Request aborted during tool post-processing' )
546557 return cancelledCompletion ( 'Request aborted during tool post-processing' )
547558 }
548559 toolCall . status = result . success ? 'success' : 'error'
@@ -590,6 +601,7 @@ export async function executeToolAndReport(
590601
591602 if ( abortRequested ( context , execContext , options ) ) {
592603 toolCall . status = 'cancelled'
604+ reportCancelledTool ( toolCall , 'Request aborted before tool result delivery' )
593605 return cancelledCompletion ( 'Request aborted before tool result delivery' )
594606 }
595607
@@ -701,6 +713,7 @@ export async function executeToolAndReport(
701713 result : { cancelled : true } ,
702714 error : 'Request aborted during tool execution' ,
703715 } ) . catch ( ( ) => { } )
716+ reportCancelledTool ( toolCall , 'Request aborted during tool execution' )
704717 return cancelledCompletion ( 'Request aborted during tool execution' )
705718 }
706719 toolCall . status = 'error'
0 commit comments