core/agent: record every tool result before yielding them

A caller that goes away mid-batch (cancel, display error) left the results of
tools that had already run out of history, so the retry ran them again. Append
the collected results first, then emit the events.
This commit is contained in:
2026-10-06 20:33:30 +08:00
parent 4b1cb84256
commit 7d9b979604
2 changed files with 49 additions and 1 deletions
+5 -1
View File
@@ -124,10 +124,14 @@ async def _execute_tool_calls(
else:
results = [await _run_one_tool(tools, call, max_result_chars=max_result_chars) for call in tool_calls]
# Record every result before yielding any: a caller that goes away mid-batch
# (cancel, display error) must not lose work that already ran, or the retry
# runs that tool a second time.
for tool_msg, _err in results:
messages.append(tool_msg)
for tool_msg, err in results:
if err is not None:
yield err
messages.append(tool_msg)
yield ToolResultEvent(message=tool_msg)