fix(tui-v2): skip ask_user picker when candidates list is empty (closes #615)#655
Open
Kailigithub wants to merge 1 commit into
Open
Conversation
lsdefine#615) v2 parity with tui_v3 (dfab299). When ask_user is called with candidates=[], mounting an empty ChoiceList still calls .focus() on mount and steals keyboard focus from the text input. Early-return at the drain layer. Verified via tests/test_tuiapp_v2_ask_user_drain.py (3 cases, all failing on main without this fix and passing with it).
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.
Summary
Issue #615: when
ask_useris called withcandidates=[],_drain_ask_user_eventsinfrontends/tuiapp_v2.pystill mounted aChoiceList containing only the "Type something" free-text escape hatch.
That widget calls
.focus()on mount, which steals keyboard focus fromthe text input. The agent's empty-candidate prompt then becomes
unreachable from the keyboard.
Fix
Add a defensive early-return at the drain layer when
candidatesisempty, mirroring
tui_v3commitdfab299. The'Waiting for your answer ...'marker is already in scrollback as part of the assistantstream, so the user replies via the normal input box without a
redirected picker.
Note:
_install_ask_user_hookalready filters empty candidates at theproducer side (line 3983). This drain-side guard is belt-and-suspenders
— any future producer that bypasses the hook (or a stale event pushed
before the hook was installed) will still be safe.
Diff
Verification
tests/test_tuiapp_v2_ask_user_drain.pycovers three cases:candidates=[]→ noChatMessageappended (bug case)candidates=['A','B']→ exactly one picker mounted, with thefree-text escape hatch appended (happy-path regression)
candidates=[]with[多选]marker → still skipped (multi phrasingmust not bypass the guard)
The first test fails on
main(mounts the empty ChoiceList) and passeswith this fix, confirming the regression test catches the bug.
Closes #615