From ea1ad68a5a0aa42b5bfc056c00f3855694281c22 Mon Sep 17 00:00:00 2001 From: dal Date: Mon, 29 Sep 2025 11:03:40 -0600 Subject: [PATCH] Fix: wait for deltas to finish then write --- .../communication-tools/done-tool/done-tool-execute.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/ai/src/tools/communication-tools/done-tool/done-tool-execute.ts b/packages/ai/src/tools/communication-tools/done-tool/done-tool-execute.ts index 9df74d9d6..228c20dd0 100644 --- a/packages/ai/src/tools/communication-tools/done-tool/done-tool-execute.ts +++ b/packages/ai/src/tools/communication-tools/done-tool/done-tool-execute.ts @@ -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; },