Skip to content

fix(cli): preserve chat -q answer by gating exit-summary screen clear (#53009) - #53025

Closed
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/53009-chat-q-clear
Closed

fix(cli): preserve chat -q answer by gating exit-summary screen clear (#53009)#53025
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/53009-chat-q-clear

Conversation

@Tranquil-Flow

Copy link
Copy Markdown
Contributor

What

hermes chat -q "<prompt>" prints the assistant's final answer and then
wipes it off the screen a fraction of a second later. What remains is only
the exit summary. The answer was generated and persisted, but never visible.

Root cause

_print_exit_summary() unconditionally calls _clear_terminal_on_exit(),
which writes ESC[3J ESC[2J ESC[H — clearing scrollback and the visible
screen. In single-query (-q) mode there is no prompt_toolkit chrome to tear
down, so the clear destroys real user-visible output.

Fix

Gate the screen clear behind a clear_screen: bool = True parameter on
_print_exit_summary():

All three call sites of _print_exit_summary() verified:
main() single-query (15518 → False), run() stdin-failure path (14770 →
default), run() interactive teardown (14922 → default).

Test plan

4 regression tests in tests/cli/test_chat_q_exit_clear.py:

Test Verifies
test_print_exit_summary_clears_screen_by_default Default still clears (preserves #38928)
test_print_exit_summary_skips_clear_when_clear_screen_false False skips the clear
test_single_query_main_skips_clear_on_exit_summary Single-query -q path passes False end-to-end
test_print_exit_summary_still_clears_in_interactive_path Interactive mode still clears
4 passed in 0.14s

Fail-without-fix proven: tests fail on upstream/main (TypeError: unexpected keyword argument 'clear_screen', assertion True != False).

Closes #53009.


Auto-published by Moonsong via Path B automated pipeline.

…NousResearch#53009)

In single-query (-q) mode, the assistant's final answer was printed and
then immediately erased by _print_exit_summary() — which unconditionally
called _clear_terminal_on_exit() (ESC[3J ESC[2J ESC[H]). The answer was
present in the session store but invisible in the terminal.

The clear is only needed for interactive TUI teardown (NousResearch#38928) where
prompt_toolkit chrome must be cleaned up. Add a clear_screen parameter
to _print_exit_summary() (default True, preserving interactive behavior)
and pass False from the single-query call site so the answer stays
visible above the exit summary.

Regression tests cover:
- clear_screen=True (default) calls _clear_terminal_on_exit()
- clear_screen=False skips the clear
- Single-query -q path passes False end-to-end
- Interactive path still clears (preserving NousResearch#38928)
@teknium1

teknium1 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Merged via #60926 - your commit was cherry-picked onto current main with authorship preserved in git log; we added a small follow-up updating the stale FakeCLI test stub that was failing your CI. Fixes #53009. Thanks!

@teknium1 teknium1 closed this Jul 8, 2026
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 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.

[Bug]: chat -q final response is erased instantly by the exit-summary screen clear in a TTY

3 participants