Skip to content

fix(openai): keep streaming when chunks include usage - #13418

Open
cestercian wants to merge 1 commit into
continuedev:mainfrom
cestercian:cursor/fix-openai-usage-stream-ca5c
Open

cestercian wants to merge 1 commit into
continuedev:mainfrom
cestercian:cursor/fix-openai-usage-stream-ca5c

Conversation

@cestercian

Copy link
Copy Markdown

Description

Gemini's OpenAI compatible endpoint sends usage on every SSE chunk, right next to the content and tool call deltas. The stream handling treated any chunk with usage as the final one, so text got dropped and tool calls never showed up.

Now the deltas keep streaming when usage is present, the latest usage wins, and unknown extras like extra_content are passed through instead of breaking things. Normal OpenAI behavior (usage only on the last empty-choices chunk) is unchanged.

Fixes #13417

Checklist

  • I've read the contributing guide
  • The relevant docs, if any, have been updated or created
  • The relevant tests, if any, have been updated or created

Tests

  • packages/openai-adapters/src/test/openai-gemini-usage.vitest.ts: Gemini style chunks with usage on every chunk plus content and tool call deltas
  • core/llm/openaiTypeConverters.gemini.vitest.ts: chunk conversion keeps content, tool calls and usage together
  • openai-adapters vitest suite passes, tsc clean in core and openai-adapters, eslint and prettier clean on touched files

Gemini's OpenAI-compat endpoint sends usage on every SSE chunk, next to content and tool call deltas. The adapter treated any usage payload as the final chunk and dropped the rest, so chat text and tool calls never showed up. Keep yielding those deltas, pass through extra fields like extra_content, and let the latest usage win.
@cestercian
cestercian requested a review from a team as a code owner October 24, 2026 15:29
@cestercian
cestercian requested review from sestinj and removed request for a team October 24, 2026 15:29
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@cestercian

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

This branch has not been deployed

No deployments
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(openai): Stream parser crashes on extra unknown JSON fields (extra_content / usage payload) in CLI (cn) & IDE

1 participant