Skip to content

fix(core): Prevent loop detection false positives on lists with long shared prefixes#18975

Merged
SandyTao520 merged 1 commit intomainfrom
st/fix/loop-detection-false-positives
Feb 13, 2026
Merged

fix(core): Prevent loop detection false positives on lists with long shared prefixes#18975
SandyTao520 merged 1 commit intomainfrom
st/fix/loop-detection-false-positives

Conversation

@SandyTao520
Copy link
Contributor

@SandyTao520 SandyTao520 commented Feb 13, 2026

Summary

Fixes an issue where loop detection was over-triggering on lists containing long, shared prefixes (e.g., lists of external service names). The LoopDetectionService now 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

  • 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 13, 2026 05:41
@gemini-cli
Copy link
Contributor

gemini-cli bot commented Feb 13, 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-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 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

  • Improved Loop Detection Accuracy: The LoopDetectionService has been enhanced to prevent false positives when processing lists that share long common prefixes, ensuring that only genuinely repeating sequences are flagged as loops.
  • Refined Algorithm: The detection algorithm now analyzes the uniqueness of the text sequences ('periods') between repeated content chunks. If these periods are highly variable, it indicates a list with a shared prefix rather than a true loop.
  • New Test Case: A specific test case was added to validate that lists with long shared prefixes (e.g., Google Cloud resource names) do not trigger false loop detections.
Changelog
  • packages/core/src/services/loopDetectionService.test.ts
    • Added a new test case to verify that the loop detection service correctly handles lists with long shared prefixes without flagging them as loops.
  • packages/core/src/services/loopDetectionService.ts
    • Modified the isLoop method to include an additional check that analyzes the uniqueness of 'periods' (text between repeated content chunks).
    • Introduced logic to return false if the number of unique periods exceeds a threshold, indicating a list with a shared prefix rather than a true loop.
Activity
  • No human activity has occurred on this pull request yet.
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.

@github-actions
Copy link

Size Change: +447 B (0%)

Total Size: 24.4 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 24.4 MB +447 B (0%)
./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-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@gemini-cli gemini-cli bot added the priority/p1 Important and should be addressed in the near term. label Feb 13, 2026
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 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!

@SandyTao520 SandyTao520 added this pull request to the merge queue Feb 13, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 13, 2026
@SandyTao520 SandyTao520 merged commit 9c285ea into main Feb 13, 2026
48 of 50 checks passed
@SandyTao520 SandyTao520 deleted the st/fix/loop-detection-false-positives branch February 13, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants