Skip to content

fix(core,cli): propagate InvalidStreamError details to UI for specific empty response guidance - #28566

Merged
DavidAPierce merged 30 commits into
mainfrom
fix/propagate-invalid-stream-details-28351
Jul 31, 2026
Merged

fix(core,cli): propagate InvalidStreamError details to UI for specific empty response guidance#28566
DavidAPierce merged 30 commits into
mainfrom
fix/propagate-invalid-stream-details-28351

Conversation

@DavidAPierce

@DavidAPierce DavidAPierce commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR propagates specific InvalidStreamError details (the error type and message) from the core backend layers up to the CLI UI hooks. This allows the CLI to display highly relevant and helpful troubleshooting suggestions—such as recommending the use of /compress to reduce context size when the model returns an empty text response.

Details

  • Core Events (Turn/geminiChat): Updated the ServerGeminiInvalidStreamEvent type and the Turn run logic to pass the specific error type and message values in the event's value payload, instead of dropping this detail.
  • UI Stream Hook (useGeminiStream): Implemented handleInvalidStreamEvent to check if eventValue.type is 'NO_RESPONSE_TEXT', in which case we display a custom, friendly message recommending the use of /compress. Otherwise, we fall back to displaying the event's raw error message.
  • Testing:
    • Updated packages/cli/src/nonInteractiveCli.test.ts mock events to include the new value metadata.
    • Updated packages/core/src/agent/event-translator.test.ts to mock the correct payload structure.
    • Updated packages/core/src/core/turn.test.ts to expect the populated value payload on InvalidStream events.
    • Fixed pre-existing/broken tests in packages/core/src/core/geminiChat.test.ts to correctly mock/stub and run the mid-conversation stream retry flow when empty text responses are received.

Related Issues

Addresses #28351 .

How to Validate

Run unit tests in the core and CLI packages to verify the new behavior:

npm test -w @google/gemini-cli-core -- src/core/turn.test.ts
npm test -w @google/gemini-cli-core -- src/core/geminiChat.test.ts
npm test -w @google/gemini-cli -- src/nonInteractiveCli.test.ts

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

@DavidAPierce
DavidAPierce requested a review from a team as a code owner July 28, 2026 19:55
@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 enhances the error handling and user feedback loop for the Gemini CLI. By propagating detailed error information from the core backend to the UI, the application can now provide actionable guidance to users when encountering specific stream issues, such as empty responses. Additionally, the change improves system robustness by enabling automatic retries for previously non-retryable empty response errors.

Highlights

  • Error Propagation: Updated the core backend to propagate InvalidStreamError details (type and message) through ServerGeminiInvalidStreamEvent instead of dropping them.
  • CLI UI Improvements: Implemented handleInvalidStreamEvent in the UI hook to display specific, helpful troubleshooting suggestions—such as recommending /compress—when the model returns an empty text response.
  • Retry Logic: Enabled retries for NO_RESPONSE_TEXT errors in GeminiChat, allowing the system to attempt recovery instead of immediately failing.
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 Jul 28, 2026
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown

📊 PR Size: size/XL

  • Lines changed: 2367
  • Additions: +2285
  • Deletions: -82
  • Files changed: 28

@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 improves the handling of invalid stream events by adding detailed error type and message information to ServerGeminiInvalidStreamEvent. It implements a handleInvalidStreamEvent callback in the CLI to display user-friendly error messages and updates the backend to retry requests on empty response text (NO_RESPONSE_TEXT) errors. The review feedback suggests defensively accessing eventValue properties using optional chaining and trimming the message to prevent potential runtime crashes and handle whitespace-only strings.

Comment thread packages/cli/src/ui/hooks/useGeminiStream.ts Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown

Size Change: +14 kB (+0.04%)

Total Size: 35.2 MB

