fix: tool call arguments lost on OpenAI-compatible providers that stream id only in first SSE chunk#1522
Open
goingforstudying-ctrl wants to merge 1 commit into
Conversation
…eam id only in first SSE chunk
When using an OpenAI-compatible provider whose streaming responses omit
the id field on tool-call continuation chunks (e.g. GLM-5 via OpenRouter),
aichat dispatched the tool with arguments: '{}' instead of the actual
arguments.
Root cause: openai_chat_completions_streaming computed the call-boundary
key using id.unwrap_or_default(), which yields empty string when id is
absent in continuation chunks, producing maybe_call_id = '/0'. This does
not match the stored call_id and triggers a spurious flush.
Fix: Only advance the boundary when id is present in the chunk — i.e.
only on the first chunk of a new call. Continuation chunks have no id
and now pass through without touching the boundary logic.
Closes sigoden#1495
Author
|
Hi, just checking in on this PR. It has been 6 days since the last update. Please let me know if there is anything else needed from my side to move this forward. Thanks for your time. |
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.
What
Fixes a bug where tool call arguments are lost (sent as
{}) when using OpenAI-compatible providers that omit theidfield on tool-call continuation SSE chunks (e.g. GLM-5 via OpenRouter).Why
Per the OpenAI streaming spec,
idis present only in the first delta chunk for a given tool call. Continuation chunks carry argument fragments with the sameindexbut noid.The current code computes the call-boundary key as:
When
idis absent,unwrap_or_default()yields "", producingmaybe_call_id = "/0". This does not match the storedcall_id, so a spurious boundary is detected:function_argumentsis flushed (empty at that point) and cleared. The subsequent argument fragments are appended to the now-empty buffer, but the tool is dispatched with the flushed empty string, normalised to{}.How
Only advance the boundary when
idis present in the chunk — i.e. only on the first chunk of a new call. Continuation chunks have noidand now pass through without touching the boundary logic.Using
{id}/{index}retains uniqueness for providers that reuseindex: 0across every call (the original intent of commit 7d33a2c).Testing
cargo +nightly check --bin aichatCloses #1495