Skip to content

Empty-response retries fail to recover model due to nudge message placement in system prompt #28909

Description

@tmtd4c93aac

What happened?

When the model sends back an empty response loop (InvalidStreamError with type NO_RESPONSE_TEXT or THINKING_ONLY_RESPONSE), the CLI attempts to recover by appending a nudge message to config.systemInstruction (introduced in PR #28566).

This recovery mechanism fails, and the model remains stuck. Because systemInstruction is evaluated at the very beginning of the prompt, the nudge message is placed at the absolute start of the context window. In sessions with even smallish context histories (Observed at 9%), the nudge is completely drowned out by the time the model processes the recent conversation history and attempts generation.

As a secondary issue, modifying systemInstruction breaks the prefix cache. In observed session logs, a retry's cache hit dropped from ~98k tokens to ~37k tokens because the static system instruction prefix was altered.

What did you expect to happen?

The model should successfully break out of the empty response loop. As I mentioned in my comment in the initial PR, to achieve this the nudge message must be injected at the end of the contents array (e.g., as a system or user message representing the failure of the previous turn) or appended to the last turn so it is the last thing the model reads before generating.
This will also preserve the context cache for the system instructions and history.

Client information

Client Information

Run gemini to enter the interactive CLI, then run the /about command.

 About Gemini CLI

 CLI Version                                        0.55.1
 Git Commit                                         41327e407
 Model                                              Auto
 Sandbox                                            no sandbox
 OS                                                 linux
 Auth Method                                        Signed in with Google (<email>)
 Tier                                               Gemini Code Assist Standard
 GCP Project                                        tm-gcp-emea-ai-platform

Login information

Signed in with Google account

Anything else we need to know?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/agentIssues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Qualitystatus/need-triageIssues that need to be triaged by the triage automation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions