Skip to content

fix(deepseek): don't drop streamed content deltas equal to "0" - #1036

Open
moaines wants to merge 1 commit into
prism-php:mainfrom
moaines:fix/drop-zero-content-delta
Open

fix(deepseek): don't drop streamed content deltas equal to "0"#1036
moaines wants to merge 1 commit into
prism-php:mainfrom
moaines:fix/drop-zero-content-delta

Conversation

@moaines

@moaines moaines commented Aug 14, 2026

Copy link
Copy Markdown

Problem

Numbers ending in 0 are corrupted when streamed through the DeepSeek provider.
The provider emits 3800 as two content deltas — "380" then "0" — and the
stream handler skips any delta that is exactly the string "0", so the assembled
text is 380. Same for 2200220.

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:

$content = $this->extractContentDelta($data);
if ($content !== '' && $content !== '0') {
    // yield TextDeltaEvent ...
    continue;
}
// a "0" delta falls through and is treated as "no content"

A "0" delta is legitimate content and must be yielded. The same guard exists
for 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

  • The existing XAI test does not truncate 0 mid stream covers the same bug for
    XAI content deltas (already fixed in that path); this PR completes the same fix
    for DeepSeek content + reasoning and XAI thinking deltas.
  • The !== '0' guard also appears in several MessageMap classes (Anthropic,
    OpenAI, Gemini, OpenRouter) — that is outgoing message serialization, a
    different code path, and is left out of this PR.

Fixes #1034

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
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.

Prism drops streamed content deltas equal to "0"

1 participant