Skip to content

fix(llm): add sanitize_tool_messages to OpenAiCodexProvider - #1971

Merged
serrrfirat merged 1 commit into
stagingfrom
fix/1969-codex-sanitize-tool-messages
Apr 3, 2026
Merged

serrrfirat merged 1 commit into
stagingfrom
fix/1969-codex-sanitize-tool-messages

Conversation

@serrrfirat

Copy link
Copy Markdown
Collaborator

Summary

  • Add missing sanitize_tool_messages() call to OpenAiCodexProvider::complete() and complete_with_tools(), matching the pattern used by all other providers (nearai_chat, rig_adapter, bedrock)
  • Without this, orphaned tool results (where the corresponding tool call was dropped during context compaction or thread resume) cause HTTP 400: "No tool call found for function call output with call_id ..."
  • Add regression test verifying orphaned tool results are rewritten before reaching the API

Test plan

  • cargo clippy --all --benches --tests --examples --all-features — zero warnings
  • cargo fmt — clean
  • All 25 tests in llm::openai_codex_provider::tests pass
  • New regression test test_build_request_sanitizes_orphaned_tool_results covers the fix
  • Manual test with LLM_BACKEND=openai_codex and a long conversation with tool calls

Fixes #1969

🤖 Generated with Claude Code

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>
@github-actions github-actions Bot added scope: llm LLM integration size: M 50-199 changed lines risk: low Changes to docs, tests, or low-risk modules contributor: experienced 6-19 merged PRs labels Apr 3, 2026
@serrrfirat
serrrfirat requested a review from henrypark133 April 3, 2026 13:59

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@serrrfirat
serrrfirat merged commit 1e2d335 into staging Apr 3, 2026
14 checks passed
@serrrfirat
serrrfirat deleted the fix/1969-codex-sanitize-tool-messages branch April 3, 2026 15:05
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>
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>
@ironclaw-ci ironclaw-ci Bot mentioned this pull request Apr 10, 2026
@ironclaw-ci ironclaw-ci Bot mentioned this pull request Apr 18, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: experienced 6-19 merged PRs risk: low Changes to docs, tests, or low-risk modules scope: llm LLM integration size: M 50-199 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAiCodexProvider missing sanitize_tool_messages causes HTTP 400 on orphaned tool results

2 participants