Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): isolate preview keyboard input #8494

Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromt3code/fix-preview-keyboard-isolation-3715opened View on GitHub

preview_press could report success without delivering a key. Native input could also reach a host shortcut, a stale document, or a replacement preview target.

This limits preview_press to printable ASCII and supported named keys. Arbitrary Unicode text stays on preview_type. Electron now receives the exact raw key-down, character, and key-up packets for each supported key.

Desktop matches native and DOM receipts through a strict per-document FIFO. It checks the exact WebContents, attachment, main frame, process, routing ID, and document generation. Unconfirmed delivery quarantines that document, including when the same WebContents moves to another tab or detaches and later returns. Only a committed navigation or a new WebContents recovers native keyboard input.

Expected keyboard failures cross Electron as fulfilled typed results, so the web host keeps their error tags and reasons. Unexpected failures still reject through the existing sanitized path.

Focused verification covers 154 tests across contracts, desktop keyboard packets, desktop manager lifecycles, desktop IPC, and web IPC handling.

Fixes #3715

Made with GPT-5.6 Sol using Codex.


Note

Medium Risk Large behavioral change to preview automation input routing and IPC semantics; mistakes could mis-deliver keys or leave keyboard quarantine state, but scope is limited to desktop preview agent control.

Overview Preview agent key presses no longer go through CDP Input.dispatchKeyEvent and focus emulation. They use Electron sendInputEvent (rawKeyDown / char / keyUp) with a tightened key set; Unicode and unsupported keys are rejected in favor of preview_type.

The desktop preview manager confirms delivery by matching DOM preview:human-input receipts (down/up, modifiers, main frame, document generation) against agent-marked native packets, with quarantine when delivery is uncertain until navigation or target recovery. It also blocks presses when the host window is unfocused, when a child frame owns focus, or when the webview attachment/tab target changes mid-operation—surfacing new tagged errors.

automationPress IPC now returns a Success / Failure result for those expected keyboard and target-changed failures instead of always void or a generic rejection; unrelated errors still propagate as before. The preload reports key phase and modifier state for human-input matching.

Extensive Manager and IPC tests cover receipts, shortcuts, navigation, WebContents reuse, and interruption by human pointer/keyboard input.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9d7b8ddd0207d1ac6a09f231d8acbcf84578f38a. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Isolate preview keyboard input via native Electron dispatch with delivery confirmation

  • Reworks performAutomationPress in Manager.ts to send native key events through wc.sendInputEvent instead of CDP, with explicit receipt confirmation via before-input-event and a 1-second timeout (AGENT_KEY_RECEIPT_TIMEOUT_MS)
  • Key signals now carry modifier booleans (meta, shift, control, alt) and a phase field ('down' | 'up'); human input listeners in PickPreload.ts report both keydown and keyup with modifier state
  • Rewrites PreviewKeyboard.ts to emit Electron KeyboardInputEvent shapes with string nativeKeyCode values, separate char packets for text insertion, and modifiers as lowercase string arrays; removes numeric bitmask encoding and macOS editing command mapping
  • Tightens PreviewAutomationPressKey schema in previewAutomation.ts to a closed set of named keys, F1–F12, and printable ASCII (excluding literal space); unsupported Unicode keys now throw instead of being forwarded
  • Adds structured Success/Failure result for automationPress IPC with new error classes: PreviewAutomationKeyboardWindowNotFocusedError, PreviewAutomationKeyboardFocusedFrameUnsupportedError, PreviewAutomationKeyboardDeliveryNotConfirmedError, and PreviewAutomationTargetChangedError
  • Behavioral Change: automationPress now rejects when the desktop window is unfocused, an iframe has focus, or delivery is not confirmed within timeout; automationType now uses Runtime.evaluate with document.execCommand("insertText") instead of native text input APIs; literal space character is no longer accepted as a press key (use 'Space')
Macroscope summarized 9d7b8dd.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: c3f71730-96cf-4a80-940a-fa92162021c0

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.3 KiB13.3 KiB+8 B (+0.1%)15.1 KiB✅
      CodexThread snapshot wire6.9 KiB6.9 KiB+1 B (+0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire6.4 KiB6.4 KiB+7 B (+0.1%)7.8 KiB✅
      CodexLive turn WebSocket decoded55.6 KiB55.6 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages11110 (0.0%)21✅
      ClaudeTotal thread wire13.4 KiB13.3 KiB−16 B (−0.1%)15.1 KiB✅
      ClaudeThread snapshot wire6.9 KiB6.9 KiB−7 B (−0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.5 KiB6.4 KiB−9 B (−0.1%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded56.4 KiB56.4 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages11110 (0.0%)21✅

      Baseline: 8f49132 · PR result: 9d7b8dd · 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.

    4. One convention issue: the new keyboard-unavailable errors use a reason literal to select the caller-visible message, which the Effect service conventions require to be modeled as separate error classes. Details inline.

      Posted via Macroscope — Effect Service Conventions
    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR replaces the preview keyboard pipeline and changes desktop/web IPC behavior, adding substantial lifecycle, receipt-confirmation, quarantine, and target-validation state. The breadth of production runtime changes and shared control-session refactoring warrants human review despite the extensive tests and experienced author.

      Notes:

      • Diff unchanged. Approvability was decided on eligibility alone.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. 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](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit c4b97d145c42e31783d06b92baeb0d38f72572b4. Configure [here](https://www.cursor.com/dashboard/bugbot).
    7. juliusmarminge added labelsmacroscope-review

    8. Note

      Grok responding on behalf of Julius.

      Closing as superseded by #18556, which just landed on main and fixes the preview keyboard leak behind #3715 in the current DesktopBrowserHost input path. This branch also targets a web preview host file that's no longer on main. If the per-key delivery receipts here are still wanted, a fresh PR on top of #18556 would be the way to go.

    9. juliusmarminge closed this

Sign in to join this conversation.