Skip to content

fix(core): keep the unsent request when loop recovery starts before a turn - #29871

Closed
codewithfourtix wants to merge 1 commit into
google-gemini:mainfrom
codewithfourtix:fix/loop-recovery-keeps-unsent-request
Closed

codewithfourtix wants to merge 1 commit into
google-gemini:mainfrom
codewithfourtix:fix/loop-recovery-keeps-unsent-request

Conversation

@codewithfourtix

@codewithfourtix codewithfourtix commented Oct 22, 2026 •

Copy link
Copy Markdown

Summary

When the loop check at the start of a turn reports a loop, _recoverFromLoop sends only the loop feedback and drops the pending request. That request is usually the functionResponse of a tool that already ran, so the call is closed as "Response was lost or interrupted." and the model loses the record of what the tool did.

Details

processTurn now passes the unsent request to _recoverFromLoop, which sends the request parts first and the feedback text after them, in one user turn. isFunctionResponse matches a turn with any functionResponse part, so closeUnansweredToolCallsTurn no longer replaces the real result.

The loop check during streaming is not changed, because there the request was already sent. I did not postpone the check while a tool response is pending: late in a prompt a response is almost always pending, so the check would almost never run.

Related Issues

Fixes #29815

How to Validate

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

… turn

When the loop check in processTurn reports a loop before the request is
sent, _recoverFromLoop sent only the loop feedback and dropped the request.
That request is usually the functionResponse of a tool that already ran,
so GeminiChat closed the call as "Response was lost or interrupted." and
the model lost the record of what the tool did.

Send the unsent request parts first and the loop feedback after them, in
one user turn. The loop check during streaming is not changed, because
there the request was already sent.

Fixes google-gemini#29815
@codewithfourtix
codewithfourtix requested a review from a team as a code owner October 22, 2026 04:02
@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 an issue where pending requests, specifically tool responses, were being discarded during loop recovery. By passing the unsent request into the recovery process, the system now ensures that the model retains the context of tool executions, preventing incorrect 'lost or interrupted' status errors.

Highlights

  • Loop Recovery Logic: Updated the loop recovery mechanism to preserve pending requests, such as tool responses, instead of dropping them when a loop is detected.
  • Test Coverage: Added a new test case to ensure that unsent tool responses are correctly maintained during loop recovery scenarios.
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/m A medium sized PR label Oct 22, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 55
  • Additions: +54
  • Deletions: -1
  • 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 ensures that unsent requests, such as tool responses, are not dropped when a loop is detected before the request is sent. It updates the 'GeminiClient' to accept and prepend 'unsentRequest' parts to the loop feedback message, and adds a corresponding unit test to verify this behavior. I have no feedback to provide as there are no review comments.

@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 labels Oct 22, 2026
@gemini-cli

gemini-cli Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'.

This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

@gemini-cli

gemini-cli Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

@gemini-cli gemini-cli Bot closed this Nov 6, 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 priority/p2 Important but can be addressed in a future release. size/m A medium sized PR status/pr-nudge-sent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLM loop recovery discards the result of a tool that already ran and tells the model it was "lost or interrupted"

1 participant