google-gemini / google-gemini/gemini-cli
Empty-response retries fail to recover model due to nudge message placement in system prompt
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
### 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](https://github.com/google-gemini/gemini-cli/pull/28566#issuecomment-5109694687) 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.
```console │
About Gemini CLI
CLI Version 0.55.1
Git Commit 41327e407
Model Auto
Sandbox no sandbox
OS linux
Auth Method Signed in with Google ()
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_
Contributor guide
Research direction
Start by tracing the CLI recovery path for InvalidStreamError values NO_RESPONSE_TEXT and THINKING_ONLY_RESPONSE, including the systemInstruction change introduced in PR #28566. Compare the current placement with the contents-array or last-turn placement described in the issue. Done means empty-response retries can recover and the static system-instruction and history cache remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100