Skip to content

fix(cli): flush queued mouse reports at the process boundary (issue 3) - #26

Merged
kiranscript merged 4 commits into
mainfrom
test/issue-3-c
Aug 3, 2026
Merged

kiranscript merged 4 commits into
mainfrom
test/issue-3-c

Conversation

@kiranscript

@kiranscript kiranscript commented Jul 31, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes the issue-3 ticket from .scratch/android-terminal-rash-bugs/issues/03-prevent-queued-mouse-report-leaks.md: mouse reports queued while a mouse-enabled TUI is stalled leaked into the returning shell as literal text (35;5;3M35;18;14M… at the prompt) and executed as shell commands — on both abrupt kills and clean DECRST exits.

Root cause (reproduced deterministically on this branch over the real wire protocol): the WebView sends mouse packets fire-and-forget and the CLI wrote every input frame straight into the PTY; bytes queued unread in the tty input buffer are re-read by the shell after the process boundary. Sender-side suppression can only gate future gestures, never the already-queued packets.

Fix — new MouseReportingGuard in cli/src/mouseReportingGuard.ts, wired into Session across all output and both input paths (WS input frames + embedded workstation):

  • Arms on DECSET 1000/1002/1003 in the output stream (same convention as the Android tracker); DECRST/1049l deliberately do not disarm — only the [mobily] prompt proves the shell, not a still-running TUI, is reading.
  • Tracks input frames consisting solely of mouse reports (SGR 1006 / X10 / urxvt shapes).
  • At the prompt boundary with mouse reports forwarded, writes VINTR (\x03): the line discipline discards queued input, and SIGINT aborts any readline line the packets already polluted — every arrival ordering ends at a clean, empty prompt and nothing executes.
  • Drops stale in-flight mouse packets for 1500 ms post-boundary; keyboard-only sessions never trigger the flush; unarmed mouse frames outside the window still forward (mid-TUI reattach safety).

Backend coverage: bare is fully covered; tmux with default mouse off neither re-emits DECSET nor lets clients generate mouse packets (probed), so arming matches the leak precondition; tmux with user mouse on re-emits DECSET and the flush reaches the pane as an ordinary key.

Trade-off: when mouse input flowed, a TUI exit emits one VINTR — bash shows a transient ^C above a fresh, empty prompt (zsh/fish show nothing). Chosen over executing 35;5;3M… as a command. Report: .scratch/android-terminal-rash-bugs/issue-3-cli-test-report-c.md.

Test plan

  • pnpm typecheck / lint / build / test — root gate green (turbo 5/5)
  • pnpm --filter mobily test — 25 files / 234 tests green (real tmux on PATH per AGENTS.md); 12 new guard unit tests + 4 rewritten wire-level integration tests (abrupt kill, clean exit, active-TUI click/wheel/key delivery, keyboard-only no-interrupt); integration suite stable 5/5 repeat runs
  • pnpm --filter mobily-android test — 21 files / 81 tests green
  • pnpm --filter mobily-android run test:browser — 25/26; the one failure is the pre-existing snapshot cursor case documented in AGENTS.md (red on main and CI's android-browser job)
  • On-device confirmation with the ticket's hover-string-repro.ps1 harness — needs a physical device + Dev Tunnel login, unavailable headless (noted in the ticket)

Notes

All seven acceptance criteria in the ticket are checked off, with on-device verification as the only residual. The first two commits on this branch hold the pre-fix reproduction evidence (raw PTY transcripts in the report).

Open in Web Open in Cursor 

cursoragent and others added 2 commits July 31, 2026 17:32
Drive the real wire protocol (bare PTY bash + Session + startServer + ws
client) with a stalled mouse-enabled TUI fixture. SGR motion packets sent
as input frames while the TUI is stalled queue unread in the tty buffer and
leak into the returning shell as literal input, then execute as commands on
Enter — for both abrupt (SIGKILL) and clean (SIGTERM + DECRST) exits.

Two bug-characterization tests document the leak; two it.fails tests pin the
acceptance behavior until a fix lands.

Co-authored-by: kiran kumar <kirank55@users.noreply.github.com>
…issue-3-c

Add the branch test report and update the ticket with progress, annotated
acceptance criteria, and the confirmed leak mechanism.

Co-authored-by: kiran kumar <kirank55@users.noreply.github.com>
@vercel

vercel Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mobily-website Ready Ready Preview Jul 31, 2026 6:13pm

cursoragent and others added 2 commits July 31, 2026 18:12
Mouse reports sent while a mouse-enabled TUI is stalled queue unread in
the tty input buffer and leak into the returning shell as literal input,
executing as commands — on both abrupt kills and clean DECRST exits.

Add MouseReportingGuard to the Station Session: it arms on DECSET
1000/1002/1003 in the output stream, tracks pure mouse-report input
frames, and at the [mobily] prompt boundary writes VINTR so the line
discipline discards the queued input (SIGINT also aborts any readline
line the packets already polluted). In-flight mouse packets are dropped
for 1500ms post-boundary; all other input and keyboard-only sessions are
untouched. DECRST/1049l do not disarm — only the prompt proves the shell,
not a still-running TUI, is reading.

Covered by 12 guard unit tests and rewritten wire-level integration
tests: abrupt kill, clean exit, active-TUI click/wheel/key delivery, and
no-interrupt for keyboard-only sessions.

Co-authored-by: kiran kumar <kirank55@users.noreply.github.com>
Rewrite the branch report around the MouseReportingGuard fix (root cause,
design, backend coverage, trade-offs, gates) and check off the ticket's
acceptance criteria with the residual on-device verification noted.

Co-authored-by: kiran kumar <kirank55@users.noreply.github.com>
@cursor cursor Bot changed the title test(cli): reproduce issue 3 — queued mouse reports leak into the shell fix(cli): flush queued mouse reports at the process boundary (issue 3) Jul 31, 2026
@kiranscript
kiranscript marked this pull request as ready for review August 3, 2026 18:11
@cursor

cursor Bot commented Aug 3, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@kiranscript
kiranscript merged commit ca2ad75 into main Aug 3, 2026
4 of 5 checks passed

This branch was successfully deployed

1 active deployment
Preview — 1ba13de3 Deployed Jul 31, 2026 by vercel[bot]
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.

2 participants