fix(core): cap chat history at 1000 items to prevent unbounded memory growth#24969
fix(core): cap chat history at 1000 items to prevent unbounded memory growth#24969spencer426 wants to merge 1 commit intomainfrom
Conversation
Summary of ChangesHello, 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 significant memory leak identified in the chat recording system. By enforcing a maximum capacity of 1000 items on the chat history, the changes ensure that memory consumption remains stable over long sessions, preventing potential performance degradation and crashes associated with unbounded data growth. 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. Footnotes
|
|
Hi @spencer426, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
|
Size Change: +307 B (0%) Total Size: 34 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request introduces a hard limit of 1000 items for chat history and conversation messages in both the CLI and core packages to prevent unbounded memory and file growth. Feedback suggests simplifying the array truncation logic using a negative index in slice(-1000) for better readability and consistency.
| if (newHistory.length > 1000) { | ||
| return newHistory.slice(newHistory.length - 1000); | ||
| } |
There was a problem hiding this comment.
The hardcoded limit of 1000 should be kept as a literal value here rather than importing a shared constant to ensure the test/logic remains self-contained. Additionally, ensure that the truncation logic is applied to loadHistory and initial state to prevent unbounded memory growth. Note: when truncating strings, ensure you are not splitting multi-byte Unicode characters.
| if (newHistory.length > 1000) { | |
| return newHistory.slice(newHistory.length - 1000); | |
| } | |
| if (newHistory.length > 1000) { | |
| return newHistory.slice(-1000); | |
| } |
References
- In tests, prefer using hardcoded literal values instead of importing constants to ensure tests are self-contained and less brittle.
- When truncating strings that may contain multi-byte Unicode characters, use methods that operate on grapheme clusters to prevent character splitting.
Summary
Addresses a memory leak caused by unbounded growth of the chat history and recording service by capping the history array at 1000 items.
Details
ChatRecordingServicewas holding ~350MB on its own because thehistoryManagerarray grew indefinitely without any truncation mechanism. The fix enforces a hard limit of 1000 items via an LRU-style slice inuseHistoryManager.tsandchatRecordingService.ts.This is 2 of 4 atomic PRs split from the monolithic memory leak PR #24963.
Related Issues
Pre-Merge Checklist