Repository navigation
fix(codex): replay tool-call history with call ids instead of flattening it to text - #5761
Merged
Merged
Conversation
…ing it to text CodexLLM.call_with_tools turned earlier assistant tool calls into an empty assistant message and each tool result into a "Tool result: ..." user message, dropping the call_id that links a result to its call. On long reflect loops the model lost track of what it had already retrieved and searched again. Reuse the OpenAI Responses provider's _messages_to_responses_input, which already emits function_call / function_call_output items keyed by call_id; system messages still go to `instructions`. Checked live against the Codex backend. Fixes #5701. Reported, diagnosed and patch tested by @sergesha.
This was referenced Oct 20, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5701.
Problem
With the
openai-codexprovider, every turn of a tool loop (reflect) sent the earlier steps back as plain text: each tool call became an empty assistant message, and each result became a user messageTool result: {...}with no call id. The model could no longer tell which result answered which search, and on long reflect runs it searched again for things it already had. The reporter measured a complex question going from 11 LLM calls / 147 s to 4–6 calls / 54–83 s with the fix.Fix
CodexLLM.call_with_toolsnow reuses_messages_to_responses_inputfrom the OpenAI Responses provider, which already sends earlier steps asfunction_call/function_call_outputitems linked bycall_id(and keeps assistant text that came with the calls). System messages still go intoinstructions. Net −20 lines.Behaviour change
Only how past turns are sent to Codex. Plain messages no longer carry
"type": "message"; the Codex backend accepts that (checked live). Instructions, tools and tool choice are unchanged.Tests
test_call_with_tools_replays_tool_history_with_call_ids(two calls, assistant text, dict arguments/results, order): fails onmain, passes here.Thanks @sergesha for the diagnosis and the tested patch — this is the same change, routed through the shared converter so the two Responses providers can't drift apart again.