Skip to content

perf(web): dedupe terminal mouse motion reports - #7845

Merged
maria-rcks merged 2 commits into
mainfrom
perf/opencode-v2-terminal
Aug 21, 2026
Merged

perf(web): dedupe terminal mouse motion reports#7845
maria-rcks merged 2 commits into
mainfrom
perf/opencode-v2-terminal

Conversation

@t3-code

@t3-code t3-code Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

summary

  • stop forwarding duplicate terminal mouse-motion packets when the pointer stays inside the same terminal cell
  • keep all meaningful motion, button, modifier, press, and release changes intact
  • reset motion deduplication after pointer leave and non-motion mouse actions
  • add regression coverage for the dedupe/reset behavior

root cause

OpenCode v2 enables DEC 1003 any-event mouse tracking. Browser pointer events use pixel coordinates, while the terminal protocol reports cell coordinates. A normal pointer sweep therefore produced several byte-identical SGR motion packets per cell, and T3 Code sent every duplicate through the websocket and PTY.

The fix drops only consecutive byte-identical motion packets. Absolute cell changes still send, while press/release events always send and reset the motion baseline.

benchmark

OpenCode v2 0.0.0-beta-17823 running in T3 Code's real in-app terminal, with 1,000 pointer events over the same sweep path. Values are medians from five runs.

  • websocket frames: 1,006 → 188, 81.3% fewer
  • websocket payload: 263,276 → 48,425 bytes, 81.6% less
  • browser task time: 1,381.9 → 861.9 ms, 37.6% less
  • script time: 724.3 → 327.3 ms, 54.8% less

OpenCode v2 terminal mouse benchmark

tested in the real app

OpenCode v2 running in the isolated T3 Code dev client's terminal after the fix. Its full-screen TUI, mouse tracking, input, and rendering remained intact.

OpenCode v2 running in T3 Code's in-app terminal

verification

  • 69 Ghostty terminal unit tests pass
  • web typecheck passes
  • web production build passes
  • focused lint and format checks pass
  • independent OpenCode v2 review found no logic or security blockers
  • benchmark rerun against the live in-app terminal

built with gpt-5.6-sol via hermes agent.

request provenance


Note

Medium Risk
Changes what mouse sequences reach the PTY for apps using any-event tracking. Duplicate same-cell motion is dropped by design; incorrect baseline resets could skip a legitimate first motion after a mode change.

Overview
Stops forwarding duplicate SGR mouse-motion packets when the pointer stays in the same terminal cell under DEC 1003 any-event tracking. Press/release still always send, and they (plus pointer leave, non-reporting motion, session reset, and DEC 1003 mode flips) reset the motion baseline so the next cell report is not dropped.

sendMouse now gates onData through resolveTerminalMouseData. Writes and pointer moves also sync cached any-event tracking so a mode change without pointer movement starts a fresh session. Unit tests cover the dedupe and tracking-reset helpers.

Reviewed by Cursor Bugbot for commit 9782d0f. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Dedupe terminal mouse motion reports in GhosttyTerminalSurface

  • Adds resolveTerminalMouseData to suppress outgoing motion reports when the encoded mouse data matches the previous motion baseline; non-motion actions (press/release) reset the baseline
  • Adds resolveTerminalMouseTrackingState to clear the stored motion baseline when the any-event tracking mode toggles
  • onPointerMove, onPointerLeave, write, and resetAndWrite now synchronize the cached tracking mode and clear the motion baseline at the appropriate points
  • Behavioral Change: sendMouse only emits data when resolveTerminalMouseData.send is true, so duplicate same-cell motion events are no longer forwarded to the terminal; lastMouseMotionData is the new private field controlling this dedup state

Macroscope summarized 9782d0f.

Co-authored-by: maria <254055478+maria-rcks@users.noreply.github.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Aug 21, 2026
Comment thread apps/web/src/terminal/ghostty/surface.ts
@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 13.4 KiB 13.4 KiB +1 B (+0.0%) 15.1 KiB
Codex Thread snapshot wire 6.9 KiB 6.9 KiB +2 B (+0.0%) 7.3 KiB
Codex Live turn WebSocket wire 6.5 KiB 6.5 KiB −1 B (−0.0%) 7.8 KiB
Codex Live turn WebSocket decoded 55.0 KiB 55.0 KiB 0 B (0.0%) 66.4 KiB
Codex Live turn messages 16 16 0 (0.0%) 21
Claude Total thread wire 13.4 KiB 13.4 KiB −12 B (−0.1%) 15.1 KiB
Claude Thread snapshot wire 6.9 KiB 6.9 KiB −10 B (−0.1%) 7.3 KiB
Claude Live turn WebSocket wire 6.6 KiB 6.6 KiB −2 B (−0.0%) 7.8 KiB
Claude Live turn WebSocket decoded 55.8 KiB 55.8 KiB 0 B (0.0%) 66.4 KiB
Claude Live turn messages 16 16 0 (0.0%) 21

Baseline: c3e3709 · PR result: 9782d0f · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 109.4 KiB
  • Claude decoded thread snapshot: 110.1 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5bcb285. Configure here.

Comment thread apps/web/src/terminal/ghostty/surface.ts
@macroscopeapp

macroscopeapp Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This performance optimization changes terminal mouse event handling by filtering duplicate motion reports. While well-tested, it modifies what data is sent to the terminal, which is a behavioral change to core input handling that warrants human review.

You can add or adjust custom eligibility rules. Learn more.

Co-authored-by: maria <254055478+maria-rcks@users.noreply.github.com>
@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). and removed size:S 10-29 changed lines (additions + deletions). labels Aug 21, 2026
@maria-rcks
maria-rcks merged commit 592c598 into main Aug 21, 2026
23 checks passed
@maria-rcks
maria-rcks deleted the perf/opencode-v2-terminal branch August 21, 2026 22:08
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Aug 22, 2026
## What's Changed
* feat(web): cmd+enter to create thread in background by @extoci in pingdotgg/t3code#7821
* fix(web): launcher shortcuts no longer hijack the empty composer by @Lucenx9 in pingdotgg/t3code#7794
* feat(desktop): choose external project icons by @Bil0000 in pingdotgg/t3code#7823
* perf(web): dedupe terminal mouse motion reports by @t3-code[bot] in pingdotgg/t3code#7845


**Full Changelog**: pingdotgg/t3code@v0.0.34-nightly.20260821.1154...v0.0.34-nightly.20260822.1155

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.34-nightly.20260822.1155
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant