-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/chat save command saves empty conversations with only system context #6121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/chat save command saves empty conversations with only system context #6121
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @trycatchkamal, 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 a bug in the /chat save command where conversations containing only initial system context messages were being saved as checkpoints. The fix refines the saving logic to ensure that only conversations with actual user interaction are saved, preventing storage waste and clutter from meaningless checkpoints. This change aligns the save behavior with the intended purpose of preserving meaningful chat history.
Highlights
- Refined Conversation Saving Logic: The condition for saving a chat conversation has been updated from history.length > 0 to history.length > 2. This change correctly accounts for the two initial system context messages present in every new chat session, ensuring that only conversations with actual user input are considered for saving.
- Prevention of Empty Checkpoints: This fix prevents the /chat save command from creating checkpoints for conversations that consist solely of system context, thus avoiding storage waste and improving the clarity of saved conversation lists.
- Enhanced Test Coverage: The unit tests for chatCommand have been expanded to explicitly cover scenarios where the conversation history is empty or contains only system context messages, verifying that the save command correctly informs the user that no conversation is found to save in these cases.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request aims to prevent saving chat sessions that only contain the initial system context. The implementation correctly identifies this scenario but introduces a critical bug where valid, short conversations (e.g., a single question and answer) would also be prevented from being saved. I've provided a suggestion to refine the logic to correctly distinguish between system-only context and actual short conversations, preventing potential data loss for users.
58a7bb3 to
44d2125
Compare
44d2125 to
b11ccc7
Compare
| it('should inform if conversation history is empty or only contains system context', async () => { | ||
| mockGetHistory.mockReturnValue([]); | ||
| const result = await saveCommand?.action?.(mockContext, tag); | ||
| let result = await saveCommand?.action?.(mockContext, tag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rather than reusing the same variable can you create new ones. result1, result2, etc
jacob314
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| const history = chat.getHistory(); | ||
| if (history.length > 0) { | ||
| if (history.length > 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as a follow up, it would it be more robust if chat had a method that determined whether the history had any messages that were actually from the user? It is slightly paranoid but I do worry this constant might change from 2 to some other value in the future if we tweaked how the initial conversation is setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jacob314 Thanks for the suggestion.
I agree that relying on a hardcoded constant for the minimum history length is fragile, especially if the initial conversation setup changes in the future. I think moving this logic into some function that checks for actual user messages would make the code more robust and maintainable.
It also makes sense to consider refactoring the resume command to use similar logic for consistency. I will take this up and propose a separate refactor PR, making future changes easier to manage.
…l/gemini-cli into bug/6119-chat-save-nonempty
…with only system context (google-gemini#6121)
…google-gemini#6121) Co-authored-by: Jacob Richman <[email protected]>
… (#6121) Co-authored-by: Jacob Richman <[email protected]>
…google-gemini#6121) Co-authored-by: Jacob Richman <[email protected]>
…google-gemini#6121) Co-authored-by: Jacob Richman <[email protected]>
…google-gemini#6121) Co-authored-by: Jacob Richman <[email protected]>

TLDR
Fixed a bug in the
/chat savecommand where conversations containing only system context messages (initial environment info and model acknowledgment) were being saved as checkpoints. The fix ensures that only conversations with actual user interaction beyond the initial system context are saved, preventing storage waste and clutter from meaningless checkpoints.Dive Deeper
The issue was that the
/chat savecommand was saving conversation checkpoints even when there were no actual user messages, only the initial system context messages. This happened because:System Context Always Present: Every new chat session automatically includes 2 initial messages:
Insufficient Filtering: The original logic checked
history.length > 2, but this wasn't sufficient to distinguish between:Storage Waste: Users could accidentally save "conversations" that contained no meaningful content, wasting storage and cluttering the checkpoint list.
The fix implements proper filtering logic that:
This aligns with the existing logic in the
/chat resumecommand, which already filters out system messages for display purposes.Reviewer Test Plan
/chat save test-emptyimmediately without any user input/chat save test-real/chat listto see saved checkpoints/chat resume test-realto verify the conversation loads with actual content/chat deleteTesting Matrix
Linked issues / bugs
Addition information