fix(core): preserve structured thoughts during session resume#24106
fix(core): preserve structured thoughts during session resume#24106X9VoiD wants to merge 1 commit intogoogle-gemini:mainfrom
Conversation
b1185a2 to
ccbb8b8
Compare
This change ensures that AI thinking blocks are correctly handled during session serialization and deserialization, preventing string contamination like '[Thought: true]'. By removing unnecessary transformations in the API conversion layer, we maintain the structured 'thought: true' property, which is supported by the CountToken and other generation APIs. Verified by running Gemini CLI with real models and added a new integration test to prevent regressions. Fixes google-gemini#23046 Partial revert of fef89f5 (google-gemini#6859)
ccbb8b8 to
6567975
Compare
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where structured thought data was being leaked as literal text during session resumption. By removing an outdated conversion workaround and updating how thoughts are rendered, the system now correctly handles structured thought data, ensuring clean output and preventing data contamination in API requests. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request removes the logic that previously converted thought parts into text parts for API compatibility in converter.ts and its associated tests. It also updates partToString in partUtils.ts to handle cases where part.thought is a boolean, ensuring that thoughts are correctly identified and formatted without being mutated into string text during session resume or rewind operations. A new integration test has been added to verify this behavior. One issue was identified where a boolean check was too broad and could incorrectly handle false values.
I am having trouble creating individual review comments. Click here to see my feedback.
packages/core/src/utils/partUtils.ts (46)
The condition typeof part.thought === 'boolean' is too broad. It will incorrectly handle the case where part.thought is false, causing a non-thought part to be displayed as [Thought]. This is misleading and inconsistent with other logic (e.g., getResponseText) which would treat such a part as regular text.
The check should be more specific to only identify parts that are explicitly marked as thoughts.
if (part.thought === true) {
Summary
Fix
[Thought: true]leaking as literal text after session resume (#23046). ThetoPart()converter inconverter.ts(from #6859) was unconditionally stringifying{thought: true}parts for all API calls, not just CountToken. I verified the CountToken API accepts the samethought: trueschema as GenerateContent, so the workaround is removed entirely (Gemini CLI still works after resume even without the workaround for CountToken API).This is a simpler approach than #23048 (filter thoughts out) and #23526 (flag-based conditional), as it trusts both APIs with structured thought data.
Details
converter.ts: RemovedtoPart()logic that appended\n[Thought: true]to text partspartUtils.ts: FixedpartToStringverbose output to render[Thought]cleanlysessionUtils.test.ts: Added integration test covering the full resume pipeline (ConversationRecord→convertSessionToClientHistory()→toContents()) to prevent regressionPartial revert of commit
fef89f5(#6859).Related Issues
Fixes #23046 | Related: #23048, #23526
How to Validate
npm run test -w @google/gemini-cli-core -- src/utils/sessionUtils.test.tsThe new integration test catches the regression precisely. When the fix is reverted, it fails with:
Manual: Resume a Code Assist (OAuth) session that had thinking blocks. Before:
[Thought: true]appears in responses and worsens each turn. After: clean output. Validated on real models.Pre-Merge Checklist