Skip to content

Comments

refactor: simplify tool output truncation to single config#18446

Merged
SandyTao520 merged 2 commits intomainfrom
st/tool-truncation-v2
Feb 6, 2026
Merged

refactor: simplify tool output truncation to single config#18446
SandyTao520 merged 2 commits intomainfrom
st/tool-truncation-v2

Conversation

@SandyTao520
Copy link
Contributor

@SandyTao520 SandyTao520 commented Feb 6, 2026

Summary

Consolidate three truncation settings into one (truncateToolOutputThreshold). Truncated output now shows head (20%) + tail (80%) with an omission marker. Default threshold lowered from 4M to 40K characters.

Details

  • Removed enableToolOutputTruncation and truncateToolOutputLines settings
  • truncateToolOutputThreshold > 0 enables truncation, <= 0 disables it
  • Truncated output format: first 20% of threshold chars, [N characters omitted] marker, last 80% of threshold chars
  • Default threshold: 40,000 chars (~10K tokens) — fits comfortably in context windows
  • Removed lines field from ToolOutputTruncatedEvent telemetry

Related Issues

#17037

How to Validate

  1. Run a shell command that produces large output (e.g. cat a large file)
  2. Verify truncated output shows head + [N characters omitted] + tail
  3. Set truncateToolOutputThreshold: 0 and verify truncation is disabled

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
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@SandyTao520 SandyTao520 requested a review from a team as a code owner February 6, 2026 17:15
@gemini-cli
Copy link
Contributor

gemini-cli bot commented Feb 6, 2026

Hi @SandyTao520, 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!

@gemini-cli
Copy link
Contributor

gemini-cli bot commented Feb 6, 2026

Hi there! Thank you for your contribution to Gemini CLI.

To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md.

This pull request is being closed because it is not currently linked to an issue. Once you have updated the description of this PR to link an issue (e.g., by adding Fixes #123 or Related to #123), it will be automatically reopened.

How to link an issue:
Add a keyword followed by the issue number (e.g., Fixes #123) in the description of your pull request. For more details on supported keywords and how linking works, please refer to the GitHub Documentation on linking pull requests to issues.

Thank you for your understanding and for being a part of our community!

@gemini-cli gemini-cli bot closed this Feb 6, 2026
@SandyTao520 SandyTao520 reopened this Feb 6, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @SandyTao520, 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 streamlines the configuration and behavior of tool output truncation. By unifying multiple settings into a single character-based threshold and implementing a more informative head-and-tail display for truncated content, the system becomes easier to manage and provides better context for large outputs, especially when interacting with language models. The default truncation limit has also been adjusted to be more practical for current LLM constraints.

Highlights

  • Simplified Truncation Configuration: Consolidated three separate tool output truncation settings (enableToolOutputTruncation, truncateToolOutputLines, truncateToolOutputThreshold) into a single truncateToolOutputThreshold setting. Truncation is now enabled if this threshold is greater than 0, and disabled otherwise.
  • Updated Truncation Logic: The method for truncating large tool outputs has been revised. Instead of line-based truncation or showing only the tail, the new logic displays the first 20% and the last 80% of the output, with an omission marker indicating the skipped characters in between.
  • Adjusted Default Threshold: The default truncateToolOutputThreshold has been significantly lowered from 4,000,000 characters to 40,000 characters. This new default is designed to fit more comfortably within typical LLM context windows.
  • Telemetry Update: The lines field has been removed from the ToolOutputTruncatedEvent telemetry, aligning with the new character-based truncation approach.
Changelog
  • packages/a2a-server/src/utils/testing_utils.ts
    • Removed DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES import and its usage in mock configuration.
  • packages/cli/src/config/config.ts
    • Removed truncateToolOutputLines and enableToolOutputTruncation from the CLI configuration loading process.
  • packages/cli/src/config/settingsSchema.ts
    • Removed DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES import.
    • Deleted schema definitions for enableToolOutputTruncation and truncateToolOutputLines.
    • Updated the description and default value for truncateToolOutputThreshold to reflect the new character-based logic and reduced default.
  • packages/cli/src/config/settings_repro.test.ts
    • Removed truncateToolOutputLines from test settings.
  • packages/cli/src/ui/hooks/useToolScheduler.test.ts
    • Removed DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES import and its usage in mock configuration.
  • packages/core/index.ts
    • Removed the export of DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES.
  • packages/core/src/config/config.ts
    • Removed the DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES constant.
    • Updated DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD from 4,000,000 to 40,000 characters.
    • Removed truncateToolOutputLines and enableToolOutputTruncation from ConfigParameters interface and Config class properties.
    • Removed initialization and getter methods for the deprecated truncation settings.
  • packages/core/src/core/coreToolScheduler.test.ts
    • Removed DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES import and its usage in mock configuration.
  • packages/core/src/scheduler/tool-executor.test.ts
    • Removed test mocks related to getEnableToolOutputTruncation and getTruncateToolOutputLines.
    • Adjusted formatTruncatedToolOutput calls in tests to pass the character threshold instead of lines.
  • packages/core/src/scheduler/tool-executor.ts
    • Simplified the conditional logic for tool output truncation, now relying solely on truncateToolOutputThreshold > 0.
    • Modified the call to formatTruncatedToolOutput to pass the character threshold.
    • Removed the lines parameter from the logToolOutputTruncated event.
  • packages/core/src/services/chatCompressionService.test.ts
    • Updated expected output messages in tests to reflect the new 'Output truncated.' message and the head/tail character-based format.
  • packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts
    • Removed GEMINI_CLI_TOOL_OUTPUT_TRUNCATED_LINES from telemetry logging.
  • packages/core/src/telemetry/loggers.test.ts
    • Removed the lines field from ToolOutputTruncatedEvent in telemetry tests.
  • packages/core/src/telemetry/types.ts
    • Removed the lines property from the ToolOutputTruncatedEvent class and its constructor.
  • packages/core/src/utils/fileUtils.test.ts
    • Removed tests for line-based truncation and 'elephant lines'.
    • Added new tests to verify the character-based head (20%) and tail (80%) truncation with an omission marker.
  • packages/core/src/utils/fileUtils.ts
    • Removed MAX_TRUNCATED_LINE_WIDTH and MAX_TRUNCATED_CHARS constants.
    • Refactored formatTruncatedToolOutput to implement the new head (20%) and tail (80%) character-based truncation logic, replacing the previous line-based and simple character-based methods.
  • schemas/settings.schema.json
    • Removed enableToolOutputTruncation and truncateToolOutputLines properties from the settings schema.
    • Updated the truncateToolOutputThreshold property's description and default value to reflect the new unified approach and default of 40,000 characters.
Activity
  • The author, SandyTao520, initiated this pull request to refactor and simplify the tool output truncation mechanism.
  • The pull request description indicates that relevant tests were added or updated, ensuring the new truncation logic functions as expected.
  • The author also noted that breaking changes were considered, which is crucial for maintaining system stability.
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.

Copy link
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 effectively simplifies the tool output truncation configuration by consolidating three settings into a single truncateToolOutputThreshold. The implementation of the new head/tail truncation logic is clean and the related changes across the codebase, including tests and schemas, are consistent. The default threshold has also been reasonably lowered.

However, I've identified one critical issue where the chat history compression logic might be unintentionally truncating tool outputs far more aggressively than before (from 4,000 characters down to 30), which could lead to significant context loss for the model. Please see the specific comment for details.

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

Size Change: -2.53 kB (-0.01%)

Total Size: 23.8 MB

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

compressed-size-action

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 6, 2026
@SandyTao520 SandyTao520 force-pushed the st/tool-truncation-v2 branch from 56d9fe6 to 6322f18 Compare February 6, 2026 17:35
@SandyTao520 SandyTao520 requested a review from a team as a code owner February 6, 2026 17:35
this.config.getTruncateToolOutputLines() > 0
) {
const originalContentLength = content.length;
if (typeof content === 'string' && toolName === SHELL_TOOL_NAME) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I forget, why do we need thr truncation logic at the tool executor level instead of inside of the shell tool?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we plan to expand this to other tools like grep and web_search which have large outputs, will explore this a bit and see if should proceed or just remove it.

@SandyTao520 SandyTao520 force-pushed the st/tool-truncation-v2 branch from 3d2e677 to e2f1c33 Compare February 6, 2026 21:07
@SandyTao520 SandyTao520 enabled auto-merge February 6, 2026 21:32
@SandyTao520 SandyTao520 added this pull request to the merge queue Feb 6, 2026
Merged via the queue into main with commit 28805a4 Feb 6, 2026
25 of 26 checks passed
@SandyTao520 SandyTao520 deleted the st/tool-truncation-v2 branch February 6, 2026 21:54
aswinashok44 pushed a commit to aswinashok44/gemini-cli that referenced this pull request Feb 9, 2026
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