Repository navigation
fix(sse): keep a numeric delta.content as string text in the OpenAI passthrough - #16614
Merged
diegosouzapw merged 3 commits intoOct 15, 2026
Conversation
…assthrough Cloudflare Workers AI sometimes streams a digit as a JSON number in choices[].delta.content. The passthrough only counts string content as text (hasValuableContent and the collectors check typeof string), so a chunk whose only content is a number was dropped and the digit disappeared from the reply. Turn a finite numeric content into its decimal string in normalizeArrayContentDelta, which every stream path already runs. A zero is kept; a NaN is left alone. Refs cheaper-inference#16554.
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
diegosouzapw
merged commit Oct 15, 2026
91e665b
into
cheaper-inference:release/v3.8.52
47 of 60 checks passed
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
choices[].delta.content({"delta":{"content":7}}) instead of a string. The OpenAI passthrough only counted string content as text, so those chunks were dropped and the digits vanished from the reply:A B 7 . 1 . 9came out asAB...hasValuableContentand the stream collectors checktypeof content === "string", so a chunk whose only content is a number is discarded (stream.tscontinues when the chunk has no valuable content).normalizeArrayContentDeltaalready folds non-stringdelta.content(Mistral part arrays) into a string for every stream path; it now also turns a finite number into its decimal string.Related Issues
Target Branch
release/v3.8.xbranch (the highest openrelease/v*), notmainProof Of Fix (required)
tests/unit/openai-numeric-delta-content.test.tsTests Added Or Updated
tests/unit/openai-numeric-delta-content.test.ts: (1) a stream throughcreateSSEStreamin passthrough mode with string and numeric deltas, including a0, concatenates toAB7.1.90and every forwardedcontentis a string; (2)normalizeArrayContentDeltaconverts7and0, leavesNaNand plain strings alone.Coverage Notes
mode: "passthrough", OpenAI client format). The Responses translator and the other stream modes call the same normalizer; they have no dedicated test for numeric content.Scope
open-sse/utils/arrayContentDelta.ts, the test and the changelog fragment)Validation
createSSEStream,arrayContentDeltaorresponseSanitizerpass (438);check:ai-attributionandcheck:changelog-integritypass; eslint is clean on the touched filesnpm run lint(the repository-wide run is left to CI).check:file-sizereports the same five violations on the base and on this branch; none of those files is touched here.Reviewer Notes
7.10arrives as the JSON number7.1, and leading zeros disappear in the same way, so a numeric chunk is recovered as the digits the number holds, not as the text the model produced. Cloudflare should emit strings; this only stops OmniRoute from discarding the chunk. The upstream report is Workers AI OpenAI-compatible streaming:delta.contentsometimes arrives as a JSON number instead of a string cloudflare/ai#651.NaNandInfinity(not valid JSON anyway) are left as they were.