fix: remove_all_tools missing MCP and reasoning item types#2700
Draft
joaquinhuigomez wants to merge 3 commits intoopenai:mainfrom
Draft
fix: remove_all_tools missing MCP and reasoning item types#2700joaquinhuigomez wants to merge 3 commits intoopenai:mainfrom
joaquinhuigomez wants to merge 3 commits intoopenai:mainfrom
Conversation
…put history The `_remove_tool_types_from_input` function was missing several item types that `_remove_tools_from_items` already handled for RunItem objects: - `reasoning` items become orphaned when surrounding tool calls are stripped - `mcp_call`, `mcp_list_tools`, `mcp_approval_request`, `mcp_approval_response` were not filtered, leaking MCP tool items through handoff boundaries Also adds MCPListToolsItem, MCPApprovalRequestItem, and MCPApprovalResponseItem to `_remove_tools_from_items` for consistency. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…filters Assert items are not str before calling .get() to satisfy mypy's union-attr check on the input_history item type.
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
_remove_tool_types_from_input(which filters raw input history dicts) was missingreasoning,mcp_call,mcp_list_tools,mcp_approval_request, andmcp_approval_responsetypes. This meant MCP tool items and orphaned reasoning items leaked through theremove_all_toolshandoff filter._remove_tools_from_items(which filters RunItem objects) was missingMCPListToolsItem,MCPApprovalRequestItem, andMCPApprovalResponseItem.Relates to #464 and #1167 (MCP tool handling), and partially addresses the data consistency aspect of #2151 (handoff filters producing inconsistent state).
Test plan
test_removes_tools_from_new_items_and_historyto expect reasoning items filtered from raw input (was 3, now 2)test_removes_reasoning_from_input_history- verifies orphaned reasoning items are removed from raw inputtest_removes_mcp_items_from_input_history- verifies all 4 MCP item types removed from raw inputtest_removes_mcp_run_items_from_new_items- verifies MCP RunItem types removed from pre_handoff_items and new_itemstest_removes_mixed_mcp_and_function_items- end-to-end test mixing MCP, function, and reasoning itemstest_extension_filters.pypass🤖 Generated with Claude Code