Skip to content

fix(google-genai): keep the finish reason of a streamed response that has no content - #2650

Merged
Luca Forstner (lforst) merged 3 commits into
braintrustdata:mainfrom
pcbeingused333:fix/google-genai-stream-finish-reason-no-content
Oct 27, 2026
Merged

Luca Forstner (lforst) merged 3 commits into
braintrustdata:mainfrom
pcbeingused333:fix/google-genai-stream-finish-reason-no-content

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

When a Gemini stream ends with a chunk that has no content, for example finishReason: "SAFETY", PROHIBITED_CONTENT, or MAX_TOKENS spent on thinking, aggregateGenerateContentChunks dropped the candidates: it only wrote them when it had collected at least one part. The span output then held only usageMetadata, with no finish reason or safety ratings.

The candidates of the last chunk are now always logged. content is included only when parts were collected, and a candidate with nothing to log is skipped. Responses with content produce the same output as before.

Tests: keeps the finish reason of a stream that ends without content streams one chunk with finishReason: "SAFETY", safety ratings and usage and checks the logged output; it fails on main and passes here, along with the rest of google-genai-plugin.test.ts. The recorded e2e streams all end with content, so their snapshots are unaffected. Adds a patch changeset.

This change was made with Claude Code.

🤖 Generated with Claude Code

🤖 Generated with Claude Code

@lforst

Copy link
Copy Markdown
Member

Thanks for reporting! <3

@lforst
Luca Forstner (lforst) merged commit 7830fce into braintrustdata:main Oct 27, 2026
56 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.

2 participants