Skip to content

fix: preserve prompt text when cancelling streaming #21103

Merged
jacob314 merged 2 commits intogoogle-gemini:mainfrom
Nixxx19:nityam/fix-escape-clears-new-prompt
Mar 10, 2026
Merged

fix: preserve prompt text when cancelling streaming #21103
jacob314 merged 2 commits intogoogle-gemini:mainfrom
Nixxx19:nityam/fix-escape-clears-new-prompt

Conversation

@Nixxx19
Copy link
Contributor

@Nixxx19 Nixxx19 commented Mar 4, 2026

Summary

Fixes issue #13387 where pressing Escape to cancel streaming would delete any newly entered prompt text. The fix ensures prompts are never removed when cancelling, preserving user-entered text regardless of content.

Details

Previously, when cancelling streaming (onCancelSubmit(false)), the buffer was always cleared to an empty string, even if the user had typed new text. This was frustrating because users would type a new prompt while waiting for a response, then lose it when pressing Escape.

The fix changes the cancellation logic to never modify the buffer when cancelling - it simply returns early, preserving whatever text the user has typed, pasted, or restored. This aligns with the principle that users are in control of their prompts.

Changes:

  • Modified cancelHandlerRef in AppContainer.tsx to return early when shouldRestorePrompt=false, never touching the buffer
  • Updated existing test to reflect new behavior (buffer preserved even when empty)
  • Added regression test to verify prompt text is preserved when cancelling, even if it matches the last message

Related Issues

Fixes #13387

How to Validate

  1. Start a query that streams (e.g., "What is Python?")
  2. While it's streaming, type a new prompt (e.g., "Tell me about JavaScript")
  3. Press Escape once to cancel streaming
  4. Expected: The new prompt text should remain visible (not disappear)
  5. Also test: Type the same prompt as your last message, press Escape - it should still be preserved

Edge cases to verify:

  • Empty buffer + Escape → buffer stays empty (not cleared)
  • Buffer with text + Escape → text preserved
  • Buffer with same text as last message + Escape → text preserved

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any) - None
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@Nixxx19 Nixxx19 requested a review from a team as a code owner March 4, 2026 12:52
@gemini-code-assist
Copy link
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 significantly improves the user experience by preventing the loss of user-typed prompt text when streaming operations are cancelled. Previously, cancelling a stream would inadvertently clear the input buffer, leading to frustration. The updated logic ensures that the user's input is always retained, giving them full control over their prompt regardless of streaming status.

Highlights

  • Prompt Preservation on Cancel: Implemented a fix to ensure that newly entered prompt text is preserved when a user cancels streaming by pressing Escape, addressing issue Hitting Escape deletes newly entered prompt! #13387.
  • Cancellation Logic Update: Modified the cancelHandlerRef in AppContainer.tsx to return early when shouldRestorePrompt is false, preventing the buffer from being cleared during cancellation.
  • Test Coverage Enhanced: Updated an existing test case to reflect the new behavior of preserving the buffer even when empty, and added a new regression test to verify prompt text preservation when cancelling, including scenarios where the text matches the last message.
Changelog
  • packages/cli/src/ui/AppContainer.test.tsx
    • Updated the description of a test case to accurately reflect that the buffer is preserved, not cleared, when cancelling with an empty buffer.
    • Added a new regression test to verify that prompt text remains preserved when cancelling streaming, even if the text is identical to the last message.
  • packages/cli/src/ui/AppContainer.tsx
    • Introduced an early return in the cancelHandlerRef function when shouldRestorePrompt is false, ensuring the prompt buffer is not modified during cancellation.
    • Refined the condition for calling buffer.setText to only proceed when there is actual text to set, removing the redundant check for !shouldRestorePrompt.
Activity
  • The pull request author, Nixxx19, has provided a detailed summary, outlining the problem, solution, and validation steps.
  • The author has marked the relevant documentation and README as updated, and tests as added/updated, in the pre-merge checklist.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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
Copy link

github-actions bot commented Mar 4, 2026

You already have 7 pull requests open. Please work on getting existing PRs merged before opening more.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 addresses an issue where user input in the prompt is lost when cancelling a streaming response. The proposed fix correctly modifies the cancellation handler to preserve the text buffer, preventing data loss. The accompanying test changes validate the new behavior and include a regression test to prevent this issue in the future. The implementation is sound and effectively resolves the reported bug.

@jacob314 jacob314 reopened this Mar 4, 2026
@Nixxx19
Copy link
Contributor Author

Nixxx19 commented Mar 5, 2026

@jacob314 the pr is ready for review, i have tested it the issue is solved by this pr, thanks for re opening!

Copy link
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jacob314 jacob314 enabled auto-merge March 5, 2026 08:13
@Nixxx19
Copy link
Contributor Author

Nixxx19 commented Mar 10, 2026

hey @jacob314 @scidomino could you please rerun the failed job? It looks like a timeout issue unrelated to my changes. thanks!

@scidomino
Copy link
Collaborator

rerunning

@jacob314 jacob314 added this pull request to the merge queue Mar 10, 2026
Merged via the queue into google-gemini:main with commit e22d991 Mar 10, 2026
27 checks passed
@Nixxx19
Copy link
Contributor Author

Nixxx19 commented Mar 11, 2026

rerunning

thanks @scidomino @jacob314 !!

JaisalJain pushed a commit to JaisalJain/gemini-cli that referenced this pull request Mar 11, 2026
)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
yashodipmore pushed a commit to yashodipmore/geemi-cli that referenced this pull request Mar 21, 2026
)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hitting Escape deletes newly entered prompt!

3 participants