fix(cli): clear TUI input buffer before dispatching inline /steer#34573
fix(cli): clear TUI input buffer before dispatching inline /steer#34573Bartok9 wants to merge 1 commit into
Conversation
When /steer <prompt> is submitted while the agent is working, the Enter
handler dispatched the command and only then reset the input buffer. If
process_command() re-entered the prompt_toolkit event loop (a print routed
through run_in_terminal, or a modal that snapshots+restores the in-progress
draft) or raised before returning, the post-dispatch reset was skipped and
the submitted prompt lingered in the input field — where the next Enter or
turn-handoff re-sent it.
Route the inline-steer case through a new _dispatch_inline_steer() helper
that resets the buffer BEFORE running process_command(), so the TUI's
input-state contract ('what's in the box hasn't been sent') holds
unconditionally. Add regression tests covering the normal path and the
exception path.
Closes NousResearch#34569
c5ad7e8 to
476d78f
Compare
|
Rebased onto current |
|
Re-verified against current |
Summary
/steer, so the submitted prompt can never linger in the buffer.Motivation
Closes #34569.
When
/steer <prompt>is submitted while the agent is working, the Enter handler dispatched the command and reset the input buffer afterward. Ifprocess_command()re-entered the prompt_toolkit event loop (a print routed throughrun_in_terminal, or a modal that snapshots+restores the in-progress draft) or raised before returning, the post-dispatchreset()was skipped — leaving the submitted prompt sitting in the input field. The next Enter (or the auto-resume / next-turn handoff) could then re-send it, which is the opposite of/steer's mid-run-injection purpose.The fix routes the inline-steer case through a small
_dispatch_inline_steer()helper that resets the buffer before runningprocess_command(). This makes the TUI's input-state contract — "what's in the box hasn't been sent" — hold unconditionally, regardless of howprocess_commandbehaves. As a bonus, because the buffer is now empty before any modal opens, the modal draft snapshot/restore path (_capture_modal_input_snapshot/_restore_modal_input_snapshot) can no longer resurrect the submitted steer text.This matches the existing post-submit clear contract that normal prompts already get, and addresses the issue's hypothesis #3 (race between async steer consumption and the synchronous buffer clear).
Verification
python3 -m pytest tests/cli/test_cli_steer_busy_path.py— 9 passed (7 existing + 2 new)test_buffer_cleared_before_dispatch— asserts the buffer is empty at the momentprocess_commandruns, the submitted text was appended to history, the steer still reachesagent.steer(), and the final buffer is empty.test_buffer_cleared_even_if_dispatch_raises— asserts the buffer is still cleared whenprocess_commandraises (the exact case a post-dispatch reset would miss).Notes
The change is a single small refactor: the inline-steer block in the Enter handler now calls
self._dispatch_inline_steer(buffer, text), which doesbuffer.reset(append_to_history=True)thenprocess_command(text).