Skip to content

fix(cli): clear TUI input buffer before dispatching inline /steer#34573

Open
Bartok9 wants to merge 1 commit into
NousResearch:mainfrom
Bartok9:fix/steer-input-buffer-34569
Open

fix(cli): clear TUI input buffer before dispatching inline /steer#34573
Bartok9 wants to merge 1 commit into
NousResearch:mainfrom
Bartok9:fix/steer-input-buffer-34569

Conversation

@Bartok9

@Bartok9 Bartok9 commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Clear the TUI input field before dispatching an inline /steer, so the submitted prompt can never linger in the buffer.
  • Fixes the workflow hazard where a steered prompt could be accidentally re-submitted on the next Enter or turn-handoff.

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. 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 — 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 running process_command(). This makes the TUI's input-state contract — "what's in the box hasn't been sent" — hold unconditionally, regardless of how process_command behaves. 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)
  • New tests:
    • test_buffer_cleared_before_dispatch — asserts the buffer is empty at the moment process_command runs, the submitted text was appended to history, the steer still reaches agent.steer(), and the final buffer is empty.
    • test_buffer_cleared_even_if_dispatch_raises — asserts the buffer is still cleared when process_command raises (the exact case a post-dispatch reset would miss).
  • Did NOT change: steer semantics, the idle-path / queue / interrupt fallbacks, or the detector gate — only the ordering of the buffer reset relative to dispatch on the inline path.

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 does buffer.reset(append_to_history=True) then process_command(text).

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels May 29, 2026
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
@Bartok9 Bartok9 force-pushed the fix/steer-input-buffer-34569 branch from c5ad7e8 to 476d78f Compare May 31, 2026 08:07
@Bartok9

Bartok9 commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current origin/main (32899279a). Collapsed to the single targeted commit; resolved the cli.py overlap with the inline #34569 reset that landed on main by routing through the _dispatch_inline_steer() helper (resets the buffer before process_command()) while keeping main's post-dispatch invalidate() repaint. 9/9 tests in tests/cli/test_cli_steer_busy_path.py pass.

@Bartok9

Bartok9 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

Re-verified against current main: mergeable: MERGEABLE, mergeStateStatus: CLEAN, all 19 checks green (no drift since the last rebase). Scope unchanged at 2 files, +99/−2 — the _dispatch_inline_steer() helper clears the TUI input buffer before process_command() while preserving main's post-dispatch invalidate() repaint from #34569. Ready for maintainer merge whenever convenient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/steer leaves submitted prompt in TUI input buffer, allows accidental re-submit

2 participants