fix(pipeline): handle duplicate finish_reason chunks from OpenRouter#2403
Merged
tanzhenxin merged 1 commit intoQwenLM:mainfrom Mar 18, 2026
Merged
Conversation
Some OpenRouter model providers (e.g. google/gemini-3.1-flash-lite-preview) send two consecutive SSE chunks with finish_reason='tool_calls'. The second chunk arrives after streamingToolCallParser.reset() has been called, so it carries empty parts — no functionCall entries. The original handleChunkMerging treated every finish chunk as authoritative and overwrote pendingFinishResponse, discarding the functionCall parts that were correctly assembled from the first finish chunk. Fix: when a second finish chunk arrives and a pendingFinishResponse already exists, only merge usageMetadata (if present) and keep the candidates from the first finish chunk.
simon100500
added a commit
to simon100500/gantt-lib-mcp
that referenced
this pull request
Mar 15, 2026
…uter OpenRouter присылает два SSE чанка с finish_reason=tool_calls. Второй пустой чанк перезаписывал pendingFinishResponse, сбрасывая functionCall parts — SDK выбрасывал "Model stream ended with empty response text". Патч handleChunkMerging: при повторном finish чанке сохраняем candidates от первого, мёрджим только usageMetadata. - patches/@qwen-code+sdk+0.1.5.patch — персистентный патч - package.json — postinstall: patch-package - patch-package добавлен в devDependencies - PR: QwenLM/qwen-code#2403 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Mingholy
approved these changes
Mar 16, 2026
Collaborator
|
Thanks for the contribution! |
This was referenced Mar 18, 2026
This was referenced Mar 21, 2026
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 #2402
Problem
Some OpenRouter model providers (e.g.
google/gemini-3.1-flash-lite-preview) send two consecutive SSE chunks withfinish_reason: "tool_calls". The second chunk arrives afterstreamingToolCallParser.reset()has already been called, so it carries emptyparts— nofunctionCallentries.handleChunkMergingtreated every finish chunk as authoritative and overwrotependingFinishResponsewith the empty duplicate, discarding thefunctionCallparts correctly assembled from the first finish chunk.This caused
processStreamResponseto seehasToolCall=falseand throw:Fix
In
handleChunkMerging: when a second finish chunk arrives and apendingFinishResponsealready exists, only mergeusageMetadata(if present) and keep thecandidatesfrom the first finish chunk.Testing
The existing
pipeline.test.tssuite should cover regressions. A new test case can be added for the duplicate-finish-chunk scenario if desired.