Skip to content

fix(result): drop reasoning items orphaned by dropped tool calls#3207

Merged
seratch merged 1 commit intoopenai:mainfrom
adityasingh2400:fix/result-orphan-reasoning-items
May 8, 2026
Merged

fix(result): drop reasoning items orphaned by dropped tool calls#3207
seratch merged 1 commit intoopenai:mainfrom
adityasingh2400:fix/result-orphan-reasoning-items

Conversation

@adityasingh2400
Copy link
Copy Markdown
Contributor

Summary

When drop_orphan_function_calls removes 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:

Item 'rs_...' of type 'reasoning' was provided without its required following item

This is the symptom reported in #985 (CodeInterpreter + handoff with reasoning models) and reproduced in #2020 (multi-agent handoff with gpt-5 reasoning).

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 omit reasoning 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

  • New regression test test_drop_orphan_function_calls_drops_reasoning_preceding_dropped_tool_call covers the dropped-orphan-tool-call -> dangling-reasoning-items chain (mirrors Item with id rs_ not found #2020).
  • New regression test test_drop_orphan_function_calls_keeps_lone_reasoning_when_no_tool_calls_dropped confirms server-managed conversations still keep standalone reasoning items.
  • Existing tests/test_run_internal_items.py (19 tests), tests/test_agent_runner*.py, tests/test_handoff*.py, and tests/test_server_conversation_tracker.py all pass.
  • Full pytest tests/ sweep (excluding optional realtime/voice/mcp/sandbox extras): 3332 passed, 28 skipped.

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.
@github-actions github-actions Bot added bug Something isn't working feature:core labels May 8, 2026
@seratch
Copy link
Copy Markdown
Member

seratch commented May 8, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@seratch seratch added this to the 0.17.x milestone May 8, 2026
@seratch seratch merged commit 1d38492 into openai:main May 8, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants