-
Notifications
You must be signed in to change notification settings - Fork 10.6k
refactor(sessions): move session summary generation to startup #14691
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
Conversation
Summary of ChangesHello @jackwotherspoon, 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 significantly refactors the session summary generation mechanism within the CLI. The primary goal is to enhance user experience by making application exit instantaneous, achieved by deferring summary creation to a background process during the subsequent startup. Additionally, it ensures that session summaries are accurate and readily available when users explicitly request to view their session history, while also optimizing resource usage by intelligently deciding which sessions warrant a summary. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This is a great refactoring that significantly improves the user experience by moving the blocking session summary generation to a background task on startup. The changes are well-structured, and the logic for identifying sessions that need a summary is sound, including the filename-based sorting and the message count threshold. The addition of summary generation to --list-sessions is also a thoughtful touch to ensure data is up-to-date. I have one suggestion to improve the robustness of the file handling logic to make it more resilient to potential race conditions.
|
Size Change: +2.97 kB (+0.01%) Total Size: 21.6 MB
ℹ️ View Unchanged
|
|
This looks like a solid refactor that will improve the user experience by making the CLI exit immediately. I have a few suggestions to improve maintainability and performance. Review Summary
Detailed Comments
|
Yes this is intended. Used to use mimetypes to look at most recently "edited" session but this was pointless as old sessions should already be summarized. If I resumed an old session, i don't want the next startup to look for a summary on that file. So I removed the pain of searching mimetypes to rely on file names which are by date and time. Also didn't want Gemini CLI to repeatedly go back and summarize old sessions. Users could have a large amount of sessions pre-dating this summarization feature and always going back and summarizing 1 potentially really old session is strange behavior. Just looking at previous session makes this behavior more clear and faster by only looking at most recent created session and will start from the feature being rolled out. |
|
In const summaryGeneratedRef = useRef(false);
useEffect(() => {
if (summaryGeneratedRef.current) return;
summaryGeneratedRef.current = true;
// ... generateSummary logic
}, [config]); |
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.
Done 👍 |
|
/patch preview |
|
✅ Patch workflow(s) dispatched successfully! 📋 Details:
🔗 Track Progress: |
|
🚀 Patch PR Created! 📋 Patch Details:
📝 Next Steps:
🔗 Track Progress: |
|
🚀 Patch Release Started! 📋 Release Details:
⏳ Status: The patch release is now running. You'll receive another update when it completes. 🔗 Track Progress: |
|
✅ Patch Release Complete! 📦 Release Details:
🎉 Status: Your patch has been successfully released and published to npm! 📝 What's Available:
🔗 Links: |
…neration to startup (google-gemini#14691)

Summary
Optimizes session summary generation by moving it from exit-time (blocking) to startup-time (non-blocking), eliminating the potential max of a 5 second delay when closing the CLI.
Previously, when a user exited the CLI, the application would block while making an API call to generate a summary for the current session. This caused a noticeable delay before the terminal returned to the user. Now, summary generation happens in the background on the next startup, making exit instant.
Also added a check that only generates a summary if more than 1 user messages exist in the session. This way non-interactive mode sessions are not summarized as well as single message sessions where the initial prompt most likely captures the overall intent of the user, saving model calls.
Details
Move summary generation from exit to startup
await generateAndSaveSummary(config)call from the cleanup handler inAppContainer.tsxgenerateSummary(config).catch(...)call in the startupuseEffectAdd summary generation to
--list-sessionsgemini --list-sessions, the CLI now checks if the most recent session needs a summary and generates one if soUse filename-based sorting instead of mtime
mtime) to sorting by filenamesession-2024-01-15T10-30-abc123.json)Skip single message sessions (1+ user message threshold)
Code cleanup
dirExistsvariable ingetPreviousSessiongenerateAndSaveFromCurrentSessionfunction (dead code after refactor)fsto asyncfs/promisesfor non-blocking I/OFiles Changed
packages/core/src/services/sessionSummaryUtils.tsgetPreviousSessionto use filename sorting and 5-message threshold; simplifiedgenerateSummaryfor fire-and-forget usagepackages/core/src/services/sessionSummaryUtils.test.tspackages/cli/src/ui/AppContainer.tsxpackages/cli/src/utils/sessions.tsgenerateSummarycall before listing sessionspackages/cli/src/utils/sessions.test.tsgenerateSummaryTesting
Related Issues
Related to #8476
How to Validate
Pre-Merge Checklist