Skip to content

feat(sessions): Introduce core ChatRecordingService for automatic conversation saving#5221

Merged
jacob314 merged 9 commits intogoogle-gemini:mainfrom
Piebald-AI:introduce-chatrecordingservice-073025
Aug 19, 2025
Merged

feat(sessions): Introduce core ChatRecordingService for automatic conversation saving#5221
jacob314 merged 9 commits intogoogle-gemini:mainfrom
Piebald-AI:introduce-chatrecordingservice-073025

Conversation

@bl-ue
Copy link
Copy Markdown
Contributor

@bl-ue bl-ue commented Jul 30, 2025

This PR is the first in a series of 9 PRs that implement automatic chat recording and resuming in both interactive and non-interactive modes, with command line flags for non-interactive resuming and session management, and an interactive session browser.

PR #4401 was the original monolithic PR, which implemented this feature from the ground up. It's too large to merge as-is, however, and so it was broken up into 9 smaller PRs, of which this PR is the first.

Please see #4401's description for the full context of this PR. The original monolithic PR's description contains a detailed analysis of the entire system, with an example of the recording JSON, 30+ linked issues, and a demo video.

@bl-ue bl-ue requested a review from a team as a code owner July 30, 2025 18:56
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a 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 @bl-ue, 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 introduces a foundational new service for persistent storage of chat conversations. It enables automatic recording of detailed interaction data, including messages, tool usage, and model thoughts, ensuring that chat sessions can be saved and potentially resumed. This is a significant step towards enhancing session management and data retention capabilities.

Highlights

  • New Service Introduction: Introduced a new ChatRecordingService responsible for automatically recording and persisting chat conversations to disk. This service captures user and assistant messages, tool calls, token usage statistics, and assistant thoughts.
  • Conversation Persistence: The ChatRecordingService stores conversation sessions as JSON files in a project-specific temporary directory (~/.gemini/tmp/<project_hash>/chats/). It supports both creating new sessions and resuming existing ones.
  • Configurability for Sessions: The Config class has been updated to allow the sessionId to be mutable, enabling the ChatRecordingService to update or set the session ID dynamically, which is crucial for resuming conversations.
  • Core Export: The new ChatRecordingService is now exported from the core package's index.ts, making it available for use by other parts of the application.
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 or fill out our survey to provide feedback.

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

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a 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 introduces a new ChatRecordingService for saving conversations, which is a great addition. The implementation is mostly solid, but I've found a few issues related to file management and error handling that could lead to silent failures or data loss. I've also pointed out a state management issue where the session ID is not consistently updated. Please see my detailed comments for suggestions on how to address these points.

Comment thread packages/core/src/config/config.ts
Comment thread packages/core/src/config/config.ts
Comment thread packages/core/src/services/chatRecordingService.ts
Comment thread packages/core/src/services/chatRecordingService.ts Outdated
@gusbemacbe
Copy link
Copy Markdown

Good afternoon, @bl-ue!

I switched to this branch and could not resume the last chat session. I reviewed the .gemini folder and I noticed that I lost the session.

@bl-ue
Copy link
Copy Markdown
Contributor Author

bl-ue commented Jul 30, 2025

Hi @gusbemacbe! Yes, I'm sorry about that. The maintainers requested that I break this PR up into 9 smaller PRs, so this PR is the first of 9 that implement automatic chat saving, and it only implements backend functionality. Until these 9 PRs are merged, stay on the #4401 branch if you want to save your chats.

@gusbemacbe
Copy link
Copy Markdown

Good evening, @bl-ue!

Thank you for your advice and tip!

Is it possible that you will keep the auto-record-chat-history-071725 branch updated? Because the gemini-cli developers are updating daily by fixing the bugs and adding new features.

@bl-ue
Copy link
Copy Markdown
Contributor Author

bl-ue commented Jul 31, 2025

@gusbemacbe Of course! I'm really glad that you're testing it! I'll keep updated.

Copy link
Copy Markdown
Collaborator

@NTaylorMullen NTaylorMullen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll also want to write some tests for the chatRecordingService. Should be easy though if you let Gemini CLI run with it :)

