fix(cli): route interactive slash commands inline to prevent CLI freeze - #23604
Closed
mcndjxlefnd wants to merge 1 commit into
Closed
fix(cli): route interactive slash commands inline to prevent CLI freeze#23604mcndjxlefnd wants to merge 1 commit into
mcndjxlefnd wants to merge 1 commit into
Conversation
/new, /clear, /undo, /reset, and /reload-mcp call _prompt_text_input which must run on the UI thread so prompt_toolkit's run_in_terminal works instead of falling back to a daemon-thread input() that races with stdin and freezes the terminal. Mirrors the existing /model inline dispatch pattern by introducing _should_handle_interactive_slash_inline, gated by a frozenset of commands that need the UI thread for user interaction. Fixes the regression introduced in b9c0011 (feat: confirm prompt for destructive slash commands) where the confirmation prompt was dispatched from the process_loop daemon thread, causing a stdin race identical to the one fixed for tools/approval.py in PR NousResearch#16477.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
/new,/clear,/undo,/reset, and/reload-mcpcall_confirm_destructive_slashwhich calls_prompt_text_inputto ask the user for confirmation. These commands are dispatched from theprocess_loopdaemon thread where_prompt_text_inputfalls back to a bareinput()call — but prompt_toolkit owns stdin in raw mode on the main thread, causing a stdin race that freezes the terminal.This is identical to the deadlock fixed for
tools/approval.pyin PR #16477.Root cause
Commit
b9c001116introduced_confirm_destructive_slashusing the_prompt_text_inputpattern from_confirm_and_reload_mcp. Commitc5f1f863aadded the daemon-threadinput()fallback to_prompt_text_inputwhich inadvertently enabled this race condition for destructive slash commands.Fix
Route interactive slash commands inline on the UI thread — exactly like
/modelalready does. This lets_prompt_text_inputuserun_in_terminalinstead of the broken daemon-threadinput()fallback._INTERACTIVE_SLASH_COMMANDSfrozenset with the 6 commands that call_prompt_text_input:model,new,clear,undo,reset,reload-mcp_should_handle_interactive_slash_inline()gate methodTesting
tests/cli/test_interactive_slash_inline_routing.pyverify each command routes inline and non-interactive commands do notCloses the freeze regression from PR #22687 / issue #4069.