fix(openai): handle unrecognized server tool names in _consolidate_calls#36187
Open
Yifei Leng (Senna1960321) wants to merge 1 commit intolangchain-ai:masterfrom
Open
Conversation
When _consolidate_calls encounters a server_tool_call with a name not in the known list (web_search, file_search, code_interpreter, remote_mcp, mcp_list_tools), the collapsed variable is never assigned, causing UnboundLocalError on yield. This affects any new or unrecognized server tool types during v1 → Responses API format conversion. Fix: - Add fallback branch for unrecognized names that emits both items unchanged - Change second `if` to `elif` for file_search to avoid redundant evaluation Fixes langchain-ai#36140
Merging this PR will degrade performance by 12.75%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | WallTime | test_init_time |
121.5 ms | 139.3 ms | -12.75% |
Comparing Senna1960321:fix/consolidate-calls-unbound-local (fb09dc2) with master (1778b08)
Footnotes
-
37 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
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
Fixes #36140
_consolidate_callscrashes withUnboundLocalErrorwhen aserver_tool_callhas a name not in the known set (web_search,file_search,code_interpreter,remote_mcp,mcp_list_tools). This affects any new or unrecognized server tool types (e.g.computer,image_generation) during v1 → Responses API format conversion.Changes:
elsebranch for unrecognized tool names that emits both items unchanged (matching the existing "not a matching pair" behavior)iftoelifforfile_searchto avoid redundant condition evaluation on everyweb_searchcallRepro before fix:
Review notes
The fix is intentionally minimal: unrecognized tools pass through unchanged rather than attempting a best-effort collapse, since we don't know the target schema for unknown tool types.
AI Disclosure
This bug was identified through code review with AI assistance.