@@ -37,6 +37,10 @@ import { makeMissingToolResult, sanitizeToolCallInputs } from "./session-transcr
3737import type { SessionManager } from "./sessions/index.js" ;
3838import { extractToolCallsFromAssistant , extractToolResultId } from "./tool-call-id.js" ;
3939
40+ function readFiniteTimestamp ( value : unknown ) : number | undefined {
41+ return typeof value === "number" && Number . isFinite ( value ) ? value : undefined ;
42+ }
43+
4044/**
4145 * Truncate oversized text content blocks in a tool result message.
4246 * Returns the original message if under the limit, or a new message with
@@ -705,16 +709,17 @@ export function installSessionToolResultGuard(
705709 return ;
706710 }
707711 if ( allowSyntheticToolResults ) {
708- for ( const [ id , name ] of pendingState . entries ( ) ) {
712+ for ( const [ id , entry ] of pendingState . entries ( ) ) {
709713 const synthetic = makeMissingToolResult ( {
710714 toolCallId : id ,
711- toolName : name ,
715+ toolName : entry . name ,
712716 text : missingToolResultText ,
717+ sourceTimestamp : entry . timestamp ,
713718 } ) ;
714719 const flushed = applyBeforeWriteHook (
715720 persistToolResult ( persistMessage ( synthetic ) , {
716721 toolCallId : id ,
717- toolName : name ,
722+ toolName : entry . name ,
718723 isSynthetic : true ,
719724 } ) ,
720725 ) ;
@@ -858,7 +863,17 @@ export function installSessionToolResultGuard(
858863 }
859864
860865 if ( toolCalls . length > 0 ) {
861- pendingState . trackToolCalls ( toolCalls ) ;
866+ const assistantTimestamp = readFiniteTimestamp (
867+ ( finalMessage as { timestamp ?: unknown } ) . timestamp ,
868+ ) ;
869+ pendingState . trackToolCalls (
870+ toolCalls . map ( ( call ) => {
871+ if ( assistantTimestamp === undefined ) {
872+ return call ;
873+ }
874+ return { id : call . id , name : call . name , timestamp : assistantTimestamp } ;
875+ } ) ,
876+ ) ;
862877 }
863878 if ( isUserAgentMessage ( finalMessage ) ) {
864879 void opts ?. onUserMessagePersisted ?.( finalMessage ) ;
0 commit comments