Skip to content

fix(core): retain ask_user question text in the tool result display - #29677

Open
elberthc-byte wants to merge 2 commits into
google-gemini:mainfrom
elberthc-byte:fix/ask-user-retain-question-29021
Open

elberthc-byte wants to merge 2 commits into
google-gemini:mainfrom
elberthc-byte:fix/ask-user-retain-question-29021

Conversation

@elberthc-byte

Copy link
Copy Markdown
Contributor

Summary

After answering an ask_user dialog, the completed tool block in the chat
history showed only the short header chip and the answer
(e.g. Retry Subagent → Yes). The question itself — which for yesno prompts
often carries the entire explanation — disappeared, leaving the human with no
context for the recorded decision, both in the live session and after
/resume.

This PR keeps the full question text in the Ask User result display, with the
answer nested beneath it.

Before

✓  Ask User

User answered:
  Retry Subagent → Yes

After

✓  Ask User

User answered:
  Retry Subagent: The subagent failed because the build step timed out. Would you like to retry it?
    → Yes

Details

Root cause — two independent decisions combine to drop the information:

  1. ToolInfo (packages/cli/src/ui/components/messages/ToolShared.tsx)
    deliberately hides the tool description (Asking user: …) once an Ask User
    call reaches a terminal status, on the assumption that "the result display
    speaks for itself" (feat: wire up AskUserTool with dialog #17411).
  2. AskUserInvocation.execute() (packages/core/src/tools/ask-user.ts) built
    returnDisplay from only question.header (a ≤16-char chip label) plus the
    answer; question.question was never emitted.

Once the modal closes, no rendered surface contains the question text.

Fix — a formatting-only change in AskUserInvocation.execute():

  • Each answered question is rendered as <header>: <question> followed by
    → <answer>. Multi-line questions/answers keep their continuation lines
    aligned, and multiple questions are unambiguously paired with their answers.
  • The defensive fallback for an answer index without a matching question
    (Q<index>) is preserved.
  • llmContent (what the model receives) and the telemetry data payload are
    unchanged, so there is no impact on model behaviour or metrics.
  • Because /resume rebuilds tool blocks from the persisted resultDisplay,
    resumed sessions retain the question as well.

Design decision — this intentionally does not add a settings toggle
(unlike the earlier attempt in #29022, which touched 10 files to plumb a
ui.keepAskUserQuestionsInHistory flag through Config). There is no scenario
in which hiding the question benefits the person reading the scrollback, and the
cost is one extra line per answered question. Default-on keeps the change
surgical and avoids settings-schema/docs churn.

The lines are rendered through the existing Markdown path; the leading spaces and
→ prefix are plain text (not list markers), verified by rendering through
ToolGroupMessage with Ink.

Related Issues

Fixes #29021
Related to #29022 (previous attempt, closed as stale)

How to Validate

  1. Unit tests (includes a regression test mirroring the reporter's scenario,
    plus coverage for multi-question pairing, multi-line answers, multi-line
    questions, and the positional fallback):

    npm test -w @google/gemini-cli-core -- src/tools/ask-user.test.ts

    Expected: 35 tests pass. On main, the regression test
    should retain the question text in returnDisplay after answering (#29021)
    fails with expected '**User answered:**\n Retry Subagent …' to contain 'The subagent failed because the build…'.

  2. Manual check:

    npm run build && npm start

    Prompt: Use the ask_user tool to ask me a yes/no question whose text explains that a build timed out and asks whether to retry. Answer the
    dialog. The completed Ask User block should now show
    Retry: <full question text> followed by → Yes. Run /resume on the
    session afterwards and confirm the question is still visible.

  3. Edge cases covered by tests: multiple questions (each paired with its answer,
    in order), multi-line text answers (continuation lines aligned under the
    answer), multi-line questions (continuation lines indented), and an answer
    whose index has no matching question (Q<index> fallback).

Local CI parity: npm run preflight (clean, install, format, build, all
linters, typecheck, test:ci) passes.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed) — not needed:
    docs/tools/ask-user.md documents parameters and llmContent, neither of
    which changed.
  • Added/updated tests (if needed)
  • Noted breaking changes (if any) — none; display string only.
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

Once the AskUser dialog closes, the CLI hides the tool description for
completed Ask User calls, so the result display becomes the only record
of the interaction. It previously contained only the short header chip
and the answer (e.g. "Retry Subagent → Yes"), losing the question (and
any explanation it carried) from the chat history and from resumed
sessions.

Include the full question text, prefixed by its header, with the answer
nested beneath it:

  **User answered:**
    Retry Subagent: The build timed out. Would you like to retry it?
      → Yes

llmContent and telemetry data are unchanged.

Fixes google-gemini#29021
@elberthc-byte
elberthc-byte requested a review from a team as a code owner October 8, 2026 04:05
@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 improves the usability of the ask_user tool by ensuring that the original question text is retained in the tool's result display. Previously, the UI only showed a short header and the answer, which often lacked sufficient context for the user. By modifying the returnDisplay generation logic, the full question is now displayed, providing a clearer record of interactions that persists across session resumes.

Highlights

  • Enhanced Ask User display: Updated the ask_user tool result display to include the full question text alongside the user's answer, ensuring context is preserved in the chat history and after session resumes.
  • Improved formatting: Refactored the display logic to support multi-line questions and answers, ensuring proper indentation and alignment for better readability.
  • Regression testing: Added comprehensive unit tests to verify the new display format, including edge cases like multi-line inputs and orphaned answers.
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 Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 207
  • Additions: +199
  • Deletions: -8
  • Files changed: 2

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

@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 updates the AskUserTool to retain and format the full question text along with its answer in the returnDisplay output, ensuring context is preserved after the dialog closes. It also adds comprehensive unit tests to verify various formatting scenarios, including multi-line questions and answers. Feedback on these changes suggests improving robustness by safely handling cases where question.header is missing or whitespace-only, and defensively handling potentially null or undefined answer values to prevent runtime crashes.

Comment thread packages/core/src/tools/ask-user.ts Outdated
Address review feedback: fall back to the positional label when the
header is whitespace-only (the previous `??` fallback never caught empty
strings), degrade to just the label when the question text is missing,
and guard the answer before splitting it into lines.
@elberthc-byte

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 updates the AskUserTool to retain the full question text in the returnDisplay output after a user answers, ensuring the context of the question is preserved even after the UI dialog closes. It also improves formatting for multi-line questions and answers, adds fallback handling for orphaned answers or empty headers, and introduces comprehensive unit tests to verify these formatting behaviors and prevent regressions. There are no review comments, and I have no feedback to provide.

@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Oct 8, 2026

This branch is waiting to be deployed

1 waiting deployment
eval-gate — dbe33ad3 Waiting Oct 8, 2026 by elberthc-byte via Evaluate Steering & Regressions #2156
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 size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ask_user tool should retain question in chat history for human context purposes

1 participant