@@ -142,6 +142,7 @@ export function attachEventBridge(
142142 let streamError : Error | undefined ;
143143 const toolMetas : AgentHarnessAttemptResult [ "toolMetas" ] = [ ] ;
144144 const toolMetaIndexByCallId = new Map < string , number > ( ) ;
145+ const projectedToolNamesByCallId = new Map < string , string > ( ) ;
145146 const userRequestedToolCallIds = new Set < string > ( ) ;
146147 let startedCount = 0 ;
147148 let completedCount = 0 ;
@@ -349,12 +350,18 @@ export function attachEventBridge(
349350 } ;
350351 }
351352 const projection = options . transcriptProjection ;
352- const wasTrackedUserRequest = userRequestedToolCallIds . delete ( event . data . toolCallId ) ;
353+ const isDurableRootCompletion = isRootSessionEvent ( event ) && event . ephemeral !== true ;
354+ const wasTrackedUserRequest = userRequestedToolCallIds . has ( event . data . toolCallId ) ;
353355 const isUserRequested = event . data . isUserRequested === true || wasTrackedUserRequest ;
354- if ( projection && isRootSessionEvent ( event ) && event . ephemeral !== true && isUserRequested ) {
356+ const projectedToolName = projectedToolNamesByCallId . get ( event . data . toolCallId ) ;
357+ if ( isDurableRootCompletion ) {
358+ userRequestedToolCallIds . delete ( event . data . toolCallId ) ;
359+ projectedToolNamesByCallId . delete ( event . data . toolCallId ) ;
360+ }
361+ if ( projection && isDurableRootCompletion && isUserRequested ) {
355362 projection . journal . markReplayIncomplete ( ) ;
356363 }
357- if ( projection && isRootSessionEvent ( event ) && event . ephemeral !== true && ! isUserRequested ) {
364+ if ( projection && isDurableRootCompletion && ! isUserRequested ) {
358365 const resultText = event . data . success
359366 ? ( event . data . result ?. content ?? "" )
360367 : ( event . data . error ?. message ?? "Tool execution failed" ) ;
@@ -368,7 +375,7 @@ export function attachEventBridge(
368375 message : {
369376 role : "toolResult" ,
370377 toolCallId : event . data . toolCallId ,
371- toolName : toolName ?? event . data . toolDescription ?. name ?? "unknown" ,
378+ toolName : toolName ?? event . data . toolDescription ?. name ?? projectedToolName ?? "unknown" ,
372379 content : [ { type : "text" , text : sanitizeToolDetailText ( resultText ) } ] ,
373380 ...( hasOwnKeys ( details ) ? { details } : { } ) ,
374381 isError : ! event . data . success ,
@@ -625,6 +632,9 @@ export function attachEventBridge(
625632 return ;
626633 }
627634 handledAssistantEventIds . add ( event . id ) ;
635+ for ( const request of event . data . toolRequests ?? [ ] ) {
636+ projectedToolNamesByCallId . set ( request . toolCallId , request . name ) ;
637+ }
628638 const entry = ensureMessageAccumulator ( messagesById , messageOrder , event . data . messageId ) ;
629639 if ( typeof event . data . content === "string" && event . data . content . length >= entry . text . length ) {
630640 entry . text = event . data . content ;
0 commit comments