Skip to content

fix: disable mouse tracking on abnormal exit to prevent terminal garbage#1503

Open
Ivaloz wants to merge 3 commits into
XiaomiMiMo:mainfrom
Ivaloz:fix/1458-mouse-tracking-cleanup
Open

fix: disable mouse tracking on abnormal exit to prevent terminal garbage#1503
Ivaloz wants to merge 3 commits into
XiaomiMiMo:mainfrom
Ivaloz:fix/1458-mouse-tracking-cleanup

Conversation

@Ivaloz

@Ivaloz Ivaloz commented Jul 1, 2026

Copy link
Copy Markdown

Summary

When MiMo-Code exits abnormally (crash, external kill, Ctrl+C), the terminal mouse tracking modes were not being reset. This caused the terminal to continuously output SGR mouse coordinate sequences like [555;106;49M\ when moving the mouse after exit, making the terminal unusable.

  • Add cross-platform \disableMouseTracking()\ function that sends CSI sequences to turn off all mouse tracking modes (X10, VT200, button-event, any-event, SGR)
  • Register \process.on('exit')\ handler to ensure cleanup runs even on abnormal exits
  • Call \disableMouseTracking()\ in the normal shutdown path as well

Test Plan

  1. Start MiMo-Code TUI
  2. Force kill the process (or trigger a crash)
  3. Move mouse in terminal - should NOT see [555;row;colM\ garbage output
  4. Verify normal exit still works correctly

Fixes #1458

Bin added 3 commits July 1, 2026 09:06
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.
When MiMo-Code exits abnormally (crash, external kill, Ctrl+C), the
terminal mouse tracking modes (X10, VT200, button-event, any-event, SGR)
were not being reset. This caused the terminal to continuously output
SGR mouse coordinate sequences like [555;106;49M when moving the mouse
after exit.

Fix by:
1. Adding a cross-platform disableMouseTracking() function that sends
   the appropriate CSI sequences to turn off all mouse tracking modes
2. Registering a process.on('exit') handler to ensure cleanup runs
   even on abnormal exits
3. Calling disableMouseTracking() in the normal shutdown path as well

Fixes XiaomiMiMo#1458
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: mimo-code异常退出后终端鼠标事件泄露,CLI出现SGR坐标乱码

1 participant