fix(agents): await block-reply flush before tool execution starts

handleToolExecutionStart() flushed pending block replies and then called
onBlockReplyFlush() as fire-and-forget (`void`). This created a race where
fast tool results (especially media on Telegram) could be delivered before
the text block that preceded the tool call.

Await onBlockReplyFlush() so the block pipeline finishes before tool
execution continues, preserving delivery order.

Fixes #25267

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
SidQin-cyber
2026-02-24 21:13:34 +08:00
committed by Peter Steinberger
parent 4d124e4a9b
commit 99d854db82
2 changed files with 32 additions and 1 deletions

View File

@@ -174,7 +174,7 @@ export async function handleToolExecutionStart(
// Flush pending block replies to preserve message boundaries before tool execution.
ctx.flushBlockReplyBuffer();
if (ctx.params.onBlockReplyFlush) {
void ctx.params.onBlockReplyFlush();
await ctx.params.onBlockReplyFlush();
}
const rawToolName = String(evt.toolName);