fix(ai): prevent orphaned tool results after errored assistant messages
When an assistant message has stopReason 'error', its tool calls are now excluded from pending tool tracking. This prevents synthetic tool results from being generated for calls that will be dropped by provider-specific converters (e.g., Codex drops tool calls from errored messages). Previously, this mismatch caused OpenAI to reject requests with 'No tool call found for function call output with call_id ...' errors. fixes #812
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed orphaned tool results after errored assistant messages causing Codex API errors. When an assistant message has `stopReason: "error"`, its tool calls are now excluded from pending tool tracking, preventing synthetic tool results from being generated for calls that will be dropped by provider-specific converters. ([#812](https://github.com/badlogic/pi-mono/issues/812))
|
||||
|
||||
## [0.48.0] - 2026-01-16
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -111,8 +111,13 @@ export function transformMessages<TApi extends Api>(messages: Message[], model:
|
||||
}
|
||||
|
||||
// Track tool calls from this assistant message
|
||||
// Don't track tool calls from errored messages - they will be dropped by
|
||||
// provider-specific converters, so we shouldn't create synthetic results for them
|
||||
const assistantMsg = msg as AssistantMessage;
|
||||
const toolCalls = assistantMsg.content.filter((b) => b.type === "toolCall") as ToolCall[];
|
||||
const toolCalls =
|
||||
assistantMsg.stopReason === "error"
|
||||
? []
|
||||
: (assistantMsg.content.filter((b) => b.type === "toolCall") as ToolCall[]);
|
||||
if (toolCalls.length > 0) {
|
||||
pendingToolCalls = toolCalls;
|
||||
existingToolResultIds = new Set();
|
||||
|
||||
Reference in New Issue
Block a user