fix(core): reduce LLM-based loop detection false positives#20701
fix(core): reduce LLM-based loop detection false positives#20701SandyTao520 merged 3 commits intomainfrom
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, 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 significantly enhances the accuracy of the LLM-based loop detection mechanism by addressing several root causes of false positives. By providing the LLM with the original user's task context, refining the system prompt with clearer definitions and argument analysis instructions, and tuning the check frequency, the system can now more effectively differentiate between legitimate, productive batch operations and actual unproductive loops, leading to a more robust and less intrusive user experience. 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
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the issue of false positives in the LLM-based loop detection by providing more context to the diagnostic model and refining its behavior. The changes, including passing the original user prompt, rewriting the system prompt for clarity, and tuning the check frequency, are well-reasoned and directly target the problems described. The updated system prompt is a particularly great improvement, offering much clearer guidance to the model. The identified high-severity security concern related to passing raw user input to the diagnostic LLM, which could open a vector for prompt injection, remains a valid point of feedback.
|
Size Change: +2.87 kB (+0.01%) Total Size: 25.8 MB
ℹ️ View Unchanged
|
- Include original user prompt in loop-check context so the LLM can distinguish batch work from actual loops - Rewrite system prompt with concrete thresholds, explicit cross-file batch exceptions, and mandatory argument differentiation - Raise LLM_CHECK_AFTER_TURNS (30→40) and DEFAULT_LLM_CHECK_INTERVAL (3→10) to give complex tasks more runway before checking - Increase MIN_LLM_CHECK_INTERVAL (5→7) to reduce over-checking
…g and build patterns Address PR feedback: rename pattern categories to emphasize identical outcomes are required, carve out build re-runs and debugging progress as legitimate workflow, and rename 'Cognitive loops' to 'Stuck reasoning' to avoid confusion with repeated command output.
Use <original_user_request> XML tags to clearly delineate user-provided content from loop detection instructions.
e026684 to
f5476d6
Compare
Summary
Reduces false positives in LLM-based loop detection by providing task context, tightening the system prompt, and tuning check frequency thresholds.
Details
The LLM-based loop detector was flagging legitimate batch operations (e.g., cross-file refactoring, adding headers to multiple files) as unproductive loops. Root causes:
Changes:
reset()signature and callsite inclient.ts.LLM_CHECK_AFTER_TURNS30→40,DEFAULT_LLM_CHECK_INTERVAL3→10,MIN_LLM_CHECK_INTERVAL5→7.Related Issues
Related to #18551
How to Validate
npm test -w @google/gemini-cli-core -- src/services/loopDetectionService.test.tsnpm test -w @google/gemini-cli-core -- src/core/client.test.tsPre-Merge Checklist