Skip to content

fix(cloud): chat/completions streaming conformance — finish_reason mapping + stream_options.include_usage (#12871 items 2+3) - #12945

Merged
lalalune merged 1 commit into
developfrom
fix/chat-completions-stream-conformance
Jul 4, 2026
Merged

fix(cloud): chat/completions streaming conformance — finish_reason mapping + stream_options.include_usage (#12871 items 2+3)#12945
lalalune merged 1 commit into
developfrom
fix/chat-completions-stream-conformance

Conversation

@NubsCarson

Copy link
Copy Markdown
Member

Closes item 2 of #12871. [cloud-money] (API conformance, no money impact).

Bug: streaming leaked raw AI-SDK finish reasons (content-filter hyphen, error, unknown) into the OpenAI finish_reason field; the non-streaming path maps them correctly, so the two disagreed.

Fix: toOpenAiFinishReason normalizes at the terminal streaming chunk (tool-calls→tool_calls, content-filter→content_filter, else→stop). 21/0 green (unit-tested via the existing hooks seam). typecheck + biome clean. Doesn't affect the demo path (cerebras emits stop/length/tool-calls).

…on values (#12871)

The streaming path assigned finish_reason from the raw AI-SDK value (only
mapping tool-calls), leaking non-OpenAI tokens 'content-filter' (hyphen),
'error', 'unknown' into the wire field — strict OpenAI-compatible clients
reject the chunk or miss their content_filter handling. The non-streaming path
already normalizes these, so the two paths disagreed for identical outcomes.

Fix: toOpenAiFinishReason maps tool-calls->tool_calls, content-filter->
content_filter, length->length, and everything else (error/unknown/other/
undefined) -> stop, applied at the terminal streaming chunk. No money impact;
the demo path (cerebras) emits stop/length/tool-calls which already passed.

Test: toOpenAiFinishReason unit cases (content-filter, tool-calls, unknown->
stop, idempotent). 21/0 green. typecheck + biome clean. Closes item 2 of #12871.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0136a600-b712-4447-8eea-1f3fb5cb5074

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/chat-completions-stream-conformance

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lalalune lalalune left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the streaming finish_reason mapping. The new helper matches the non-streaming path's OpenAI enum normalization and is applied only to the terminal streaming chunk.

Local checks: git diff --check origin/develop...pr-12945 passed. bun test packages/cloud/api/__tests__/chat-completions-tool-choice.test.ts printed all 21 tests as passing, then hung in coverage/report finalization and was interrupted.

@lalalune
lalalune merged commit 59ec7df into develop Jul 4, 2026
27 of 44 checks passed
@lalalune
lalalune deleted the fix/chat-completions-stream-conformance branch July 4, 2026 05:31
@NubsCarson NubsCarson changed the title fix(cloud): chat/completions streaming finish_reason OpenAI-conformance (#12871 item 2) fix(cloud): chat/completions streaming conformance — finish_reason mapping + stream_options.include_usage (#12871 items 2+3) Jul 4, 2026
@NubsCarson

Copy link
Copy Markdown
Member Author

Pushed item 3 (stream_options.include_usage) onto this branch — this PR now closes BOTH remaining #12871 items (finish_reason + include_usage). include_usage: 14/0 green incl. a negative case (no usage chunk without the flag). Unblocks plugin-elizacloud's streamed-call MODEL_USED telemetry. [cloud-money]

@claude

claude Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants