fix(core): prevent cross-type content block merging in merge_lists#35984
Open
Mason Daugherty (mdrxy) wants to merge 2 commits intomasterfrom
Open
fix(core): prevent cross-type content block merging in merge_lists#35984Mason Daugherty (mdrxy) wants to merge 2 commits intomasterfrom
merge_lists#35984Mason Daugherty (mdrxy) wants to merge 2 commits intomasterfrom
Conversation
Merging this PR will not alter performance
|
merge_lists
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.
merge_listsmerges dicts by matchingindexvalues but does not checktype. When a model returns both text and tool calls in a streaming response withoutput_version="v1", text blocks (index: 0from the streaming wrapper) andtool_call_chunkblocks (index: 0from the API) merge into a single corrupt dict withtype: "text"carrying orphanedname/args/idfields. Theinit_tool_callsvalidator cannot findtype: "tool_call_chunk"to promote, so tool calls silently vanish fromcontent_blocks.This affects
BaseChatOpenAIsubclassers without registered block translators and any model that returns text alongside tool calls (e.g., GLM-5 via Baseten). Related to #32888 which proposes the broader fix of raising ontypeconflicts inmerge_dicts.Changes
merge_listsindex-matching: prevent merging when one block hastype: "text"and the other does not — a text-vs-everything-else partition that keeps text and tool_call_chunk blocks separate soinit_tool_callscan promote them correctly. Non-text blocks at the same index (e.g., Anthropic'stool_use+input_json_delta) still merge as before.Revert basetenlabs/langchain-baseten#6 when released