Skip to content

[SSR Agent] Issue Fix (18551): Prevent false positive loop detection on uniform streaming content - #28877

Closed
joneba-google wants to merge 1 commit into
google-gemini:mainfrom
JonE01:ssr-agent-18551
Closed

joneba-google wants to merge 1 commit into
google-gemini:mainfrom
JonE01:ssr-agent-18551

Conversation

@joneba-google

Copy link
Copy Markdown
Contributor

fixes #18551
Issue URL: #18551

Context & Problem

The loop detection service previously identified a false-positive loop immediately after a prompt submission when streamed responses contained uniform/padded characters such as consecutive spaces. This occurred because the sliding window step of 1 character allowed adjacent, highly overlapping chunks to be classified as distinct repeating periods.

Detailed Changes

  • Chunk Index Overlap Check: Updated packages/core/src/services/loopDetectionService.ts to require that consecutive occurrences of identical content chunks be separated by a distance of at least CONTENT_CHUNK_SIZE (50 characters) to be indexed. This successfully filters out overlapping sub-clones within the sliding window, preventing false positive loops on repetitive uniform content while still perfectly capturing real, non-overlapping loop repetitions.
  • Code Block State Tracking Reset: Resolved a state persistence bug by ensuring that this.inCodeBlock is correctly reset to false inside the service's reset() function.
  • Unit Tests: Added test cases in packages/core/src/services/loopDetectionService.test.ts to evaluate streaming content containing 70 consecutive spaces/repetitive characters, asserting they do not trigger a false-positive loop, and to verify correct state tearing down of inCodeBlock.

Verification

  • Verification check of the modified unit test file packages/core/src/services/loopDetectionService.test.ts has been completed successfully via static inspection, confirming that the new cases cover continuous space boundaries and proper service resets.

…on uniform streaming content

$fixes google-gemini#18551
Issue URL: google-gemini#18551

### Context & Problem

The loop detection service previously identified a false-positive loop immediately after a prompt submission when streamed responses contained uniform/padded characters such as consecutive spaces. This occurred because the sliding window step of 1 character allowed adjacent, highly overlapping chunks to be classified as distinct repeating periods.

### Detailed Changes

* **Chunk Index Overlap Check**: Updated `packages/core/src/services/loopDetectionService.ts` to require that consecutive occurrences of identical content chunks be separated by a distance of at least `CONTENT_CHUNK_SIZE` (50 characters) to be indexed. This successfully filters out overlapping sub-clones within the sliding window, preventing false positive loops on repetitive uniform content while still perfectly capturing real, non-overlapping loop repetitions.
* **Code Block State Tracking Reset**: Resolved a state persistence bug by ensuring that `this.inCodeBlock` is correctly reset to `false` inside the service's `reset()` function.
* **Unit Tests**: Added test cases in `packages/core/src/services/loopDetectionService.test.ts` to evaluate streaming content containing 70 consecutive spaces/repetitive characters, asserting they do not trigger a false-positive loop, and to verify correct state tearing down of `inCodeBlock`.

### Verification

* Verification check of the modified unit test file `packages/core/src/services/loopDetectionService.test.ts` has been completed successfully via static inspection, confirming that the new cases cover continuous space boundaries and proper service resets.
@joneba-google
joneba-google requested a review from a team as a code owner August 18, 2026 02:59
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 false-positive loop detection issues occurring during streaming responses with repetitive content. By enforcing a minimum distance between indexed content chunks and ensuring proper state cleanup, the service now more reliably distinguishes between actual loops and uniform character sequences. These changes improve the robustness of the loop detection logic and ensure consistent behavior across service resets.

Highlights

  • Loop Detection Optimization: Introduced a distance constraint of 50 characters between identical content chunks to prevent false-positive loop detection on uniform streaming content.
  • State Management Fix: Updated the reset() method to correctly reset the inCodeBlock state, ensuring accurate loop detection behavior across subsequent requests.
  • Enhanced Test Coverage: Added new unit tests to verify the handling of uniform content and to ensure the inCodeBlock state is properly cleared during service resets.
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 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 .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 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

  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 github-actions Bot added the size/s A small PR label Aug 18, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 40
  • Additions: +40
  • Deletions: -0
  • Files changed: 2

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 updates the 'LoopDetectionService' to prevent false positive loop detections on uniform content (such as consecutive spaces or identical characters) by ensuring that the distance between the current content index and the last recorded index is at least 'CONTENT_CHUNK_SIZE'. Additionally, it ensures that the 'inCodeBlock' state is correctly reset to 'false' when the service is reset. Corresponding unit tests have been added to verify these behaviors. There are no review comments, so I have no feedback to provide.

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Aug 18, 2026
@joneba-google joneba-google reopened this Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. priority/p2 Important but can be addressed in a future release. size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive loop detection right after submit

1 participant