fix(approval): route fallback input() through prompt_toolkit run_in_terminal to fix deadlock - #16477
Closed
Feranmi10 wants to merge 0 commit into
Closed
fix(approval): route fallback input() through prompt_toolkit run_in_terminal to fix deadlock#16477Feranmi10 wants to merge 0 commit into
Feranmi10 wants to merge 0 commit into
Conversation
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.
What does this PR do?
Fixes the deadlock in
tools/approval.pywhereget_inputwas called from a background thread whileprompt_toolkit'sApplication.run()was already running on MainThread. Both competed for stdin, causing the approval prompt to freeze with no way to typeo/s/d.Root cause: In subagent/delegate threads,
_callback_tls.approvalisNonebecause TLS doesn't propagate to child threads. This causedprompt_dangerous_approvalto fall through to its rawinput()fallback — which deadlocked with prompt_toolkit's own stdin reader.Fix — two changes in
tools/approval.py:_try_pt_run_in_terminal(func, timeout)helper that detects a live prompt_toolkit Application via_current_appContextVar, schedules an async_schedule()coroutine viaasyncio.run_coroutine_threadsafe, then inside_schedule, callsapp.run_in_terminal(func)— the non-executor path that detaches prompt_toolkit's stdin reader and restores cooked mode before callingfunc, eliminating the stdin race.prompt_dangerous_approvalfallback to call_try_pt_run_in_terminalfirst; falls back to the original daemon-thread +input()approach only whenNoneis returned (no live Application — non-TUI paths, tests, cron).Related Issue
Fixes #15216
Type of Change