fix(web): prevent duplicate terminal paste #8457
main fromrefs/pull/8457/head·opened View on GitHubWhat Changed#
Centralized terminal paste delivery so every non-empty paste invalidates older clipboard reads before writing to the PTY. Added focused coverage for keyboard/context-menu races, native/shortcut races, and empty paste data.
Why#
Terminal paste can arrive through an async clipboard read or a native paste event. Keeping token invalidation in one method prevents both paths from delivering the same clipboard content.
Validation#
vp test run apps/web/src/terminal/ghostty/surface.test.ts(46 passed)- Targeted lint for
surface.tsandsurface.test.ts vp run --filter @t3tools/web typecheck
Checklist#
- This PR is small and focused
- I explained what changed and why
Implemented with GPT-5.6 Codex in T3 Code.
Note
Low Risk Focused change to web terminal input handling with new regression tests; no auth, data persistence, or broader API surface changes.
Overview
Centralizes Ghostty terminal paste delivery in a new paste() method so native events, keyboard shortcut clipboard reads, and host pasteFromClipboard all share one path to bracketed-paste encode and send data to the PTY.
When a non-empty paste wins, paste() bumps pasteShortcutToken, which invalidates slower async reads that still hold an older token—so context-menu vs keyboard and shortcut vs native races no longer double-send the same clipboard text. Empty paste() calls are no-ops and do not bump the token, so an empty native paste still lets a pending shortcut read complete.
Adds unit tests for those race scenarios using a lightweight surface stub.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7e5f26785dee5492bb2c58a59b0dbafad7dd79d2. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).Note
Fix duplicate terminal paste by consolidating delivery in GhosttyTerminalSurface.paste#
- Adds a single
paste(data)method toGhosttyTerminalSurfacethat handles token bumping, encoding, and delivery viaoptions.onData; early-returns on disposed surfaces or empty strings. - Routes all three paste paths —
onKeyDownclipboard read,onPasteevent handler, andpasteFromClipboard— throughthis.paste()instead of duplicating the token/dispatch logic inline. - Adds unit tests in surface.test.ts covering paste race scenarios (keyboard vs context-menu, native vs shortcut) and empty-paste-while-pending behavior.
- Behavioral Change:
pasteFromClipboardnow callsonDatafor non-empty clipboard text even whencore.encodePastereturns an empty string; empty input remains a no-op.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved at
7e5f267Macroscope's review found this PR approvable — This is a small, localized terminal bug fix that consolidates existing paste paths to prevent duplicate PTY input during clipboard races. Focused regression tests cover the affected scenarios, with no schema, security, persistence, or deployment changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Note
🤖 GPT-5.6 Sol responding on behalf of Theo
Closing this because current main already prevents the duplicate-paste orderings covered here.
pasteFromClipboard, the keyboard shortcut path, and the native paste handler already claim or invalidatepasteShortcutToken, while an empty native paste leaves the pending read current.This patch now centralizes existing behavior, and its tests call the proposed helper instead of the current event paths. It also does not cover the remaining inverse ordering where the async clipboard read delivers before a later native paste event. There is no behavior left in this PR that should land.
t3dotgg(GitHub profile, opens in a new tab) closed this
Not sure why but I'm struggling with CMD+V double pasting everywhere whether inside or outside tmux.
It might be because safari again.
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
3287ae89-610f-4bb7-b256-ee933dc79cddYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.