fix(result): drop reasoning items orphaned by dropped tool calls#3207
Merged
seratch merged 1 commit intoopenai:mainfrom May 8, 2026
Merged
Conversation
When a tool call is dropped by `drop_orphan_function_calls` because its output is missing, any reasoning items immediately preceding it become dangling. Forwarding them to the Responses API triggers `Item 'rs_...' of type 'reasoning' was provided without its required following item` (issues openai#985, openai#2020). Track which tool-call indexes get dropped during the existing pass and strip the reasoning items that were tied to them before returning. Lone reasoning items (e.g. server-managed conversations where the required following item lives on the server) are still preserved when no tool calls are dropped.
Member
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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
When
drop_orphan_function_callsremoves an unpaired tool call from the items being sent to the Responses API, any reasoning items that immediately precede it become dangling. Forwarding them triggers errors like:This is the symptom reported in #985 (CodeInterpreter + handoff with reasoning models) and reproduced in #2020 (multi-agent handoff with
gpt-5reasoning).The fix tracks which tool-call indexes are dropped during the existing pass and removes the reasoning items that were tied to them before returning. A reasoning item is considered tied to the next non-reasoning item; if that next item was dropped, the reasoning chain is now dangling and is stripped.
Lone reasoning items (e.g. server-managed conversations where the required following item lives on the server, or the
omitreasoning policy that strips standalone reasoning trace inputs) are still preserved when no tool calls are dropped, so the existing tracker behavior is unchanged.Test plan
test_drop_orphan_function_calls_drops_reasoning_preceding_dropped_tool_callcovers the dropped-orphan-tool-call -> dangling-reasoning-items chain (mirrors Item with idrs_not found #2020).test_drop_orphan_function_calls_keeps_lone_reasoning_when_no_tool_calls_droppedconfirms server-managed conversations still keep standalone reasoning items.tests/test_run_internal_items.py(19 tests),tests/test_agent_runner*.py,tests/test_handoff*.py, andtests/test_server_conversation_tracker.pyall pass.pytest tests/sweep (excluding optionalrealtime/voice/mcp/sandboxextras): 3332 passed, 28 skipped.