fix(responses): insert synthetic tool messages for missing function_call_output items - #2051
Conversation
Greptile SummaryThis PR repairs incomplete tool-call cycles before forwarding requests. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (3): Last reviewed commit: "fix(pipeline): universal fix for missing..." | Re-trigger Greptile |
d1675d2 to
459675e
Compare
|
Good catch! Fixed in 459675e. The updated algorithm does per-assistant-message independent checking instead of using a global
This means Added a dedicated test case: "same ID across two assistant turns — each checked independently" that validates this exact scenario. |
…n tool definitions Add FixMissingToolCalls pipeline middleware that runs on every request to: 1. Insert synthetic tool messages for assistant tool_calls that lack a corresponding tool response (prevents 'tool_calls must be followed by tool messages' errors from downstream providers) 2. Add dummy tool definitions for any function name referenced in conversation history tool_calls that is missing from the request's tools array (prevents 'tool call id X is not found' errors when Codex-specific tools like exec_command appear in history) The FixMissingToolCallOutputs function in the responses transformer is exported and each assistant message is checked independently so repeated tool-call IDs across turns are handled correctly. Fixes looplj#2049 Co-Authored-By: Claude <noreply@anthropic.com>
459675e to
ab4318c
Compare
|
Updated with the full fix. The original approach only covered the Changes since last review
Middleware does two things on every request:
|
|
这是客户端问题吧 |
Summary
When converting Responses API input items to Chat Completions messages,
function_callitems without matchingfunction_call_outputitems produce assistant messages withtool_callsbut notoolresponses. Downstream providers reject such incomplete tool call cycles.Fix
Add
fixMissingToolCallOutputs— a post-processing step inconvertInputToMessagesthat:tool_call_ids that already have responsesrole: "tool"messages for any tool call lacking a responseChanges
llm/transformer/openai/responses/inbound.go: AddfixMissingToolCallOutputs, called at end ofconvertInputToMessagesllm/transformer/openai/responses/inbound_test.go: Add 9 test casesAll existing tests in
transformer/openai/responses/continue to pass.Closes #2049
🤖 Generated with Claude Code