google-gemini/gemini-cli
Turn drops non-thought parts when a chunk's first part is a thought
Summary
Context: The
Turnclass inpackages/core/src/core/turn.tsprocesses streaming responses from the Gemini API, yielding events for thoughts, content, function calls, and citations.Bug: When a response chunk’s first part contains a thought, all other parts in that chunk (text content, function calls, citations) are silently discarded.
Actual vs. expected: The code skips processing remaining parts after encountering a thought, whereas it should process all parts while filtering out the thought.
Impact: Users lose response content, function calls fail to execute, citations are not displayed, and finish reasons are not processed when they arrive in the same chunk as a thought.
Code with bug
Example
Given a Gemini response chunk that mixes a thought with text and other data:
Expected behavior:
Yield Thought event
Yield Content event with “I will help you with that.”
Yield ToolCallRequest for ReadFile
Collect the citation and later emit it on finish
Yield Finished event with reason STOP
Actual behavior (bug):
Yields Thought event, then continues to next chunk
Content, function call, citations, and finish reason from this chunk are not processed
Recommended fix
Remove the
continueso other parts are processed after yielding the Thought.Filter out thought parts when extracting text (or update the shared text-extraction util to do so):
Alternatively, update getResponseText() in packages/core/src/utils/partUtils.ts to filter thought parts: