Skip to content

fix(sse): keep a numeric delta.content as string text in the OpenAI passthrough - #16614

Merged
diegosouzapw merged 3 commits into
cheaper-inference:release/v3.8.52from
pacocartones:fix/numeric-delta-content
Oct 15, 2026
Merged

diegosouzapw merged 3 commits into
cheaper-inference:release/v3.8.52from
pacocartones:fix/numeric-delta-content

Conversation

@pacocartones

Copy link
Copy Markdown
Contributor

Summary

  • Some Cloudflare Workers AI models stream a digit as a JSON number in 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 . 9 came out as AB...
  • Root cause: hasValuableContent and the stream collectors check typeof content === "string", so a chunk whose only content is a number is discarded (stream.ts continues when the chunk has no valuable content). normalizeArrayContentDelta already folds non-string delta.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

  • Base is the active release/v3.8.x branch (the highest open release/v*), not main

Proof Of Fix (required)

  • TDD (preferred) — a test that fails before the fix and passes after it.
    • Test file(s): tests/unit/openai-numeric-delta-content.test.ts
    • Failing output before the fix:
      passthrough keeps numeric delta.content as string text
        actual:   'AB..'
        expected: 'AB7.1.90'
      normalizeArrayContentDelta turns a finite number into its decimal string
        actual: false
      

Tests Added Or Updated

  • tests/unit/openai-numeric-delta-content.test.ts: (1) a stream through createSSEStream in passthrough mode with string and numeric deltas, including a 0, concatenates to AB7.1.90 and every forwarded content is a string; (2) normalizeArrayContentDelta converts 7 and 0, leaves NaN and plain strings alone.

Coverage Notes

  • Covers the shared normalizer and the passthrough path (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

  • Only the files the failing test proves need changing are touched (open-sse/utils/arrayContentDelta.ts, the test and the changelog fragment)
  • No test was weakened or deleted to make the suite pass

Validation

  • Change type: other (SSE passthrough)
  • Focused tests and category gates from the golden path: the tests that use createSSEStream, arrayContentDelta or responseSanitizer pass (438); check:ai-attribution and check:changelog-integrity pass; eslint is clean on the touched files
  • npm run lint (the repository-wide run is left to CI). check:file-size reports the same five violations on the base and on this branch; none of those files is touched here.

Reviewer Notes

…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.
pacocartones and others added 2 commits October 14, 2026 20:06
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
@diegosouzapw
diegosouzapw merged commit 91e665b into cheaper-inference:release/v3.8.52 Oct 15, 2026
47 of 60 checks passed
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.

fix(providers): Cloudflare numeric SSE content loses digits

2 participants