fix(core): add uniqueness guard to edit tool#19890
fix(core): add uniqueness guard to edit tool#19890bdmorgan merged 3 commits intogoogle-gemini:mainfrom
Conversation
This adds a check in `calculateExactReplacement` to prevent multiple occurrences from being incorrectly replaced if they exceed 'expectedReplacements'. Fixes google-gemini#18917
Summary of ChangesHello @Shivangisharma4, 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 resolves an issue where the 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. 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a safety guard in the edit tool's calculateExactReplacement function. The change correctly prevents replacements when the number of found occurrences exceeds the expected number, avoiding unintended modifications. The implementation is clear and effectively addresses the issue described, improving the robustness of the exact replacement strategy.
|
/gemini I am concerned that this fix only guards the exact matching strategy. If the exact match fails (e.g., due to a single space difference), the tool falls back to the flexible strategy, which still applies all matches it finds without a guard. It seems to me that the PR should apply the same uniqueness guard to the flexible and regex matching strategies. This would ensure that the tool doesn't "fail open" by falling back to an unguarded strategy when a guarded one found too many matches. Please re-review with this in mind CC: @Shivangisharma4 |
There was a problem hiding this comment.
Code Review
This pull request introduces a fix to the edit tool to prevent incorrect replacements when the number of found occurrences exceeds the expected number. The change adds a guard in calculateExactReplacement to check for this condition and return the original content, which correctly prevents the generation of a misleading diff for user confirmation. The fix is well-targeted and effectively resolves the described issue.
Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
Fixes #18917 by adding a check in
calculateExactReplacementto prevent multiple occurrences from being incorrectly replaced if they exceed 'expectedReplacements'.