orca icon indicating copy to clipboard operation
orca copied to clipboard

[Bug]: Ctrl+Alt chords are swallowed by terminal input on Windows

Open takayama-dm opened this issue 4 months ago • 2 comments

Operating system

Windows

Orca version

1.4.139.0

Details

Summary

On Windows, Orca's integrated terminal does not forward a broad class of genuine Ctrl+Alt chords to the terminal process.

The issue reproduces in both:

  • A local native Windows PowerShell terminal in Orca
  • An Orca SSH terminal connected to an external Linux host running tmux and zsh

It is therefore not specific to SSH, WSL, tmux, zsh, or Kitty keyboard protocol.

The same physical key combinations work outside Orca in Windows Terminal.

Steps to reproduce with local PowerShell

  1. Open a local native Windows PowerShell terminal in Orca.

  2. Run:

    Write-Host 'Press keys; Ctrl+Q exits'
    
    while ($true) {
        $k = [Console]::ReadKey($true)
    
        if (
            $k.Key -eq [ConsoleKey]::Q -and
            $k.Modifiers -eq [ConsoleModifiers]::Control
        ) {
            break
        }
    
        $charCode = [int][char]$k.KeyChar
    
        '{0,-12} char=0x{1:X4} modifiers={2}' -f `
            $k.Key, $charCode, $k.Modifiers
    }
    
  3. Press Ctrl+U.

  4. Press Alt+U.

  5. Press Ctrl+Alt+U.

  6. Repeat with Ctrl+Alt+J and Ctrl+Alt+K.

  7. Press Ctrl+Q to exit.

Actual behavior

PowerShell receives the individual Ctrl and Alt chords:

U            char=0x0015 modifiers=Control
U            char=0x0075 modifiers=Alt

Pressing any of the following produces no ReadKey event:

Ctrl+Alt+U
Ctrl+Alt+J
Ctrl+Alt+K

The chord reaches Orca itself: Orca's shortcut recorder recognizes Ctrl+Alt+K correctly. It is lost specifically between the application keyboard event and terminal input.

Secondary reproduction with a Linux PTY

In an Orca SSH terminal connected to Linux, run:

showkey -a

Observed results:

Ctrl+U       -> ^U / 0x15
Alt+U        -> ESC followed by "u"
Ctrl+Alt+U  -> no output
Ctrl+Alt+J  -> no output
Ctrl+Alt+K  -> no output

No bytes reach the Linux PTY, so shell, readline, zsh, tmux, and TUI keybindings cannot handle these chords.

Equivalent Ctrl+Alt zsh bindings work when entering WSL through Windows Terminal.

Expected behavior

A genuine physical Ctrl+Alt chord should be forwarded to the terminal process using a distinguishable terminal encoding.

It should not be silently dropped.

Actual AltGr character composition must continue to work.

Likely cause and affected scope

Orca v1.4.139 pins @xterm/xterm version 6.1.0-beta.287:

https://github.com/stablyai/orca/blob/0ab2e001d16839f5c95cbda84fffb46f08e77359/package.json#L163-L169

In the corresponding xterm.js input path, _keyDown() returns before triggerDataEvent() when _isThirdLevelShift() succeeds:

https://github.com/xtermjs/xterm.js/blob/53a98a720ae4a973e384fa2440880d09537132f3/src/browser/CoreBrowserTerminal.ts#L867-L947

On Windows, _isThirdLevelShift() treats either of the following as a third-level-shift event:

  • altKey && ctrlKey && !metaKey
  • getModifierState('AltGraph')

Consequently, a genuine physical Ctrl+Alt chord is classified as AltGr even when it is not an AltGraph composition event.

For keydown events with a keyCode greater than 47, _keyDown() then returns before the evaluated terminal input is emitted. The source-level scope is therefore broader than the manually verified U, J, and K keys and potentially includes letters, digits, punctuation, function keys, and other non-navigation keys.

This check is based on the Windows client platform and occurs before terminal data is sent, explaining why it reproduces with both local Windows ConPTY and remote Linux PTYs.

Suggested direction

Distinguish genuine physical Ctrl+Alt chords from actual AltGr composition before xterm.js applies its third-level-shift return.

Regression coverage should verify:

  • A genuine Ctrl+Alt+letter chord reaches a local Windows ConPTY.
  • The same chord reaches an SSH/Unix PTY.
  • Representative Ctrl+Alt+digit and Ctrl+Alt+punctuation chords are not silently dropped.
  • Actual AltGr character composition continues to work.
  • Existing navigation and Orca application shortcuts remain unaffected.

Related issues

  • #8231 reports a Windows Ctrl+Alt problem for an Orca application shortcut rather than terminal PTY input.
  • #481 previously covered plain Ctrl+U being dropped by terminal input handling.

takayama-dm avatar Jul 14 '26 11:07 takayama-dm

I reproduced the xterm drop on current main and verified the proposed terminal encoding against a real Windows ConPTY: writing ESC + Ctrl-U makes PowerShell ReadKey report U / 0x0015 / Alt, Control as one event. I'm working on a focused fix in Orca's existing xterm custom-key boundary that handles genuine Windows Ctrl+Alt text chords while leaving getModifierState('AltGraph') events to the native composition path. I'll cover the shared local/SSH PTY write path plus AltGr, digit, punctuation, shortcut, and keyup regressions.

bbingz avatar Jul 15 '26 03:07 bbingz

Agent reproduction package (Windows orchestration 2026-07-16)

Host context: Windows 11 / Orca 1.4.143.0 / repo path used: docs/bug-reproductions/
Labels applied: see issue labels (has_repro or cannot_repro).
Security: Do not run user-uploaded binaries from issue attachments. Recreate fixtures from the steps/scripts below.


Issue 8734 — Ctrl+Alt chords swallowed by terminal input on Windows

Status: repro_confirmed (source + maintainer; live key inject blocked in agent env)
Host: Windows 11 10.0.26200 (25H2), Orca 1.4.143.0
Label: has_repro
URL: https://github.com/stablyai/orca/issues/8734

Summary

Genuine physical Ctrl+Alt+letter chords never reach the PTY on Windows. xterm.js classifies altKey && ctrlKey && !metaKey as third-level shift (AltGr) and returns from _keyDown before triggerDataEvent. Same drop hits local ConPTY and remote/SSH PTYs because it happens in the client xterm input path.

Pin: @xterm/xterm 6.1.0-beta.287 (package.json).

Maintainer bbingz already reproduced on main and is implementing a custom-key-boundary fix.

Conclusive evidence (source)

1. Production bundle (1.4.143 install)

Extracted from C:\Users\neil\AppData\Local\Programs\orca\resources\app.asar:

_isThirdLevelShift(e,t){
  let n =
    e.isMac && !this.options.macOptionIsMeta && t.altKey && !t.ctrlKey && !t.metaKey
    || e.isWindows && t.altKey && t.ctrlKey && !t.metaKey
    || e.isWindows && t.getModifierState("AltGraph");
  return t.type === "keypress" ? n : n && (!t.keyCode || t.keyCode > 47)
}

On Windows, any Ctrl+Alt keydown with keyCode > 47 (letters, digits, punctuation, many F-keys) is treated as third-level shift. _keyDown then returns early:

if (... this._isThirdLevelShift(this.browser, e) || ...) return true;
// evaluated key never reaches triggerDataEvent / PTY

Saved: docs/bug-reproductions/evidence/8734-xterm-isThirdLevelShift-extract.txt

2. Repo pin + no Orca workaround yet

  • package.json: "@xterm/xterm": "6.1.0-beta.287"
  • attachCustomKeyEventHandler / xterm-bypass-policy.ts handle clipboard, IME, interrupt — not Windows genuine Ctrl+Alt vs AltGr.

3. Maintainer confirmation

Issue comment (bbingz): reproduced xterm drop on current main; verified ESC+Ctrl-U encoding for PowerShell ReadKey; fix planned at Orca custom-key boundary.

Manual / UI repro (still required for ReadKey transcript)

Scripts:

powershell -NoProfile -ExecutionPolicy Bypass -File docs/bug-reproductions/scripts/repro-8734-ctrl-alt.ps1

Then in an Orca native PowerShell tab:

  1. Run docs/bug-reproductions/evidence/8734-probe.ps1
  2. Press Ctrl+U, Alt+U, Ctrl+Alt+U, Ctrl+Alt+J, Ctrl+Alt+K, then Ctrl+Q
  3. Save output as evidence/8734-readkey.txt
Chord Expected (fixed) Bug (current)
Ctrl+U event, modifiers=Control event
Alt+U event, modifiers=Alt event
Ctrl+Alt+U/J/K event (Alt+Control) no ReadKey event

Same chords work in Windows Terminal.

Automation attempt (this host)

Step Result
Start probe via orca terminal send OK — preview shows Press keys; Ctrl+Q exits...
orca computer hotkey Control+Alt+u Failed window_not_focused (restore-window cannot foreground Electron)
Win32 keybd_event injection FG HWND stayed 0; no ReadKey lines appeared
Screenshots computer-use screenshot_failed / permission

Live keyboard path is blocked in this agent desktop session; source extract + maintainer + pin is sufficient for has_repro.

Expected vs actual

Expected Genuine Ctrl+Alt+letter bytes reach local ConPTY / remote PTY with distinguishable encoding; AltGr composition still works
Actual Chords dropped inside xterm before PTY write

Fix hint

At Orca attachCustomKeyEventHandler (or fork/patch): distinguish genuine Ctrl+Alt text chords from getModifierState('AltGraph') composition; emit a terminal encoding for the former instead of letting _isThirdLevelShift swallow keydown. Cover digits/punctuation/shortcuts/keyup/AltGr regressions.

Repro script: repro-8734-ctrl-alt.ps1

# Repro for https://github.com/stablyai/orca/issues/8734
# Ctrl+Alt chords swallowed before terminal input on Windows.
#
# This script cannot inject real keyboard events into Orca's xterm alone.
# It prepares the PowerShell probe the issue specifies and documents how to
# complete the repro manually or via Orca computer-use / UI automation.
#
# Usage:
#   1. Open a native PowerShell terminal tab in Orca.
#   2. Paste the probe from evidence/8734-probe.ps1 (written by this script).
#   3. Press Ctrl+U, Alt+U, Ctrl+Alt+U, Ctrl+Alt+J, Ctrl+Alt+K, then Ctrl+Q.
#   4. Save terminal output under docs/bug-reproductions/evidence/8734-*.txt
#
# Optional auto-check of source pin:
#   powershell -NoProfile -ExecutionPolicy Bypass -File docs/bug-reproductions/scripts/repro-8734-ctrl-alt.ps1

$ErrorActionPreference = 'Stop'
$evidenceDir = Join-Path (Split-Path $PSScriptRoot -Parent) 'evidence'
New-Item -ItemType Directory -Force -Path $evidenceDir | Out-Null
$probe = @'
Write-Host "Press keys; Ctrl+Q exits. Expected BUG: Ctrl+Alt+U/J/K produce NO ReadKey event."
while ($true) {
  $k = [Console]::ReadKey($true)
  if ($k.Key -eq [ConsoleKey]::Q -and $k.Modifiers -eq [ConsoleModifiers]::Control) { break }
  $charCode = [int][char]$k.KeyChar
  "{0,-12} char=0x{1:X4} modifiers={2}" -f $k.Key, $charCode, $k.Modifiers
}
'@
$probePath = Join-Path $evidenceDir '8734-probe.ps1'
Set-Content -Path $probePath -Value $probe -Encoding utf8

$repoRoot = Split-Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) -Parent
# package.json xterm pin
$pkg = Get-Content (Join-Path $repoRoot 'package.json') -Raw | ConvertFrom-Json
$xterm =
  if ($pkg.dependencies.'@xterm/xterm') { $pkg.dependencies.'@xterm/xterm' }
  elseif ($pkg.devDependencies.'@xterm/xterm') { $pkg.devDependencies.'@xterm/xterm' }
  else { '(not found)' }

$meta = [ordered]@{
  issue = 8734
  probePath = $probePath
  xtermVersion = $xterm
  maintainerNote = 'Issue comment by bbingz: reproduced xterm drop on main; fix in progress'
  manualSteps = @(
    'Open PowerShell terminal in Orca',
    "powershell -NoProfile -File `"$probePath`"",
    'Press Ctrl+U (expect event), Alt+U (expect event), Ctrl+Alt+U/J/K (BUG: no event)',
    'Ctrl+Q to exit; save output to evidence/8734-readkey.txt'
  )
}
$meta | ConvertTo-Json -Depth 5 | Set-Content (Join-Path $evidenceDir '8734-meta.json') -Encoding utf8
Write-Host "Wrote probe: $probePath"
Write-Host "xterm pin: $xterm"
Write-Host "Complete manual/UI steps to confirm bug on this machine."
exit 0


How another agent should use this

  1. Read this comment fully (status, expected vs actual, blockers).
  2. If a script is included above, copy it to a temp file and run it on a Windows 11 host with Orca installed (prefer production install under %LOCALAPPDATA%\Programs\orca).
  3. Capture evidence (CLI --json, screenshots, logs) under a local folder; optionally comment results back here.
  4. If status is cannot_repro / needs_setup, satisfy the listed prerequisites first, then re-attempt and flip labels: remove cannot_repro, add has_repro when conclusive.

OrcaWin avatar Jul 17 '26 00:07 OrcaWin