fix(openai): strengthen streaming tool call dedup to prevent false evictions#1510
Open
majiayu000 wants to merge 1 commit into0xPlaygrounds:mainfrom
Open
fix(openai): strengthen streaming tool call dedup to prevent false evictions#1510majiayu000 wants to merge 1 commit into0xPlaygrounds:mainfrom
majiayu000 wants to merge 1 commit into0xPlaygrounds:mainfrom
Conversation
…ictions The deduplication heuristic added in v0.32 evicts a tool call entry when a new chunk arrives at the same index with a different id. This breaks providers (e.g. GLM-4) that send a unique id on every SSE chunk for the same logical tool call — each chunk triggers a false eviction, yielding incomplete fragments. Strengthen the condition to require both id AND name to differ before evicting. A genuinely new tool call at the same index (the LiteLLM/OneAPI gateway case) always carries a new non-empty name, while continuation chunks have an empty name. Adds a regression test reproducing the GLM-4 scenario from issue 0xPlaygrounds#1508. Fixes 0xPlaygrounds#1508 Signed-off-by: majiayu000 <1835304752@qq.com>
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
The deduplication heuristic added in v0.32 (
streaming.rs~line 211) evicts a tool call entry when a new SSE chunk arrives at the same index with a differentid. This breaks providers (e.g. GLM-4 via OpenAI-compatible endpoints) that send a uniqueidon every SSE delta chunk for the same logical tool call — each chunk triggers a false eviction, yielding incomplete fragments as "completed" tool calls.Fix: Strengthen the eviction condition to require both
idANDnameto be non-empty and different from the existing entry. A genuinely new tool call at the same index (the LiteLLM/OneAPI gateway case) always carries a new non-empty name, while continuation chunks from providers like GLM-4 have an empty name.Fixes #1508
Changes
namecomparison to the dedup eviction guard: eviction now requires both a new non-emptyidthat differs and a new non-emptynamethat differstest_unique_id_per_chunk_single_tool_callreproducing the exact GLM-4 scenario from the issueTest plan
test_unique_id_per_chunk_single_tool_callverifies GLM-4 chunks with unique IDs accumulate into one tool calltest_duplicate_index_different_id_tool_callsstill passes (LiteLLM/OneAPI gateway case)cargo fmtcleancargo clippyclean