Repository navigation
fix(terminal): clear leaked mouse-reporting modes on pane reattach - #7893
Conversation
A TUI that enables mouse tracking (?1000/1002/1003 + SGR 1006/1016) and dies uncleanly never emits the disable sequence, so the daemon's snapshot records the mode and buildRehydrateSequences re-arms it on every reattach. POST_REPLAY_REATTACH_RESET cleared cursor/focus/kitty state but not mouse modes, so a plain shell in the reattached pane echoed every pointer-motion report (`<35;col;rowM`) as literal text. Add RESET_MOUSE_REPORTING (?9l ?1000l ?1002l ?1003l ?1006l ?1016l) to both POST_REPLAY_REATTACH_RESET and POST_REPLAY_MODE_RESET. Live agent panes keep mouse modes via POST_REPLAY_LIVE_AGENT_REATTACH_RESET, so agent scroll is unaffected. Verified against the real daemon serializer + real xterm: the old reset leaves mouseTrackingMode armed, the new reset returns it to 'none'.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis change fixes leaked terminal mouse-reporting modes after replay and reattach. A new 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- Add an E2E test to verify that a warm reattach disarms mouse modes left armed by an uncleanly exited TUI. - Add a test fixture that writes the mouse tracking enable sequence without a matching disable sequence. - Ensure the reattached pane disarms mouse tracking and that actual mouse movement produces no reports.
Explicitly annotate parameter and return types for the isMouseReport helper function inside the page.evaluate block.
Eliminate the external Node.js fixture file and streamline the E2E test by using a POSIX printf shell builtin to arm the mouse tracking modes. Additionally, verify the leak precondition by inspecting the active pane's live terminal state (mouseTrackingMode) rather than querying internal daemon buffer snapshots via window.api.pty.getMainBufferSnapshot.
#7895) The warm-reattach mouse-leak e2e (added in #7893) awaited the readiness marker unconditionally, so it hard-failed on sandboxed runners whose PTY echoes input but never execs a shell. Wrap the gate in a skip guard that mirrors the existing pane-manager guard: run the assertions where the shell executes, and skip gracefully otherwise instead of a false red. Co-authored-by: Orca <[email protected]>
…tablyai#7893) * fix(terminal): clear leaked mouse-reporting modes on pane reattach A TUI that enables mouse tracking (?1000/1002/1003 + SGR 1006/1016) and dies uncleanly never emits the disable sequence, so the daemon's snapshot records the mode and buildRehydrateSequences re-arms it on every reattach. POST_REPLAY_REATTACH_RESET cleared cursor/focus/kitty state but not mouse modes, so a plain shell in the reattached pane echoed every pointer-motion report (`<35;col;rowM`) as literal text. Add RESET_MOUSE_REPORTING (?9l ?1000l ?1002l ?1003l ?1006l ?1016l) to both POST_REPLAY_REATTACH_RESET and POST_REPLAY_MODE_RESET. Live agent panes keep mouse modes via POST_REPLAY_LIVE_AGENT_REATTACH_RESET, so agent scroll is unaffected. Verified against the real daemon serializer + real xterm: the old reset leaves mouseTrackingMode armed, the new reset returns it to 'none'. * test: add regression tests for terminal mouse mode leak on reattach - Add an E2E test to verify that a warm reattach disarms mouse modes left armed by an uncleanly exited TUI. - Add a test fixture that writes the mouse tracking enable sequence without a matching disable sequence. - Ensure the reattached pane disarms mouse tracking and that actual mouse movement produces no reports. * Add types to isMouseReport in terminal reattach leak test Explicitly annotate parameter and return types for the isMouseReport helper function inside the page.evaluate block. * Refactor mouse-mode leak E2E test to use shell printf and live pane Eliminate the external Node.js fixture file and streamline the E2E test by using a POSIX printf shell builtin to arm the mouse tracking modes. Additionally, verify the leak precondition by inspecting the active pane's live terminal state (mouseTrackingMode) rather than querying internal daemon buffer snapshots via window.api.pty.getMainBufferSnapshot.
stablyai#7895) The warm-reattach mouse-leak e2e (added in stablyai#7893) awaited the readiness marker unconditionally, so it hard-failed on sandboxed runners whose PTY echoes input but never execs a shell. Wrap the gate in a skip guard that mirrors the existing pane-manager guard: run the assertions where the shell executes, and skip gracefully otherwise instead of a false red. Co-authored-by: Orca <[email protected]>
After a serve restart where the daemon survives, a paired client could drop mouse and focus reporting for a still-live agent. The host publishes the pane with its tab-default title until it seeds the daemon's live title about 180 ms later. A reattach image replayed inside that window was judged against the default title, read as a plain normal-buffer program, and got the reset that disarms its modes, though the image itself carried them. The snapshot now carries the host's tracked title when the image was taken, as an additive `lastTitle` field in the snapshot info, gated on the image's seq. Every reset that judges a replayed image as a live agent's (the post-replay reset, the focus-in that follows it, the hidden-restore reset, and the model-snapshot reattach) uses that title when present, so the decision describes the same moment as the replayed bytes. Local Electron model snapshots already carried this title and now use it the same way. The reattach policy itself is unchanged: non-agent normal-buffer panes still shed modes a dead child may have left (#7329, #7893). Older hosts omit the field and clients fall back to the published title. Older clients ignore it. Refs #35559
…le (#35920) After a serve restart where the daemon survives, a paired client could drop mouse and focus reporting for a still-live agent. The host publishes the pane with its tab-default title until it seeds the daemon's live title about 180 ms later. A reattach image replayed inside that window was judged against the default title, read as a plain normal-buffer program, and got the reset that disarms its modes, though the image itself carried them. The snapshot now carries the host's tracked title when the image was taken, as an additive `lastTitle` field in the snapshot info, gated on the image's seq. Every reset that judges a replayed image as a live agent's (the post-replay reset, the focus-in that follows it, the hidden-restore reset, and the model-snapshot reattach) uses that title when present, so the decision describes the same moment as the replayed bytes. Local Electron model snapshots already carried this title and now use it the same way. The reattach policy itself is unchanged: non-agent normal-buffer panes still shed modes a dead child may have left (#7329, #7893). Older hosts omit the field and clients fall back to the published title. Older clients ignore it. Refs #35559
After a serve restart where the daemon survives, a paired client could drop mouse and focus reporting for a still-live agent. The host publishes the pane with its tab-default title until it seeds the daemon's live title about 180 ms later. A reattach image replayed inside that window was judged against the default title, read as a plain normal-buffer program, and got the reset that disarms its modes, though the image itself carried them. The snapshot now carries the host's tracked title when the image was taken, as an additive `lastTitle` field in the snapshot info, gated on the image's seq. Every reset that judges a replayed image as a live agent's (the post-replay reset, the focus-in that follows it, the hidden-restore reset, and the model-snapshot reattach) uses that title when present, so the decision describes the same moment as the replayed bytes. Local Electron model snapshots already carried this title and now use it the same way. The reattach policy itself is unchanged: non-agent normal-buffer panes still shed modes a dead child may have left (#7329, #7893). Older hosts omit the field and clients fall back to the published title. Older clients ignore it. Refs #35559
Problem
A terminal pane can start spewing random text like
35;43M 35;41M … 5Mon mouse movement — visible garbage echoed into a plain shell. These are SGR mouse-motion reports (ESC [ < 35;col;row M) being echoed as literal text.Root cause is Orca-side and reproducible:
?1003h) + SGR encoding (?1006h), then dies uncleanly — the disable sequence is never emitted.terminal-private-mode-tracker.ts) and re-arms them on every reattach viabuildRehydrateSequences(headless-emulator.ts) — originally added so mobile scroll works in live panes.?1003h) and then appliesPOST_REPLAY_REATTACH_RESET, which cleared cursor style, cursor visibility, focus reporting, and Kitty keyboard flags — but not mouse modes.The
repro-7329test even documented this as a known leak (// leak).Fix
Add
RESET_MOUSE_REPORTING(?9l ?1000l ?1002l ?1003l ?1006l ?1016l— every protocol + SGR encoding the daemon can rehydrate) to bothPOST_REPLAY_REATTACH_RESETandPOST_REPLAY_MODE_RESET.Live agent panes still preserve mouse modes via
POST_REPLAY_LIVE_AGENT_REATTACH_RESET(unchanged), so scroll-in-agent keeps working — mouse is only disarmed when the pane doesn't look agent-owned, mirroring the existing?1004focus-reporting tradeoff.Verification
Reproduced end-to-end with the real components (no mocks):
term.modes.mouseTrackingModearmed; the new reset returns it to'none'.35;10;5M 35;11;5M 35;12;5M— matching the reported symptom.The
repro-7329tests are flipped from documenting the leak to asserting the disarm, plus a new regression test for the?1003h+?1016hkilled-TUI shape. All terminal-pane + daemon suites pass (2,332 tests); full typecheck clean.Made with Orca 🐋