Filename Size Change
./bundle/chunk-3S7PVFVO.js 0 B -13 kB (removed) 🏆
./bundle/chunk-7IXNSQH4.js 0 B -19.5 kB (removed) 🏆
./bundle/chunk-APNICLQT.js 0 B -49.2 kB (removed) 🏆
./bundle/chunk-EGM4L4TI.js 0 B -3.65 MB (removed) 🏆
./bundle/chunk-KHXRUQA3.js 0 B -3.77 kB (removed) 🏆
./bundle/chunk-O3JKZR4F.js 0 B -3.43 kB (removed) 🏆
./bundle/chunk-U26Z6N2E.js 0 B -661 kB (removed) 🏆
./bundle/chunk-WYJNC7TW.js 0 B -16.6 MB (removed) 🏆
./bundle/core-K54ZFILY.js 0 B -50.1 kB (removed) 🏆
./bundle/devtoolsService-6VVR66FB.js 0 B -147 kB (removed) 🏆
./bundle/gemini-UI25UUUA.js 0 B -590 kB (removed) 🏆
./bundle/interactiveCli-LI4SPZ4X.js 0 B -1.3 MB (removed) 🏆
./bundle/liteRtServerManager-4ZMQQ6RT.js 0 B -2.08 kB (removed) 🏆
./bundle/oauth2-provider-R5RFQ5F7.js 0 B -9.12 kB (removed) 🏆
./bundle/chunk-26YFHBSF.js 49.2 kB +49.2 kB (new file) 🆕
./bundle/chunk-5LEK27TS.js 19.5 kB +19.5 kB (new file) 🆕
./bundle/chunk-DBD75DGZ.js 3.65 MB +3.65 MB (new file) 🆕
./bundle/chunk-LHE2GJEL.js 13 kB +13 kB (new file) 🆕
./bundle/chunk-O7O5W7YM.js 3.43 kB +3.43 kB (new file) 🆕
./bundle/chunk-PSYV3TCU.js 3.77 kB +3.77 kB (new file) 🆕
./bundle/chunk-RB2VKDK6.js 16.6 MB +16.6 MB (new file) 🆕
./bundle/chunk-UOAAXNJJ.js 661 kB +661 kB (new file) 🆕
./bundle/core-6HVUD6K2.js 50.5 kB +50.5 kB (new file) 🆕
./bundle/devtoolsService-ZHLO7CRK.js 147 kB +147 kB (new file) 🆕
./bundle/gemini-A3RPAW4E.js 593 kB +593 kB (new file) 🆕
./bundle/interactiveCli-NTFKBWFQ.js 1.31 MB +1.31 MB (new file) 🆕
./bundle/liteRtServerManager-AQQWEAWG.js 2.08 kB +2.08 kB (new file) 🆕
./bundle/oauth2-provider-LGG524O4.js 9.12 kB +9.12 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/bundled/third_party/index.js 8 MB 0 B
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-5PS3AYFU.js 1.18 kB 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-L5V3KIDT.js 1.62 kB 0 B
./bundle/chunk-TUDYL3X4.js 40.3 kB 0 B
./bundle/cleanup-AIQGLZAZ.js 0 B -902 B (removed) 🏆
./bundle/devtools-TYCPOPV3.js 683 kB 0 B
./bundle/events-XB7DADIJ.js 418 B 0 B
./bundle/examples/hooks/scripts/on-start.js 188 B 0 B
./bundle/examples/mcp-server/example.js 1.43 kB 0 B
./bundle/gemini.js 5.38 kB 0 B
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB 0 B
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB 0 B
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB 0 B
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB 0 B
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB 0 B
./bundle/https-proxy-agent-AVGR4LHR.js 490 B 0 B
./bundle/multipart-parser-E7RMVJWU.js 11.7 kB 0 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 5.29 kB 0 B
./bundle/sandbox-macos-permissive-proxied.sb 5.58 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.3 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.5 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.75 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 4.96 kB 0 B
./bundle/src-65GKNWUJ.js 45.4 kB 0 B
./bundle/src-U45KTUYT.js 45.7 kB 0 B
./bundle/src-XZYPU6PJ.js 352 kB 0 B
./bundle/start-TMO2APX2.js 0 B -622 B (removed) 🏆
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/worker/worker-entry.js 363 kB 0 B
./bundle/cleanup-3EKDWUJJ.js 902 B +902 B (new file) 🆕
./bundle/start-6D4XRF43.js 622 B +622 B (new file) 🆕

compressed-size-action

@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/core Issues related to User Interface, OS Support, Core Functionality labels Jul 28, 2026
@tmtd4c93aac

