Fix: wait for deltas to finish then write

This commit is contained in:
dal 2025-09-29 11:03:40 -06:00
parent 200ea567a7
commit ea1ad68a5a
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
1 changed files with 5 additions and 3 deletions

View File

@ -75,11 +75,13 @@ export function createDoneToolExecute(context: DoneToolContext, state: DoneToolS
throw new Error('Tool call ID is required');
}
const result = await processDone(state, state.toolCallId, context.messageId, context, input);
// Wait for all pending updates from delta/finish to complete before returning
// CRITICAL: Wait for ALL pending updates from delta/finish to complete FIRST
// This ensures execute's update is always the last one in the queue
await waitForPendingUpdates(context.messageId);
// Now do the final authoritative update with the complete input
const result = await processDone(state, state.toolCallId, context.messageId, context, input);
cleanupState(state);
return result;
},