Repository navigation
Conversation
… nudge The empty-response auto-nudge fired from inside the stream loop as a floating promise whenever a continuation produced no visible text. That also happened when the stream ended because the user cancelled, an API error occurred, a hook stopped or blocked the agent, a limit was reached, or the core reported an invalid stream (after already retrying with its own nudge). Because submitQuery resets turnCancelledRef and creates a new AbortController, a nudge after Esc silently undid the cancellation. The stream loop now only reports an empty continuation when the stream ended normally and was not aborted. submitQuery then sends the nudge after flushing the pending history item, only if the turn was not cancelled and no newer query has started, and awaits it so the request stays responding until the nudge completes. Fixes google-gemini#29071
|
📊 PR Size: size/M
|
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 improves the reliability of the auto-nudge feature in the Gemini CLI. Previously, the nudge was triggered incorrectly when streams ended for reasons other than an empty model response, such as user cancellation or errors. By introducing a status-based tracking system and properly awaiting the nudge operation, this change ensures that nudges only occur when appropriate and do not interfere with active request lifecycles. 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 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 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
|
There was a problem hiding this comment.
Code Review
This pull request refactors the auto-nudge behavior on empty continuation responses in useGeminiStream. Instead of triggering the nudge as a fire-and-forget promise, the stream processing now returns an EmptyContinuation status, allowing the nudge query to be properly awaited. It also introduces an endedAbnormally flag to prevent nudging when the stream terminates due to errors, cancellations, or other limits. Comprehensive unit tests have been added to verify these scenarios. I have no feedback to provide as there are no review comments.
|
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. |
|
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. |
Summary
When a tool-loop continuation came back with no visible text,
useGeminiStreamautomatically sent a nudge ([System: You successfully executed a tool but returned an empty response...]). It did this as a fire-and-forget promise from inside the stream loop, and it only checked that the text buffer was empty. As a result the nudge also fired when the stream ended for reasons that are not an empty model response, including after the user pressed Esc. In that case it silently undid the cancellation and started a new request. This PR only nudges genuinely empty continuations and sequences the nudge properly.Details
Before (
processGeminiStreamEvents):isContinuation && buffer is empty && attempts < 2. That is also true when the stream ended with:UserCancelled, or a signal aborted by Esc.submitQuerythen resetsturnCancelledRefand creates a newAbortController, so the cancel is undone and the model is called again.Error: the error is shown, then another request is sent anyway.AgentExecutionStopped/AgentExecutionBlocked: a hook asked the agent to stop and the nudge overrode it.MaxSessionTurns,ContextWindowWillOverflow,LoopDetected.InvalidStream, e.g.NO_RESPONSE_TEXT. Since (FIX) history rollback and retry nudge optimizations #28934 the core already retries empty responses with its own nudge (NO_RESPONSE_TEXT_NUDGE_MESSAGE) before reporting this, so the CLI nudge was a second, stacked retry.submitQueryRef.current?.(...)call, started before the outersubmitQueryhad flushed its pending history item.After:
processGeminiStreamEventsrecords when the stream ended abnormally (the events above). It returns a newStreamProcessingStatus.EmptyContinuationonly for a continuation that ended normally, was not aborted, and produced no text or tool calls.submitQueryhandles that status after flushing the pending history item. It sends the nudge only if:turnCancelledRef),activeQueryIdRef),Respondinguntil the nudge has finished.prompt_idparameter ofprocessGeminiStreamEventsis removed.Not changed: the issue also suggests skipping
geminiClient.addHistoryfor completed tools in the cancelled path ofhandleCompletedTools. I left that alone. Those responses pair the model'sfunctionCallturn that is already in history, and dropping them would leave an unansweredfunctionCall, which is the corruption the surrounding code works to avoid (see the comment in themodelSwitchedFromQuotaErrorbranch). Happy to look at it separately if maintainers see a concrete repro.Related Issues
Fixes #29071
How to Validate
New
auto-nudge on empty continuation responsestests:cancelOngoingRequest) while the continuation is still streaming7 of these fail on
mainand pass with this change. The existing auto-nudge test (viahandleCompletedTools) still passes. All CLI hook andAppContainertests pass (68 files, 1278 tests), and typecheck and lint are clean.Pre-Merge Checklist