Skip to content

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
lazy-hq:mainfrom
zouxiaoliang:fix/streaming-tool-call-name-minimal
Open

fix(openai_chat_completions): don't overwrite tool-call name with an empty-string continuation chunk#121
zouxiaoliang wants to merge 2 commits into
lazy-hq:mainfrom
zouxiaoliang:fix/streaming-tool-call-name-minimal

Conversation

@zouxiaoliang

Copy link
Copy Markdown

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":"", not null and not an omitted key) on every subsequent chunk that only carries argument fragments. The streaming tool-call accumulator in openai_chat_completions's stream_text unconditionally overwrites the accumulated name on every Some(name), so the empty-string continuation chunks clobber the real name — by the time the tool call finishes, ToolCallInfo.tool.name is "" and downstream tool dispatch fails with "Tool not found".

  • Guard the accumulation with !name.is_empty() so only a non-empty name updates the accumulated value.

Test plan

  • cargo check --features openai,openaicompatible passes
  • Verified against the real-world case: captured raw SSE from Volcengine Ark for a tool-calling request and confirmed the delta shape (name empty-string on continuation chunks) that triggers the bug
  • Applied this patch downstream in a consuming project and confirmed a tool-calling turn against the same Ark endpoint now resolves the tool name correctly end to end

…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".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant