-
Notifications
You must be signed in to change notification settings - Fork 9.2k
feat(core): enhance loop detection with 2-stage check #12902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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 significantly upgrades the LLM-based loop detection mechanism by introducing a more efficient and reliable two-stage verification process. It prioritizes a fast initial check with a lightweight model and escalates to a more robust model for high-confidence detections, ensuring accuracy while optimizing resource usage. Additionally, it integrates detailed telemetry to provide better insights into the loop detection process. 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
|
|
Size Change: +5.37 kB (+0.03%) Total Size: 20.5 MB
ℹ️ View Unchanged
|
There was a problem hiding this 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 introduces a valuable two-stage loop detection mechanism, leveraging a faster model for an initial check before escalating to the main model. This is a smart approach to optimize for cost and latency. The associated telemetry and unit tests are comprehensive and well-implemented. However, I've identified a high-severity issue where the optimization to skip the second check can be defeated when model routing is active (e.g., when using an 'auto' model alias), potentially leading to redundant API calls.
TLDR
This PR enhances the
LoopDetectionServiceby implementing a two-stage check mechanism. It first uses thegemini-2.5-flashmodel for a fast and cost-effective initial assessment. If a potential loop is detected with high confidence (>= 0.9), it performs a secondary confirmation check usinggemini-2.5-pro(unless the CLI is in fallback mode). It also adds comprehensive telemetry for these checks.Dive Deeper
gemini-2.5-flash.DEFAULT_GEMINI_MODEL(gemini-2.5-pro).this.config.isInFallbackMode()is true, the second check is skipped, and the first result is used. This prevents using the more expensive model when we are already in a fallback state.LlmLoopCheckEventto track:flash_confidence: Confidence score from the Flash model.main_model: The name of the main model used for the second check.main_model_confidence: Confidence score from the main model (or -1 if skipped, or 0 if the second check wasn't triggered).EventMetadataKeys.loopDetectionService.test.tsto cover the new logic, including boundary conditions and model disagreement scenarios.Reviewer Test Plan
npm run test:cito verify the new unit tests inpackages/core/src/services/loopDetectionService.test.ts.LLM_CHECK_AFTER_TURNS.isInFallbackMode()is true.Testing Matrix
Linked issues / bugs