Comment thread packages/core/src/services/chatRecordingService.ts
Comment thread packages/core/src/services/chatRecordingService.ts Outdated
Comment thread packages/core/src/services/chatRecordingService.ts
Comment thread packages/core/src/services/chatRecordingService.ts Outdated
@bl-ue bl-ue requested a review from NTaylorMullen August 1, 2025 23:59
@bl-ue
Copy link
Copy Markdown
Contributor Author

bl-ue commented Aug 10, 2025

Hi @NTaylorMullen! You probably have tons of PRs but I don't want this one to get lost in the shuffle. Any chance you can look at this one this week?

@NTaylorMullen
Copy link
Copy Markdown
Collaborator

Hi @NTaylorMullen! You probably have tons of PRs but I don't want this one to get lost in the shuffle. Any chance you can look at this one this week?

Thank you for mentioning me directly! Yes I get hundreds per day lol. Looking now!

Copy link
Copy Markdown
Collaborator

@NTaylorMullen NTaylorMullen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, PR 1, getting in!

@bl-ue to help make sure I don't miss things like this (so sorry about the delay) feel free to shoot me an email (it's ntaylormullen (my GH handle 😄 ) at google.com and I can send you an invite to a chat space which should be easier to poke me / the team at.

Comment thread packages/core/src/services/chatRecordingService.ts
@NTaylorMullen
Copy link
Copy Markdown
Collaborator

Ah looks like you might have a linting error. You should be able to fix by doing npm run format and pushing the branch

@bl-ue bl-ue force-pushed the introduce-chatrecordingservice-073025 branch from 23e45a0 to 1173b62 Compare August 18, 2025 00:19
@bl-ue
Copy link
Copy Markdown
Contributor Author

bl-ue commented Aug 18, 2025

Hi @NTaylorMullen! Okay, sounds great. I resolved the linting error, so it should be ready. I also sent you an email with a subject of "PR #5221 on Gemini CLI".

@NTaylorMullen
Copy link
Copy Markdown
Collaborator

@bl-ue looks like you may have a few test failures!

auto-merge was automatically disabled August 18, 2025 15:05

Head branch was pushed to by a user without write access

@bl-ue
Copy link
Copy Markdown
Contributor Author

bl-ue commented Aug 18, 2025

Hi @NTaylorMullen, okay, fixed. The mkdirSync call in ChatRecordingService.initialize was getting through to the FS directly because it wasn't being mocked for all the ChatRecordingService tests. It succeeded on Windows and not macOS and Linux because /home/project/... was getting converted to C:\home\project\... and Windows has looser permissions than macOS/Linux around creating items in the root directory (C:\ and /), so the mkdir call was succeeding on Windows but not the other platforms. We fixed it by mocking mkdirSync for the entire ChatRecordingService test suite. The entire test suite now passes on all three platforms.

@jacob314 jacob314 enabled auto-merge August 19, 2025 00:33
@jacob314 jacob314 added this pull request to the merge queue Aug 19, 2025
Merged via the queue into google-gemini:main with commit 36ea986 Aug 19, 2025
18 checks passed
@bl-ue bl-ue deleted the introduce-chatrecordingservice-073025 branch August 19, 2025 00:52
thacio added a commit to thacio/auditaria that referenced this pull request Aug 19, 2025
agarwalravikant pushed a commit to agarwalravikant/gemini-cli that referenced this pull request Aug 19, 2025
JeongJaeSoon pushed a commit to JeongJaeSoon/gemini-cli that referenced this pull request Aug 21, 2025
@bl-ue
Copy link
Copy Markdown
Contributor Author

bl-ue commented Aug 21, 2025

Next PR: #6721

bl-ue added a commit to Piebald-AI/gemini-cli that referenced this pull request Aug 29, 2025
It was made mutable in google-gemini#5221 as part of this google-gemini#4401 branch, but that was too
early, and so was reverted in google-gemini#7219.  We need it mutable as part of the setup
but we'll not bring it to main until it's needed.
involvex pushed a commit to involvex/gemini-cli that referenced this pull request Sep 11, 2025
reconsumeralization pushed a commit to reconsumeralization/gemini-cli that referenced this pull request Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants