Repository navigation
fix(core): disable truncation when maxChars <= 0 in formatTruncatedToolOutput - #29542
Conversation
…olOutput Add a guard condition for maxChars <= 0 in formatTruncatedToolOutput. When maxChars is non-positive, output truncation is disabled and contentStr is returned untouched, preventing negative index slicing edge cases where output string size inadvertently expanded. Fixes google-gemini#28620
|
📊 PR Size: size/S
|
|
/gemini review |
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 an issue where negative or zero values for 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
|
There was a problem hiding this comment.
Code Review
This pull request updates the formatTruncatedToolOutput utility in packages/core/src/utils/fileUtils.ts to return the original content string unchanged when maxChars is less than or equal to 0. It also reorganizes the corresponding unit tests in fileUtils.test.ts into separate describe blocks and adds comprehensive test coverage for edge cases, including maxChars values of 0, negative numbers, and when the content length is within the maxChars limit. There are no review comments, so I have no additional feedback to provide.
There was a problem hiding this comment.
Code Review
This pull request updates the formatTruncatedToolOutput function in packages/core/src/utils/fileUtils.ts to return the original content string unmodified when maxChars is less than or equal to zero. It also adds corresponding unit tests in packages/core/src/utils/fileUtils.test.ts to verify this behavior for maxChars values of 0, negative numbers, and when the content length is within the maxChars limit. I have no feedback to provide.
d75234c
Summary
Clarifies behavior and adds a non-positive guard so that
maxChars <= 0disables output truncation and returnscontentStrunchanged, preventing index slicing edge cases where output string size inadvertently expanded.Details
In
packages/core/src/utils/fileUtils.ts,formatTruncatedToolOutputcalculates head and tail character slices to display output previews when strings exceedmaxChars. WhenmaxChars <= 0, negative slice indices cause unexpected boundary behavior where head and tail slices capture nearly the full string, resulting in output size inflation.This change updates the early return condition to:
When
maxChars <= 0, truncation is treated as disabled andcontentStris returned untouched without wrapping in truncation headers.Regression unit tests have been added to
packages/core/src/utils/fileUtils.test.tsto verify behavior formaxChars = 0,maxChars < 0(e.g.,-1,-1000), andmaxChars > 0.Related Issues
Fixes #28620
How to Validate
fileUtils:formatTruncatedToolOutputpass, including cases formaxChars = 0andmaxChars < 0.Pre-Merge Checklist