fix(openai_chat_completions): don't overwrite tool-call name with an empty-string continuation chunk#121
Open
zouxiaoliang wants to merge 2 commits into
Conversation
…me overwrite an already-captured tool-call name Some OpenAI-compatible gateways (observed: Volcengine Ark) resend the tool-call function name as an empty string on every delta chunk after the first, instead of omitting the field or sending null. The streaming accumulator was unconditionally overwriting the previously captured name with this empty string, so by the time the tool call completed its name was always "", and the SDK's tool dispatch failed with "Tool not found".
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
Some OpenAI-compatible gateways (observed with Volcengine Ark) send the tool-call function name once on the first streamed delta chunk, then resend it as an empty string (
"name":"", notnulland not an omitted key) on every subsequent chunk that only carries argument fragments. The streaming tool-call accumulator inopenai_chat_completions'sstream_textunconditionally overwrites the accumulated name on everySome(name), so the empty-string continuation chunks clobber the real name — by the time the tool call finishes,ToolCallInfo.tool.nameis""and downstream tool dispatch fails with "Tool not found".!name.is_empty()so only a non-empty name updates the accumulated value.Test plan
cargo check --features openai,openaicompatiblepassesnameempty-string on continuation chunks) that triggers the bug