tmtd4c93aac commented Jul 28, 2026

Copy link
Copy Markdown

Hey I'm the person who raised #28351. Thanks for raising a PR for it.
I would recommend that you read the last message I left on that issue. The information in there is based on me running my own patch for this issue locally.

But I'll reiterate a few important things:

  • Chunks with no response text are actually normal at the end of chunk chain. They are really common and they're fine as long as there was chunks before.
    The PR in its current state would result in a lot of unnecessary retries.
  • The issue with NO_RESPONSE_TEXT as an error is that it fires when any of the chunk are empty. Instead it should be firing only when it is the only chunk in the response.
    This PR does not change when the error is fired.
  • From my experience retrying the request as-is will most likely result in another empty response. Most likely because the previous turn was a large wall of text and the LLM gets confused about what it was doing.
    A nudge (e.g. [System Nudge: Please continue. Analyze the latest results and proceed with your task.]) needs to either be inserted in the previous user text or added as a new turn in the request.
    This PR does not add a nudge.

As such I believe that this PR is not ready to land.

@DavidAPierce

Copy link
Copy Markdown
Contributor Author

Thanks for your comment and analysis!
This PR is still a work in progress, so I will certainly take into account your suggestions.

@github-actions github-actions Bot added the size/l A large sized PR label Jul 29, 2026
…id-stream-details-28351' into fix/propagate-invalid-stream-details-28351
…cate empty response messages

Aligns the agentic non-interactive execution mode (nonInteractiveCliAgentSession.ts) with the standard non-interactive loop (nonInteractiveCli.ts) by introducing emitFinalResult(errorPayload) to properly output the 'INVALID_STREAM' error details and 'error' status in JSON/STREAM_JSON format outputs. Also deduplicates the user empty-text response warning string into a shared constant EMPTY_RESPONSE_COMPRESS_SUGGESTION defined in @google/gemini-cli-core.
@DavidAPierce

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 improves the handling of InvalidStream events across both interactive and non-interactive CLI modes. It ensures that empty text responses suggest using /compress and that API errors are properly logged for telemetry. Additionally, it enables retries on NO_RESPONSE_TEXT stream errors and tracks distinct error types in telemetry metrics. The feedback recommends reusing the EMPTY_RESPONSE_COMPRESS_SUGGESTION constant in useGeminiStream.ts to avoid duplicate strings and maintain consistency.

Note: Security Review did not run due to the size of the PR.

Comment thread packages/cli/src/ui/hooks/useGeminiStream.ts Outdated
Comment thread packages/cli/src/ui/hooks/useGeminiStream.ts

@SandyTao520 SandyTao520 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.

Two remaining P1 findings from the latest verification round.

Comment thread packages/core/src/core/geminiChat.ts
Comment thread packages/cli/src/ui/hooks/useGeminiStream.ts Outdated

@SandyTao520 SandyTao520 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.

Verified the addressed review findings and latest CI. Looks good.

@DavidAPierce
DavidAPierce added this pull request to the merge queue Jul 31, 2026
Merged via the queue into main with commit f47d6c6 Jul 31, 2026
36 checks passed
@DavidAPierce
DavidAPierce deleted the fix/propagate-invalid-stream-details-28351 branch July 31, 2026 18:03
@DavidAPierce

Copy link
Copy Markdown
Contributor Author

/patch

@github-actions

Copy link
Copy Markdown

🚀 [Step 1/4] Patch workflow(s) waiting for approval!

📋 Details:

  • Channels: stable,preview
  • Commit: f47d6c6f7a1308d81f9f57acf7d279f0928c5249
  • Workflows Created: 2

⏳ Status: The patch creation workflow has been triggered and is waiting for deployment approval. Please visit the specific workflow links below and approve the runs.

🔗 Track Progress:

@github-actions

Copy link
Copy Markdown

🚀 [Step 2/4] Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. Review and approve the hotfix PR: #28609
  2. Once merged, the patch release will automatically trigger
  3. You'll receive updates here when the release completes

🔗 Track Progress:

@github-actions

Copy link
Copy Markdown

