fix(cli): skip output-history replay on terminal resize#21972
Conversation
_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.
|
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: |
|
Closing as superseded — the same end-state landed via #25227 / commit e2b2d48. Current |
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()调用,只保留:self._clear_prompt_toolkit_screen()— 清除 SIGWINCH 后的鬼影self.renderer.reset()— 重置渲染器状态prompt_toolkit 原生的
_on_resize会自行重绘输入区和状态栏。Ctrl+L 仍可手动恢复完整历史(
_force_full_redraw路径未受影响)。Testing
tests/cli/test_cli_force_redraw.py中的 resize 测试,不再期望"replay"eventRelated