Add automatic session saving with list and resume support. (feature/2174)#2419
Add automatic session saving with list and resume support. (feature/2174)#2419saheersk wants to merge 15 commits intogoogle-gemini:mainfrom
Conversation
- Automatically checkpoints conversation history after each user+model turn - Saves checkpoints in `.gemini/tmp/` with unique identifiers (timestamp/UUID) - Limits total checkpoints to avoid excessive disk usage (configurable) - Adds `chat list-auto` to display available saved sessions - Adds `chat resume-auto <session_id>` to resume a specific session - Ensures last session is saved on graceful CLI exit
|
/gemini summary |
Summary of ChangesThis pull request significantly enhances the user experience by introducing automatic conversation session saving and resumption capabilities to the Gemini CLI. It ensures that chat history is persistently stored, can be easily listed and reloaded, and is preserved even upon unexpected exits, making the CLI more robust and user-friendly. Highlights
Changelog
Activity
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces automatic session saving and resumption. There are a few critical and high-severity issues that need to be addressed:
- A critical issue with using an asynchronous operation in a synchronous
process.on('exit')handler, which could lead to data loss. - A high-severity bug where the session cleanup logic targets the wrong directory, preventing old sessions from being deleted.
- A high-severity bug in session listing where sorting by a localized date string will lead to incorrect ordering.
- Replace 'exit' event with 'beforeExit' for async session saving - Add signal handlers for SIGINT, SIGTERM, SIGHUP, SIGQUIT - Add crash protection for uncaught exceptions/rejections - Implement sync fallback for immediate exits - Prevent duplicate saves with exit state tracking
- Sort sessions using numeric mtimeMs values for reliable chronological order - Fix locale-dependent string sorting that caused incorrect session ordering
c923894 to
3c2607d
Compare
|
Hi @umairidris , I've fixed the issue by replacing the unreliable localized timestamp sorting with a proper sort using mtimeMs for accurate chronological order. Also addressed the async saveSession call by using beforeExit and signal handlers for graceful shutdown. Could you please run the review again when you get a chance? Let me know if anything needs clarification. Thanks |
|
@sethtroisi could you please review this one? |
|
This is so close to auto saving and resuming chats, only the auto resume is missing. Would you consider adding a startup parameter to gemini so it will resume the last chat you had? (I assume the auto-id with the highest number, if available) |
|
@saheersk are you still interested in pursuing this PR? It looks like @sethtroisi comments still need to be addressed and there are several merge conflicts that will also need to be resolved. |
|
Hi @allenhutchison, |
- Replace undefined input with empty string for cleaner type safety - Remove process.exit calls in chat resume/list commands, use empty input fallback - Add TODO comments for future chat processor refactoring - Simplify stdin concatenation logic
|
Hey @allenhutchison @sethtroisi, I’ve added all the new changes and resolved the merge conflicts. Could you please re-review when you get a chance?. Thanks. |
- Add findSession() utility to session.ts for centralized session lookup
|
Hey @sethtroisi, I’ve resolved all the issues and pushed the changes. Please validate when you get a chance. |
|
hey @allenhutchison, #5221 is already merged. Is there anything i can do further. |
|
Probably not on this PR. Sorry about that. We're trying to get better at staying ahead of the incoming PRs. I'll close this one since the other one is merged in now. |
.gemini/tmp/with unique identifiers (timestamp/UUID)chat list-autoto display available saved sessionschat resume-auto <session_id>to resume a specific sessionTLDR
This PR adds automatic session saving and resumption to the Gemini CLI. After every complete chat turn (user input + model response), the conversation history is checkpointed to disk. It also introduces new sub-commands to list and resume saved sessions.
This makes the user experience significantly smoother by removing the need to manually save with /chat save and ensures continuity between sessions even after restarting the CLI.
Dive Deeper
What's New:
Reviewer Test Plan
To verify that everything works correctly, please follow these steps:
Start a chat session and interact with the CLI.
Verify that a new checkpoint is created in .gemini/tmp/ after each complete user + model turn.
Run /chat list-auto
Run /chat resume-auto <session_id> with one of the listed IDs
Test graceful exit using CTRL+C or typing exit
Optionally, test deletion or limit behavior by generating more than N checkpoints and verifying older ones are cleaned up.
Testing Matrix
Other platforms have not been tested directly, but the feature is expected to work cross-platform.
Contributions or confirmations from users on Linux and Windows are welcome
Linked issues / bugs
#2174