Gemini CLI PR fixes loop recovery dropping unsent tool results

codewithfourtix · ghdev · 2026-10-22

A PR to google-gemini/gemini-cli (#29871) fixes a subtle agent-loop bug: when the start-of-turn loop check triggered, recoverFromLoop sent only the loop feedback and dropped the pending request — usually the functionResponse of an already-executed tool — so the call was closed as "Response was lost or interrupted" and the model lost the tool's result.

The fix passes the unsent request into recoverFromLoop, sending request parts first followed by the feedback text in one user turn. isFunctionResponse now matches any turn containing a functionResponse part, so closeUnansweredToolCallsTurn no longer replaces the real result. The streaming-time loop check is unchanged (the request was already sent there), and the check is deliberately not postponed: late in a prompt a tool response is almost always pending, so the check would nearly never run. Includes a new test that fails on main, fixing #29815.

Original post →

More from coding & agent

coding & agent channel →