Skip to content

fix: restore AskUser answers after Ctrl+Z + fg suspend/resume#20881

Closed
PrafulVRaj wants to merge 4 commits intogoogle-gemini:mainfrom
PrafulVRaj:fix/ask-user-input-lost
Closed

fix: restore AskUser answers after Ctrl+Z + fg suspend/resume#20881
PrafulVRaj wants to merge 4 commits intogoogle-gemini:mainfrom
PrafulVRaj:fix/ask-user-input-lost

Conversation

@PrafulVRaj
Copy link
Copy Markdown

@PrafulVRaj PrafulVRaj commented Mar 2, 2026

Summary

Fix loss of in-progress AskUser answers when the user suspends gemini-cli with Ctrl+Z and resumes with fg. Answers typed before suspension are now fully restored on resume.

Details

A way for AskUserDialog to register a function that returns its current answers. AppContainer stores those answers before suspension using onBeforeSuspend. When the dialog mounts again, it initializes its reducer with the saved answers. New methods were added to UIActionsContext: savedAskUserAnswers, registerAskUserAnswers, unregisterAskUserAnswers. useSuspend now supports an optional onBeforeSuspend callback.

It achieves pressing Ctrl+Z no longer resets AskUser dialog inputs, answers are saved before suspend and restored after resume. Dialog still owns its state (no unnecessary global state lifting) and clean separation of concerns using context + refs.

Related Issues

Fixes #20838

How to Validate

Windows:

  1. Run gemini CLI
  2. Trigger an AskUser dialog
  3. Press Ctrl+Z
  4. Verify warning appears: "Ctrl+Z suspend is not supported on Windows."
  5. Verify the dialog and typed text are unaffected ✓

macOS / Linux:
same as win but some difference

  1. Press Ctrl+Z once — verify warning: "Press Ctrl+Z again to suspend"
  2. Press Ctrl+Z again — CLI suspends, shell prompt returns
  3. Run fg to resume
  4. Verify your typed answer is fully restored ✓

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

@PrafulVRaj PrafulVRaj requested a review from a team as a code owner March 2, 2026 20:16
@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 addresses a critical bug in the gemini-cli where in-progress user answers in AskUserDialog were lost after suspending the application with Ctrl+Z and then resuming it. The fix ensures that user input is fully restored upon resuming the CLI, significantly improving the user experience for interactive prompts by preventing unexpected data loss.

Highlights

  • State Preservation: Implemented a mechanism to preserve user-typed answers in AskUserDialog after suspending and resuming the gemini-cli application.
  • Signal Handling: Added SIGTSTP and SIGCONT signal handlers to manage application suspension and resume events, specifically for non-Windows platforms.
  • Component Re-keying: Utilized a resumeKey to force re-mounting of TextQuestionView and ChoiceQuestionView components upon resume, preventing loss of their internal state.
Changelog
  • packages/cli/src/ui/components/AskUserDialog.tsx
    • Imported the useState React hook.
    • Introduced a resumeKey state variable initialized to 0.
    • Added a useEffect hook to register signal handlers for SIGTSTP and SIGCONT.
    • Implemented logic to increment resumeKey when a SIGCONT signal is received, indicating a resume from suspension.
    • Updated the key prop for TextQuestionView and ChoiceQuestionView components to include the resumeKey, forcing a re-render and state restoration upon resume.
Activity
  • The author has updated tests to reflect the changes.
  • No breaking changes were noted by the author.
  • Validation has been performed on Windows, MacOS, and Linux using npm run and npx.
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.

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

The pull request effectively addresses the issue of losing in-progress AskUser answers when the CLI is suspended and resumed. By introducing a resumeKey that increments on SIGCONT and using it in the key prop of TextQuestionView and ChoiceQuestionView, the components are correctly remounted, ensuring their internal state is re-initialized with the preserved answers. The use of useEffect for signal handling and useState for the key is a standard and appropriate React pattern for this scenario. The solution is well-implemented and directly resolves the problem described.

@gemini-cli gemini-cli bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Mar 2, 2026
@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Mar 4, 2026
@PrafulVRaj PrafulVRaj closed this Mar 6, 2026
@PrafulVRaj PrafulVRaj force-pushed the fix/ask-user-input-lost branch from 5b16770 to 5575c5f Compare March 6, 2026 04:45
@PrafulVRaj PrafulVRaj deleted the fix/ask-user-input-lost branch March 6, 2026 04:52
@PrafulVRaj PrafulVRaj restored the fix/ask-user-input-lost branch March 6, 2026 14:37
@PrafulVRaj PrafulVRaj reopened this Mar 6, 2026
@jackwotherspoon
Copy link
Copy Markdown
Collaborator

Closing to allow other PR created before this to fix the issue 👍

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 help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CTRL-z removes unfinished open questions in AskUser tool

2 participants