fix(core): Prevent loop detection false positives on lists with long shared prefixes#18975
Conversation
|
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! |
Summary of ChangesHello @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 addresses a critical issue in the loop detection mechanism where it incorrectly identified valid lists with extensive shared prefixes as repetitive loops, leading to premature termination of content generation. The core change involves a more sophisticated algorithm that differentiates between true content repetition and common prefixes by examining the variability of the content segments between suspected repeating chunks. This ensures the service accurately identifies actual loops while allowing legitimate, structured lists to stream without interruption, significantly improving the robustness of content generation. Highlights
Changelog
Activity
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
|
|
Size Change: +447 B (0%) Total Size: 24.4 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a false positive in the loop detection mechanism that occurred with lists sharing long prefixes. The new logic, which analyzes the "period" between repeated content chunks to differentiate true loops from lists, is a solid improvement. The added test case correctly validates this fix by simulating the exact scenario that caused the issue. The changes are well-implemented and improve the robustness of the loop detection service. Good work!
Summary
Fixes an issue where loop detection was over-triggering on lists containing long, shared prefixes (e.g., lists of external service names). The
LoopDetectionServicenow verifies that the sequence is actually repeating in its entirety and not just sharing a common prefix.Details
The algorithm previously hashed 50-character chunks of streaming text and triggered when a chunk repeated 10 times in close proximity. This meant any sequence sharing a 50+ character prefix (like a list of Google Cloud service names) would trigger a false loop detection.
By analyzing the sequences of text ("periods") between each identical chunk occurrence, the logic now differentiates between true chanting/looping (where the periods are highly repetitive or few in unique number) and valid lists with shared prefixes (where the text trailing the prefix is highly variable).
Related Issues
#18007
How to Validate
You can validate this change by prompting the AI to output a long list of items sharing a very long prefix (e.g., "List 20 Google Cloud resource names in the format 'projects/my-google-cloud-project-12345/locations/us-central1/services/...'"). The model should stream the full list without halting with a loop detection error.
Pre-Merge Checklist