Skip to content

fix(codex): replay tool-call history with call ids instead of flattening it to text - #5761

Merged
nicoloboschi merged 1 commit into
mainfrom
triage/5701
Oct 19, 2026
Merged

nicoloboschi merged 1 commit into
mainfrom
triage/5701

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Fixes #5701.

Problem

With the openai-codex provider, 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 message Tool 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_tools now reuses _messages_to_responses_input from the OpenAI Responses provider, which already sends earlier steps as function_call / function_call_output items linked by call_id (and keeps assistant text that came with the calls). System messages still go into instructions. 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

  • New test_call_with_tools_replays_tool_history_with_call_ids (two calls, assistant text, dict arguments/results, order): fails on main, passes here.
  • All Codex + OpenAI Responses provider tests pass (114).
  • Live call against the real Codex backend with a replayed tool history: accepted; the model answers from the linked result.

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.

…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.
@nicoloboschi
nicoloboschi merged commit 2e4339c into main Oct 19, 2026
117 checks passed
@nicoloboschi
nicoloboschi deleted the triage/5701 branch October 19, 2026 11:40
@nicoloboschi nicoloboschi mentioned this pull request Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex provider drops tool-call history and call IDs, causing repeated Reflect retrieval; tested patch

1 participant