fix(acl/openai): assign new block index for text interleaved between tool calls - #976
Open
oierxjn wants to merge 3 commits into
Open
fix(acl/openai): assign new block index for text interleaved between tool calls#976oierxjn wants to merge 3 commits into
oierxjn wants to merge 3 commits into
Conversation
…tool calls Some providers (e.g. Cloudflare Workers AI gateways) emit content chunks between parallel tool-call chunks in one stream. Once tool calls started, chunkConverter.advanceContent only compared block type and source index, so an interleaved text chunk inherited the tool-call group's StreamingMeta.Index. ConcatAgenticMessages then grouped mismatched block types under one index and failed with: content block type mismatch: expected 'function_tool_call', but got 'assistant_gen_text' When inToolCalls is set, advanceContent now always starts a new block and resets inToolCalls so a following tool call also gets a fresh index. Fixes cloudwego#975
oierxjn
marked this pull request as ready for review
August 28, 2026 03:45
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.
Fixes #975
Problem
Some providers (observed on Cloudflare Workers AI gateways) emit content chunks between parallel tool-call chunks in one stream:
chunkConverter.advanceContentonly compares block type and source index, ignoringc.inToolCalls. Once tool calls have started, an interleaved text chunk still matches the previous text block's type, so it inherits the tool-call group'sStreamingMeta.Index.schema.ConcatAgenticMessagesthen groups mismatched block types under one index and fails with:Fix
When
inToolCallsis set,advanceContentnow always advances to a new block index and resetsinToolCalls, so:Change is confined to
(*chunkConverter).advanceContent; streams without interleaved text are unaffected.Test
Added
TestChunkConverter/text_interleaved_between_tool_callscovering the exact frame sequence (text → tool call 0 → interleaved text → tool call 1), asserting each block gets a distinct index and the full sequence passesConcatAgenticMessages.