Skip to content

perf(cli): truncate large debug logs and limit message history#18663

Merged
mattKorwel merged 5 commits intomainfrom
fix/debug-log-memory
Feb 11, 2026
Merged

perf(cli): truncate large debug logs and limit message history#18663
mattKorwel merged 5 commits intomainfrom
fix/debug-log-memory

Conversation

@mattKorwel
Copy link
Collaborator

Summary

This PR fixes memory bloat and potential OOM crashes when running the Gemini CLI with the --debug flag enabled. It introduces truncation for large console logs and output chunks, and limits the total number of debug messages stored in the UI.

Details

  • Implemented log truncation in ConsolePatcher (capped at 10,000 characters).
  • Implemented output chunk truncation in useConsoleMessages hook (capped at 10,000 characters).
  • Added a limit of 1,000 messages for the debug console history in useConsoleMessages reducer.

Related Issues

Related to the out-of-memory error crashes reported during session.

How to Validate

  1. Run the CLI with the --debug flag.
  2. Trigger large outputs (e.g., npm run test or reading large files).
  3. Open the debug drawer and verify that large messages are truncated and indicated with "... [Truncated X characters]".
  4. Verify that the UI remains responsive and memory usage stays stable even after many messages are logged.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run

@mattKorwel mattKorwel requested a review from a team as a code owner February 9, 2026 19:07
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @mattKorwel, 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 enhances the stability and performance of the Gemini CLI, particularly when operating in debug mode. By introducing intelligent truncation mechanisms for excessively large log messages and output data, and by capping the historical record of debug messages, the changes effectively mitigate memory consumption issues. This ensures a more robust and responsive user interface, preventing crashes that could arise from overwhelming the system with verbose debug information.

Highlights

  • Memory Optimization: Implemented truncation for large console logs and output chunks to prevent memory bloat and potential Out-Of-Memory (OOM) crashes when running the CLI with the --debug flag.
  • Debug Message History Limit: Limited the total number of debug messages stored in the UI to 1,000 to maintain responsiveness and stable memory usage.
  • User Feedback for Truncation: Truncated messages and output chunks now include an indicator '... [Truncated X characters]' to inform the user about the truncation.
Changelog
  • packages/cli/src/ui/hooks/useConsoleMessages.ts
    • Introduced MAX_CONSOLE_MESSAGES constant set to 1000 to limit the number of stored console messages.
    • Added logic within the ADD_MESSAGES case to slice the newMessages array, ensuring the message history does not exceed MAX_CONSOLE_MESSAGES.
    • Defined MAX_OUTPUT_CHUNK_LENGTH constant as 10000 for truncating large output chunks.
    • Implemented truncation for payload.chunk content if its length exceeds MAX_OUTPUT_CHUNK_LENGTH, appending a truncation message.
  • packages/cli/src/ui/utils/ConsolePatcher.ts
    • Modified the formatArgs private method to include truncation logic for formatted console messages.
    • Messages exceeding MAX_CONSOLE_MSG_LENGTH (10000 characters) are now truncated, with a '... [Truncated X characters]' suffix added.
Activity
  • The pull request was opened by mattKorwel to address memory bloat and OOM crashes.
  • No further review comments or activity have been recorded since the initial commit.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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. 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

  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.

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 9, 2026
@github-actions
Copy link

github-actions bot commented Feb 9, 2026

Size Change: +670 B (0%)

Total Size: 23.9 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 23.9 MB +670 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

@mattKorwel mattKorwel enabled auto-merge February 9, 2026 22:40
? payload.chunk
: new TextDecoder().decode(payload.chunk);

const MAX_OUTPUT_CHUNK_LENGTH = 10000;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add a helper for this string truncation logic

state: ConsoleMessageItem[],
action: Action,
): ConsoleMessageItem[] {
const MAX_CONSOLE_MESSAGES = 1000;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: move const to the top level.

Copy link
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

lgtm

@mattKorwel mattKorwel added this pull request to the merge queue Feb 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 10, 2026
@mattKorwel mattKorwel added this pull request to the merge queue Feb 11, 2026
Merged via the queue into main with commit c202cf3 Feb 11, 2026
26 checks passed
@mattKorwel mattKorwel deleted the fix/debug-log-memory branch February 11, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants