Skip to content

fix(cli): skip output-history replay on terminal resize#21972

Open
29206394 wants to merge 1 commit into
NousResearch:mainfrom
29206394:fix/resize-no-replay
Open

fix(cli): skip output-history replay on terminal resize#21972
29206394 wants to merge 1 commit into
NousResearch:mainfrom
29206394:fix/resize-no-replay

Conversation

@29206394
Copy link
Copy Markdown

@29206394 29206394 commented May 8, 2026

Problem

#20444 引入的 _resize_clear_ghosts 机制在每次终端窗口 resize 时重放 _OUTPUT_HISTORY,导致一个严重体验问题:

最大化/还原终端窗口时,所有历史输出行(包括流式 token、spinner 帧)被快速重放一遍,视觉效果如同对话从头"重新流式输出"。

macOS 上用户习惯用 Command+Enter 切换窗口大小,这个重放非常突兀。

Root Cause

_recover_after_resize_replay_output_history()_OUTPUT_HISTORY 缓冲区(最多200行,包含 callable 条目如历史面板 lambda)全部重新送给 prompt_toolkit 输出。

Fix

删除 _recover_after_resize 中的 self._replay_output_history() 调用,只保留:

  1. self._clear_prompt_toolkit_screen() — 清除 SIGWINCH 后的鬼影
  2. self.renderer.reset() — 重置渲染器状态

prompt_toolkit 原生的 _on_resize 会自行重绘输入区和状态栏。

Ctrl+L 仍可手动恢复完整历史(_force_full_redraw 路径未受影响)。

Testing

  • 更新 tests/cli/test_cli_force_redraw.py 中的 resize 测试,不再期望 "replay" event
  • 57/57 相关测试通过

Related

_resize_clear_ghosts (introduced in NousResearch#20444) replays _OUTPUT_HISTORY after
every SIGWINCH to recover conversation content lost by the screen clear.
This causes a jarring "re-streaming" effect — all recent output lines,
including streaming tokens and spinner frames, are reprinted in rapid
succession whenever the user maximizes/restores the terminal window
(Command+Enter on macOS).

Change _recover_after_resize to only clear the screen + reset the
renderer, without replaying output history.  prompt_toolkit's native
_on_resize handler redraws the input area and status bar cleanly.

Users who want to see conversation history restored after resize can
still press Ctrl+L (/redraw), which calls _force_full_redraw (that path
still includes _replay_output_history).

Fixes the symptom reported in NousResearch#19280 where resize recovery replays
entire conversation as if it were streaming from the beginning.
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists labels May 11, 2026
@liw71750-dotcom
Copy link
Copy Markdown

This PR addresses one specific symptom of a broader issue: the CLI/TUI does not reflow content on terminal resize. There are 34+ open bugs about various manifestations of this problem.

I've opened a tracking feature request (#24164) that proposes a comprehensive solution — a SIGWINCH handler triggering full re-render at new viewport dimensions, comparable to how opencode and Claude Code handle resize smoothly.

If this PR gets merged, please consider whether the underlying architecture supports full reflow, or if we still need a systematic fix. The tracking issue consolidates all related work:

#24164

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.

3 participants