Save transcript to file before function call is performed#17996
Save transcript to file before function call is performed#17996laurentsimon wants to merge 3 commits intogoogle-gemini:mainfrom
Conversation
Summary of ChangesHello @laurentsimon, 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 the chat transcript might not be fully available to 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request updates the chat recording logic to save the transcript to a file even when the model's response contains only thoughts and no text, which is useful for BeforeTool hooks. The changes involve adding a hasThoughts flag that is checked before recording the message.
My main feedback is regarding a redundant check for thoughts being added, which could be consolidated with an existing check to improve efficiency and maintainability. Otherwise, the logic seems correct and addresses the intended issue.
e8ee17e to
509fb36
Compare
|
Hi there! Thank you for your contribution to Gemini CLI. We really appreciate the time and effort you've put into this pull request. To keep our backlog manageable and ensure we're focusing on current priorities, we are closing pull requests that haven't seen maintainer activity for 30 days. Currently, the team is prioritizing work associated with 🔒 maintainer only or help wanted issues. If you believe this change is still critical, please feel free to comment with updated details. Otherwise, we encourage contributors to focus on open issues labeled as help wanted. Thank you for your understanding! |
|
Fixes #17922 |
yes this change is "critical" |
|
Hi @laurentsimon — just a quick follow-up.
I’m still working with the CLI and keeping this branch up to date with
main. The change has been working well locally and does preserve the
session history when a tool call fails, which was the main issue I
encountered while testing tool integrations.
Whenever you have time, I’d really appreciate your thoughts on whether this
approach aligns with the project’s intended behavior, or if you’d prefer a
different direction for handling transcripts.
Happy to adjust the implementation based on your feedback.
…On Mon, 23 Feb 2026 at 22:50, laurentsimon ***@***.***> wrote:
*laurentsimon* left a comment (google-gemini/gemini-cli#17996)
<#17996 (comment)>
Hi there! Thank you for your contribution to Gemini CLI. We really
appreciate the time and effort you've put into this pull request.
To keep our backlog manageable and ensure we're focusing on current
priorities, we are closing pull requests that haven't seen maintainer
activity for 30 days. Currently, the team is prioritizing work associated
with *🔒 maintainer only* or *help wanted* issues.
If you believe this change is still critical, please feel free to comment
with updated details. Otherwise, we encourage contributors to focus on open
issues labeled as *help wanted*. Thank you for your understanding!
yes this change is "critical"
—
Reply to this email directly, view it on GitHub
<#17996 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BE4BKIVEM5SQNE57VQHD4MT4NMZFNAVCNFSM6AAAAACTPQQCE2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSNBWGEZTGMZYGU>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
|
@theshloksschauhan |
|
Hi @laurentsimon — thanks for the question, and sorry for the confusion
caused by my wording. When I said “my branch/code,” I meant the branch for
this PR (#17996) (i.e., the changes under review here), not a separate
implementation.
So there isn’t another patch to compare against—what I’ve tested locally is
exactly what’s in this PR: flush the transcript to disk before the
tool/function call runs, so a BeforeTool hook can reliably read the latest
transcript state (including in cases where the tool call fails).
If it’d help, I can add clear repro/validation steps to the PR description
to make the behavioral difference explicit.
…On Mon, 23 Feb 2026 at 23:56, laurentsimon ***@***.***> wrote:
*laurentsimon* left a comment (google-gemini/gemini-cli#17996)
<#17996 (comment)>
@theshloksschauhan <https://github.com/theshloksschauhan>
where is your code? How does it differ from this PR?
—
Reply to this email directly, view it on GitHub
<#17996 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BE4BKIQPOAIQQOQQYA4HS634NNA3RAVCNFSM6AAAAACTPQQCE2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSNBWGUYTQMBSHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
This change looks useful, especially for ensuring BeforeTool hooks have access to the latest transcript state. One thing I was thinking about while reading this — currently the flush happens when handling model output (including thoughts). For cases where tool calls are triggered asynchronously, would it make sense to explicitly flush the transcript at the point where a tool call is dispatched as well? That could ensure consistency even when execution paths diverge (e.g., streaming responses vs tool-triggered execution). Happy to explore this further or help test edge cases if useful. Thanks! |
Help greatly appreciated. I'm not super familiar with the codebase so I did the best I could to make it work, but like you say there are likely edge cases this PR does not cover |
|
Hi @laurentsimon — thanks, that makes sense. I’ll take a closer look at the tool dispatch path and how it interacts with transcript persistence, especially in async and streaming scenarios. Initial thought: it might help to explicitly flush the transcript right before tool execution is dispatched, so BeforeTool hooks always see the latest state (including thoughts), even if the execution path diverges. I’ll validate this against:
If it holds, I’ll follow up with a concrete PR + tests shortly. Does this direction align with what you had in mind? |
Makes sense, in particular for thoughts. Tool execution metadata is available in BeforeTool inputs, so having the tool info in the transcript is less critical
That makes sense, yes. Really appreciate the help, thank you for taking the time. |
…esponses Extends the fix in google-gemini#17996: when the model emits a functionCall with no response text and no thoughts, recordMessage was not called, leaving BeforeTool hooks with no gemini entry in the transcript at dispatch time. - Add hasThoughts flag (from google-gemini#17996) to track thought-only responses - Add hasToolCall to flush condition so pure tool calls also trigger a transcript write before tool execution - Add regression test verifying gemini entry is written on pure tool call Fixes the edge case noted in PR google-gemini#17996 discussion.
…esponses Extends the fix in google-gemini#17996: when the model emits a functionCall with no response text and no thoughts, recordMessage was not called, leaving BeforeTool hooks with no gemini entry in the transcript at dispatch time. - Add hasThoughts flag (from google-gemini#17996) to track thought-only responses - Add hasToolCall to flush condition so pure tool calls also trigger a transcript write before tool execution - Add regression test verifying gemini entry is written on pure tool call Fixes the edge case noted in PR google-gemini#17996 discussion.
…esponses Extends the fix in google-gemini#17996: when the model emits a functionCall with no response text and no thoughts, recordMessage was not called, leaving BeforeTool hooks with no gemini entry in the transcript at dispatch time. - Add hasThoughts flag (from google-gemini#17996) to track thought-only responses - Add hasToolCall to flush condition so pure tool calls also trigger a transcript write before tool execution - Add regression test verifying gemini entry is written on pure tool call Fixes the edge case noted in PR google-gemini#17996 discussion.
|
Hi @laurentsimon — I've opened a follow-up PR (#20419) that addresses the remaining edge case. When the model emits a pure functionCall with no text and no thoughts, recordMessage was still not called, so BeforeTool hooks saw no gemini entry at dispatch time. The fix extends the flush condition to responseText || hasThoughts || hasToolCall — a 3-line change in processStreamResponse, no new dependencies. Includes a regression test. Happy to rebase onto your branch if you'd prefer to land both together. |
Great. Let me close this PR then. Thank you! |
Summary
This PR closes #17922.
It flushes transcript to disk to ensure it's available in a
BeforeToolhook.Details
Before this PR, transcript contains:
{ "messages": [ { "type": "user", "content": "analyze code test.py" } ] }After this PR:
{ "messages": [ { "type": "user", "content": "analyze code test.py" }, { "type": "gemini", "content": "I'm calling the function...", "thoughts": [ { "subject": "Initiating Code Exploration", "description": "I'm starting by examining the code located at `test.py`. My immediate plan is to use the `read_file` tool. This will help me acquire the content of the file so I can provide a comprehensive explanation.", } ] } ] }Related Issues
How to Validate
Pre-Merge Checklist