Skip to content

Conversation

@galz10
Copy link
Collaborator

@galz10 galz10 commented Dec 5, 2025

Summary

Fixes a critical bug where the background prompt completion feature would enter an infinite retry loop when encountering an API error (such as "Quota Exceeded").

Details

The issue was caused by the usePromptCompletion hook clearing its internal state (lastRequestedTextRef) whenever an API request failed. This was intended to allow retries, but instead caused the component to treat the existing user input as "new" during the next render cycle, triggering an immediate retry. This cycle would repeat indefinitely as long as the error persisted.

The fix removes the logic that clears lastRequestedTextRef on error. Now, the CLI remembers that it has already attempted completion for the current text, preventing automatic retries until the user actually modifies the input.

Related Issues

Fixes #14477

How to Validate

  1. Ensure prompt completion is enabled in your configuration (enablePromptCompletion: true).
  2. Open the CLI and type a partial command (e.g., Create a func).
  3. Simulate a failure condition (e.g., by temporarily disabling network or if you are hitting a rate limit).
  4. Before Fix: The CLI would endlessly spam the API in the background (visible in logs or via high CPU usage).
  5. After Fix: The CLI should attempt the request once, fail gracefully, and not retry until you type another character.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (Verified via reproduction test suite locally)
  • 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

@galz10 galz10 requested a review from a team as a code owner December 5, 2025 00:12
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @galz10, 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 resolves a significant bug in the CLI's background prompt completion mechanism. Previously, API errors would cause the system to enter an endless retry loop, leading to excessive resource consumption and API calls. The implemented solution prevents this by ensuring that the system no longer automatically retries completion requests after an error unless the user explicitly changes their input, thereby improving the stability and efficiency of the CLI.

Highlights

  • Bug Fix: Infinite Retry Loop: Addresses a critical bug where the background prompt completion feature would enter an infinite retry loop when encountering API errors like 'Quota Exceeded'.
  • Root Cause Identified: The issue stemmed from the usePromptCompletion hook clearing its internal state (lastRequestedTextRef) upon API request failure, which inadvertently triggered immediate retries as the existing user input was treated as 'new'.
  • Solution Implemented: The fix involves removing the logic that clears lastRequestedTextRef on error. This ensures the CLI remembers previous completion attempts, preventing automatic retries until the user actively modifies their input.
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.

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 correctly addresses a critical infinite loop bug in the prompt completion feature. The issue occurred when an API error would cause the component to continuously retry the request. The fix is simple and effective: by not clearing lastRequestedTextRef on an error, the hook now correctly remembers the last attempted text and avoids retrying until the user modifies the input. The change is well-explained in the pull request description and effectively resolves the reported issue.

@github-actions
Copy link

github-actions bot commented Dec 5, 2025

Size Change: -45 B (0%)

Total Size: 21.5 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 21.5 MB -45 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./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-closed.sb 3.29 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

compressed-size-action

@galz10 galz10 changed the title Galzahavi/fix/inf loop fix: prevent infinite loop in prompt completion on error Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinity loop gemini-2.5-flash lite requests in background

3 participants