🚀 [Step 2/4] Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. ⚠️ Resolve conflicts in the hotfix PR first: #28610
  2. Test your changes after resolving conflicts
  3. Once merged, the patch release will automatically trigger
  4. You'll receive updates here when the release completes

🔗 Track Progress:

@github-actions

Copy link
Copy Markdown

🚀 [Step 3/4] Patch Release Waiting for Approval!

📋 Release Details:

  • Environment: prod
  • Channel: stable → publishing to npm tag latest
  • Version: v0.53.0
  • Hotfix PR: Merged ✅
  • Release Branch: release/v0.53.0-pr-28566

⏳ Status: The patch release has been triggered and is waiting for deployment approval. Please visit the specific workflow run link below and approve the deployment. You'll receive another update when it completes.

🔗 Track Progress:

@github-actions

Copy link
Copy Markdown

🚀 [Step 3/4] Patch Release Waiting for Approval!

📋 Release Details:

  • Environment: prod
  • Channel: preview → publishing to npm tag preview
  • Version: v0.54.0-preview.0
  • Hotfix PR: Merged ✅
  • Release Branch: release/v0.54.0-preview.0-pr-28566

⏳ Status: The patch release has been triggered and is waiting for deployment approval. Please visit the specific workflow run link below and approve the deployment. You'll receive another update when it completes.

🔗 Track Progress:

@github-actions

Copy link
Copy Markdown

[Step 4/4] Patch Release Complete!

📦 Release Details:

  • Version: 0.53.1
  • NPM Tag: latest
  • Channel: stable
  • Dry Run: false

🎉 Status: Your patch has been successfully released and published to npm!

📝 What's Available:

🔗 Links:

@github-actions

Copy link
Copy Markdown

[Step 4/4] Patch Release Complete!

📦 Release Details:

🎉 Status: Your patch has been successfully released and published to npm!

📝 What's Available:

🔗 Links:

@tmtd4c93aac

Copy link
Copy Markdown

The changes have addressed all my comments. Thanks for fixing this 👍

@wissamblue69-dotcom

Copy link
Copy Markdown

Summary

This PR propagates specific InvalidStreamError details (the error type and message) from the core backend layers up to the CLI UI hooks. This allows the CLI to display highly relevant and helpful troubleshooting suggestions—such as recommending the use of /compress to reduce context size when the model returns an empty text response.

Details

  • Core Events (Turn/geminiChat): Updated the ServerGeminiInvalidStreamEvent type and the Turn run logic to pass the specific error type and message values in the event's value payload, instead of dropping this detail.
  • UI Stream Hook (useGeminiStream): Implemented handleInvalidStreamEvent to check if eventValue.type is 'NO_RESPONSE_TEXT', in which case we display a custom, friendly message recommending the use of /compress. Otherwise, we fall back to displaying the event's raw error message.
  • Testing:
    • Updated packages/cli/src/nonInteractiveCli.test.ts mock events to include the new value metadata.
    • Updated packages/core/src/agent/event-translator.test.ts to mock the correct payload structure.
    • Updated packages/core/src/core/turn.test.ts to expect the populated value payload on InvalidStream events.
    • Fixed pre-existing/broken tests in packages/core/src/core/geminiChat.test.ts to correctly mock/stub and run the mid-conversation stream retry flow when empty text responses are received.

Related Issues

Addresses #28351 .

How to Validate

Run unit tests in the core and CLI packages to verify the new behavior:

npm test -w @google/gemini-cli-core -- src/core/turn.test.ts
npm test -w @google/gemini-cli-core -- src/core/geminiChat.test.ts
npm test -w @google/gemini-cli -- src/nonInteractiveCli.test.ts

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

@wissamblue69-dotcom

Copy link
Copy Markdown

🚀 [Step 1/4] Patch workflow(s) waiting for approval!

📋 Details:

  • Channels: stable,preview
  • Commit: f47d6c6f7a1308d81f9f57acf7d279f0928c5249
  • Workflows Created: 2

⏳ Status: The patch creation workflow has been triggered and is waiting for deployment approval. Please visit the specific workflow links below and approve the runs.

🔗 Track Progress:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality priority/p1 Important and should be addressed in the near term. size/l A large sized PR size/m A medium sized PR size/xl An extra large PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants