fix: restore terminal state on abnormal exit#1
Open
Ivaloz wants to merge 2 commits into
Open
Conversation
added 2 commits
June 12, 2026 10:09
Add signal handlers for SIGINT, SIGTERM, and beforeExit to ensure terminal cleanup (raw mode, alternate screen buffer) happens even when the process is killed by model errors or external signals. Fixes: Terminal scrolling persists after CTRL+C exit, and session resume crashes due to corrupted terminal state.
Sync from upstream PR XiaomiMiMo#274 (whitelonng): - setupProjectIdEnvironment: tolerate filesystem errors on Windows - Log rotation: cap at 20MB per file, keep 10 files max (~200MB total) - Update cleanup glob pattern to match rotated filenames Fixes XiaomiMiMo#243, XiaomiMiMo#209, XiaomiMiMo#219
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.
问题描述
当模型返回 "Internal error" 导致进程异常退出时,终端状态未正确恢复,导致:
根因分析
exit.tsx中只处理了SIGHUP信号,没有处理SIGINT和SIGTERM。当模型错误导致进程被杀时,终端清理逻辑(raw mode、alternate screen buffer)不会执行。修复方案
1.
packages/opencode/src/cli/cmd/tui/context/exit.tsx添加信号处理器,确保异常退出时执行清理:
2.
packages/opencode/src/cli/cmd/tui/thread.ts在 Worker 线程中添加信号处理,确保子进程清理:
测试
环境