fix(llm): add sanitize_tool_messages to OpenAiCodexProvider - #1971
Merged
Merged
Conversation
The OpenAI Codex provider was missing the sanitize_tool_messages() call that all other providers use to rewrite orphaned tool results as user messages. This caused HTTP 400 errors when conversation history contained tool result messages whose corresponding tool calls were dropped during context compaction or thread resume. Adds the call to both complete() and complete_with_tools(), matching the pattern used by rig_adapter, nearai_chat, and bedrock providers. Fixes #1969 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements message sanitization in the OpenAiCodexProvider to handle orphaned tool results, preventing HTTP 400 errors from the OpenAI Responses API. The complete and tool_complete methods now invoke sanitize_tool_messages to ensure orphaned tool results are converted into user messages before the request body is constructed. Additionally, a regression test has been added to verify that these messages are correctly rewritten. I have no feedback to provide.
henrypark133
approved these changes
Apr 3, 2026
This was referenced Apr 3, 2026
serrrfirat
added a commit
that referenced
this pull request
Apr 5, 2026
The OpenAI Codex provider was missing the sanitize_tool_messages() call that all other providers use to rewrite orphaned tool results as user messages. This caused HTTP 400 errors when conversation history contained tool result messages whose corresponding tool calls were dropped during context compaction or thread resume. Adds the call to both complete() and complete_with_tools(), matching the pattern used by rig_adapter, nearai_chat, and bedrock providers. Fixes #1969 Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 5, 2026
This was referenced Apr 7, 2026
drchirag1991
pushed a commit
to drchirag1991/ironclaw
that referenced
this pull request
Apr 8, 2026
) The OpenAI Codex provider was missing the sanitize_tool_messages() call that all other providers use to rewrite orphaned tool results as user messages. This caused HTTP 400 errors when conversation history contained tool result messages whose corresponding tool calls were dropped during context compaction or thread resume. Adds the call to both complete() and complete_with_tools(), matching the pattern used by rig_adapter, nearai_chat, and bedrock providers. Fixes nearai#1969 Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 8, 2026
Merged
Merged
theredspoon
pushed a commit
to theredspoon/ironclaw
that referenced
this pull request
Jun 21, 2026
) The OpenAI Codex provider was missing the sanitize_tool_messages() call that all other providers use to rewrite orphaned tool results as user messages. This caused HTTP 400 errors when conversation history contained tool result messages whose corresponding tool calls were dropped during context compaction or thread resume. Adds the call to both complete() and complete_with_tools(), matching the pattern used by rig_adapter, nearai_chat, and bedrock providers. Fixes nearai#1969 Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
sanitize_tool_messages()call toOpenAiCodexProvider::complete()andcomplete_with_tools(), matching the pattern used by all other providers (nearai_chat, rig_adapter, bedrock)Test plan
cargo clippy --all --benches --tests --examples --all-features— zero warningscargo fmt— cleanllm::openai_codex_provider::testspasstest_build_request_sanitizes_orphaned_tool_resultscovers the fixLLM_BACKEND=openai_codexand a long conversation with tool callsFixes #1969
🤖 Generated with Claude Code