fix(core,cli): improve terminal buffer memory management and format Windows diagnostic paths - #29380
Conversation
…indows diagnostic paths
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 introduces critical memory management and stability improvements for terminal execution within the core and CLI packages. By optimizing buffer sizing, streamlining serialization processes, and ensuring rigorous cleanup of PTY and child process resources, the changes significantly reduce the risk of memory leaks and performance degradation during long-running shell operations. Additionally, it addresses minor UI formatting issues to improve the readability of diagnostic file paths on Windows. 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 the 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 counterproductive. 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
|
|
📊 PR Size: size/L
|
There was a problem hiding this comment.
Code Review
This pull request addresses memory leaks and excessive V8 heap growth during shell execution. Key changes include reducing the scrollback limit, releasing intermediate closure buffers, properly cleaning up active PTYs and event listeners on exit, and updating serializeTerminalToObject to optionally omit foreground and background colors. Additionally, file paths in bug commands are now wrapped in backticks to prevent Markdown escaping on Windows. The review feedback points out a redundant loop in shellExecutionService.ts that manually clears fg and bg colors when showColor is disabled, as this is already handled internally by serializeTerminalToObject when passing the includeColor parameter. Removing this loop will avoid unnecessary O(N*M) traversals and improve rendering efficiency.
…r token coalescing
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces memory optimizations, robust cleanup mechanisms, and path formatting fixes. It wraps Windows file paths in backticks within the bug and memory commands to prevent Markdown backslash escaping. In the core package, it reduces the terminal scrollback limit to prevent excessive V8 heap growth, optimizes terminal serialization by allowing color omission, ensures proper disposal of event listeners and active PTYs (including a thorough cleanup in resetForTest), and releases intermediate closure buffers to prevent heap retention. As there are no review comments, I have no additional feedback to provide.
Optimizes memory usage during PTY shell execution and headless terminal buffer serialization in
ShellExecutionServiceandterminalSerializer, and improves Markdown formatting of Windows file paths in/bugand/bug-memorydiagnostic messages.Details
SCROLLBACK_LIMITto50,000lines per headless terminal instance and enforces aMAX_CHILD_PROCESS_BUFFER_SIZEbyte cap insidegetFullBufferTextusing sliding window truncation (truncateMiddle).includeColorparameter toserializeTerminalToObjectto skip redundant RGB/palette hex string conversions when color output is disabled, and updatesrenderFnto clear color properties in-place without allocating duplicate arrays via.map().onAbortDuringDrainlisteners fromAbortSignalupon normal process exit to avoid listener accumulation across repeated command executions.outputandsniffChunksclosure buffers and cancels pendingrenderTimeouttimers during process finalization.ShellExecutionService.resetForTest()to properly tear down active PTY processes, child processes, and background log streams./bugand/bug-memoryin inline code backticks so backslashes (e.g.,C:\Users\ASUS\.gemini\...) are preserved accurately by Markdown renderers.includeColor = falseserialization,AbortSignallistener cleanup on normal exit,resetForTest()resource teardown, and Windows path backtick formatting.Related Issues
GH-27557
How to Validate
ShellExecutionService,terminalSerializer,bugCommand, andbugMemoryCommand:Pre-Merge Checklist