fix(cloud): chat/completions streaming conformance — finish_reason mapping + stream_options.include_usage (#12871 items 2+3) - #12945
Conversation
…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>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
lalalune
left a comment
There was a problem hiding this comment.
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.
|
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. |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Closes item 2 of #12871.
[cloud-money](API conformance, no money impact).Bug: streaming leaked raw AI-SDK finish reasons (
content-filterhyphen,error,unknown) into the OpenAIfinish_reasonfield; the non-streaming path maps them correctly, so the two disagreed.Fix:
toOpenAiFinishReasonnormalizes 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).