From 00a5176773a897828c9011172f2e503fc57e4e8b Mon Sep 17 00:00:00 2001 From: niho2 <115228830+niho2@users.noreply.github.com> Date: Wed, 26 Aug 2026 17:19:19 +0200 Subject: [PATCH] fix(tui): skip question reject when dialog is open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guard ESC and app.exit handlers in QuestionPrompt to skip reject() when a dialog is currently open (dialog.stack.length > 0). This prevents the question from being rejected while the user is closing a dialog such as the model picker. Previously, pressing ESC with both a dialog and a pending question would fire both handlers simultaneously — closing the dialog and rejecting the question. The agent's execution was interrupted and the question disappeared. Fixes #45304 --- packages/tui/src/routes/session/question.tsx | 23 ++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/tui/src/routes/session/question.tsx b/packages/tui/src/routes/session/question.tsx index 5ab467a351d3..5c36f4d2a799 100644 --- a/packages/tui/src/routes/session/question.tsx +++ b/packages/tui/src/routes/session/question.tsx @@ -8,6 +8,7 @@ import { useSDK } from "../../context/sdk" import { SplitBorder } from "../../ui/border" import { useTuiConfig } from "../../config" import { useBindings, useOpencodeModeStack } from "../../keymap" +import { useDialog } from "../../ui/dialog" const QUESTION_MODE = "question" @@ -17,6 +18,7 @@ export function QuestionPrompt(props: { request: QuestionRequest; directory?: st const renderer = useRenderer() const tuiConfig = useTuiConfig() const modeStack = useOpencodeModeStack() + const dialog = useDialog() const questions = createMemo(() => props.request.questions) const single = createMemo(() => questions().length === 1 && questions()[0]?.multiple !== true) @@ -220,6 +222,7 @@ export function QuestionPrompt(props: { request: QuestionRequest; directory?: st title: "Reject question", category: "Question", run() { + if (dialog.stack.length > 0) return reject() }, }, @@ -250,7 +253,15 @@ export function QuestionPrompt(props: { request: QuestionRequest; directory?: st ...(confirm() ? [ { key: "return", desc: "Submit answer", group: "Question", cmd: () => submit() }, - { key: "escape", desc: "Reject question", group: "Question", cmd: () => reject() }, + { + key: "escape", + desc: "Reject question", + group: "Question", + cmd: () => { + if (dialog.stack.length > 0) return + reject() + }, + }, ...tuiConfig.keybinds.get("app.exit"), ] : [ @@ -278,7 +289,15 @@ export function QuestionPrompt(props: { request: QuestionRequest; directory?: st { key: "down", desc: "Next answer", group: "Question", cmd: () => moveTo((store.selected + 1) % total) }, { key: "j", desc: "Next answer", group: "Question", cmd: () => moveTo((store.selected + 1) % total) }, { key: "return", desc: "Select answer", group: "Question", cmd: () => selectOption() }, - { key: "escape", desc: "Reject question", group: "Question", cmd: () => reject() }, + { + key: "escape", + desc: "Reject question", + group: "Question", + cmd: () => { + if (dialog.stack.length > 0) return + reject() + }, + }, ...tuiConfig.keybinds.get("app.exit"), ]), ],