fix(deepseek): don't drop streamed content deltas equal to "0" - #1036
Open
moaines wants to merge 1 commit into
Open
fix(deepseek): don't drop streamed content deltas equal to "0"#1036moaines wants to merge 1 commit into
moaines wants to merge 1 commit into
Conversation
A streamed number ending in 0 is emitted by the provider as two deltas (e.g. "380" then "0"). The stream handlers treated a "0" delta as "no content" and dropped it, so "3800" was assembled as "380" while the raw API response was correct. A "0" delta is legitimate content and must be yielded. Applies to DeepSeek content + reasoning deltas and XAI thinking deltas. Fixes prism-php#1034
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.
Problem
Numbers ending in
0are corrupted when streamed through the DeepSeek provider.The provider emits
3800as two content deltas —"380"then"0"— and thestream handler skips any delta that is exactly the string
"0", so the assembledtext is
380. Same for2200→220.A raw API call (and Prism's non-streaming
asText()) return the value correctly.The corruption is introduced by Prism's stream parsing, not by the model.
Root cause
src/Providers/DeepSeek/Handlers/Stream.php:A
"0"delta is legitimate content and must be yielded. The same guard existsfor reasoning deltas in the DeepSeek handler and for thinking deltas in the XAI
handler.
Changes
src/Providers/DeepSeek/Handlers/Stream.php— yield"0"content and reasoning deltas.src/Providers/XAI/Handlers/Stream.php— yield"0"thinking deltas.tests/Providers/DeepSeek/StreamTest.php,tests/Providers/XAI/StreamTest.php— regression tests(fail without the fix, pass with it), plus SSE fixtures.
Notes
does not truncate 0 mid streamcovers the same bug forXAI content deltas (already fixed in that path); this PR completes the same fix
for DeepSeek content + reasoning and XAI thinking deltas.
!== '0'guard also appears in severalMessageMapclasses (Anthropic,OpenAI, Gemini, OpenRouter) — that is outgoing message serialization, a
different code path, and is left out of this PR.
Fixes #1034