fix(cli): skip output-history replay on terminal resize#21972
Open
29206394 wants to merge 1 commit into
Open
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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