Skip to content

fix(cli): clear pending steering hints upon cancellation#26134

Closed
JayadityaGit wants to merge 6 commits into
google-gemini:mainfrom
JayadityaGit:fix/steering-hint-cancellation
Closed

fix(cli): clear pending steering hints upon cancellation#26134
JayadityaGit wants to merge 6 commits into
google-gemini:mainfrom
JayadityaGit:fix/steering-hint-cancellation

Conversation

@JayadityaGit
Copy link
Copy Markdown
Contributor

@JayadityaGit JayadityaGit commented Apr 28, 2026

Summary

This PR fixes a bug where cancelling a turn (via ESC or Ctrl+C) would immediately resubmit any pending user steering hints as a new turn.

Details

The AppContainer maintains a buffer of pending steering hints that have not yet been submitted. When a turn is active, these hints are queued. If the turn is cancelled, the state returns to Idle. A useEffect in AppContainer monitors the Idle state and, if it finds pending hints, automatically submits them.

This change updates the cancelOngoingRequest handler in both useGeminiStream and useAgentStream to consume (clear) the pending hint buffer during cancellation, preventing the unwanted automatic resubmission.

Related Issues

Fixes #26133

How to Validate

  1. Run the CLI in a mode where you can trigger a long-running tool (e.g., sleep 10 in a shell).
  2. While the tool is running, type a steering hint and press Enter.
  3. Press ESC or Ctrl+C to cancel the turn.
  4. Expected: The turn cancels, and you are returned to a clean prompt.
  5. Observed (before fix): The turn cancels, but then immediately a new turn starts with your steering hint.

Automated tests:
npm test -w @google/gemini-cli -- src/ui/hooks/useGeminiStream.test.tsx src/ui/hooks/useAgentStream.test.tsx

Meme

ZomboMeme 28042026234311.jpg

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:
    • Linux
      • npm run

@JayadityaGit JayadityaGit requested a review from a team as a code owner April 28, 2026 17:34
@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 resolves a user experience bug in the CLI where cancelling an active turn inadvertently triggered a new turn with previously entered steering hints. The changes ensure that any buffered user input is properly discarded when a cancellation occurs, leading to a cleaner and more predictable interaction flow for users.

Highlights

  • Bug Fix: Addressed an issue where cancelling an active turn in the CLI would cause pending user steering hints to be immediately resubmitted as a new turn.
  • Hint Consumption: Modified cancelOngoingRequest handlers in useGeminiStream and useAgentStream to clear the pending user hint buffer upon cancellation.
  • Test Coverage: Added new test cases to useAgentStream.test.tsx and useGeminiStream.test.tsx to verify that pending user hints are consumed when a request is cancelled.
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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are adding consumeUserHint() in the useGeminiStream, so that pending steering hints will be cleared upon user request to cancel via ctrl+c or esc

Copy link
Copy Markdown
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 introduces a mechanism to clear pending user hints when an ongoing request is cancelled or interrupted in the Gemini CLI. The changes include adding a consumeUserHint callback to the useAgentStream and useGeminiStream hooks, updating the cancellation logic to invoke this callback, and adding corresponding unit tests. I have provided a suggestion to reorder the operations in useGeminiStream.ts to ensure the hint buffer is cleared before triggering state transitions, which helps prevent potential race conditions.

Note: Security Review is unavailable for this PR.

Comment thread packages/cli/src/ui/hooks/useGeminiStream.ts
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we are doing the same as in the useGeminiStream, but this file is responsible for when the cli is managing the subagents, and there is a pending steering hint in this scenario

@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented May 6, 2026

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.

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality labels May 8, 2026
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented May 13, 2026

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.

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/p2 Important but can be addressed in a future release. size/m A medium sized PR status/pr-nudge-sent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug : Steering hint cancellation resubmits hint as new turn

2 participants