fix(core): prevent tool replay on generateText retries
Fixes #1537
When a later model request fails after a tool step, generateText can
restart from the original messages and execute the same tool again.
Once a step records a tool result or error, surface the original failure
to the caller instead of restarting generation through retry or fallback.
Added regression tests for both paths. The core suite passed with
1,402 tests and no type errors.
Summary by cubic
Fixes a bug where generateText could replay completed tool calls when a later model request failed. Once a tool executes, a subsequent model failure is now returned to the caller instead of restarting generation through retry or fallback, preventing duplicate tool side effects. This also covers approved tools that run before the first model step.
- Adds regression tests for retry and fallback paths, covering both model-called and approval-resumed tools.
- Updates the retries and fallback docs to describe the new behavior.
Summary by CodeRabbit
-
Bug Fixes
- Prevented
generateTextretries and model fallback from re-executing completed tool calls. If a tool runs or a step records a tool result or error, the failure is returned to the caller instead. - This also applies when an approved tool runs before the first model step.
- Prevented
-
Documentation
- Clarified how
generateTexthandles failures after tool execution, including approved tools run before the first model step.
- Clarified how