fix: #1668 Handoffs with gpt-5* model + store=False + remove_all_tools fails due to 404 error response #1757
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.
Issue
When
store=False
andhandoff_filters.remove_all_tools
is used during a handoff, the filter currently removes:HandoffCallItem
andHandoffOutputItem
... But it does not remove the correspondingReasoningItem
.Since
store=False
means items are not persisted on the server side, the Responses API fails because theReasoningItem
is still present, but its referenced item has already been removed. This leads to a 404 error:This PR fixes: #1668
Reproduction Example
Solution
Updated
_remove_tools_from_items(...)
to also dropReasoningItem
.This ensures that reasoning items are removed together with tool/handoff items, preventing API errors.
Note
There is another function in the same file,
_remove_tool_types_from_input(...)
, which is for filtering the input history, and it intentionally does not remove reasoning items.With store=False, removing it would also work without errors.
However, with store=True, developers often reuse the previous round’s
to_input_list()
(containing message items that include IDs) and pass it into the Responses API. In this case, the server requires each message to be paired with its corresponding reasoning item. Removing reasoning in this path would cause errors such as: Item 'msg_xxxxx' of type 'message' was provided without its required 'reasoning' item: 'rs_xxxxxx'For this reason,
_remove_tool_types_from_input(...)
intentionally keeps reasoning items.