Skip to content

fix(terminal): route Shift+Enter by PTY host - #8065

Merged
Jinwoo-H merged 9 commits into
stablyai:mainfrom
bbingz:fix/remote-windows-shift-enter
Jul 13, 2026
Merged

Jinwoo-H merged 9 commits into
stablyai:mainfrom
bbingz:fix/remote-windows-shift-enter

Conversation

@bbingz

@bbingz bbingz commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix Shift+Enter when the Orca client and active terminal PTY run on different operating systems, such as a macOS client connected to a Windows host.

Shortcut recognition still follows the client keyboard platform, while the bytes written to the terminal follow the active PTY host and application protocol:

  • Active Kitty keyboard protocol sends CSI-u on every host.
  • Without Kitty mode, Windows PTYs use ESC + carriage return by default.
  • Trusted Droid evidence remains an additional Windows-only reason to send CSI-u.
  • Without Kitty mode, non-Windows PTYs use ESC + carriage return.

The active pane's captured SSH connection, paired runtime, or live local session wins over later worktree-host changes. Missing platform metadata safely falls back to the client platform.

This prevents [13;2u from being inserted literally in Windows-hosted terminals reached from macOS without regressing applications that explicitly negotiate Kitty keyboard mode.

Screenshots

No visual change. This is terminal byte routing; validation used exact renderer-to-PTY byte assertions.

Testing

  • pnpm typecheck
  • pnpm lint
  • 208 focused Vitest tests across keyboard policy, host resolution, local/SSH/runtime transport identity, paste/runtime classification, and Windows Droid routing
  • pnpm check:reliability-gates
  • pnpm check:max-lines-ratchet
  • git diff --check
  • Fresh Linux ARM64 Docker target: real relay deployment, real SSH PTY, and raw-byte capture
    • Kitty inactive: 1b0d
    • Kitty active: 1b5b31333b3275
  • Independent final review after rebasing onto current main

Terminal reliability proof

  • Reliability invariant: terminal-input.windows-modified-enter-routing. Shift+Enter bytes follow the active application's negotiated protocol and active PTY host; stale worktree ownership, sibling panes, or prior PTYs cannot change routing authority.
  • Material impact: makes cross-OS SSH and paired-runtime routing explicit and regression-tested while preserving the Kitty-protocol safety gate from fix(terminal): gate Shift+Enter CSI-u on active protocol #8427 and the trusted Windows Droid exception motivated by [Bug]: [Droid] Shift + Enter for a line break, treating it simply as Enter instead. #7620/fix(terminal): send CSI-u Shift+Enter to Droid on Windows (#7620) #7668.
  • Product change type: mixed runtime hardening and deterministic gate coverage.
  • Performance risk inventory: touches terminal typing only on Shift+Enter. Ordinary keys perform zero host, agent, or protocol lookups. Shift+Enter uses bounded synchronous active-transport/indexed-store lookups and at most one pane-keyed Kitty-mode lookup; it adds no IPC, RPC, subprocess, polling, listener, timer, buffering, or provider fanout.
  • No-regression evidence: callback-count tests cover ordinary-key zero-work and lookup short-circuiting; 208 focused tests, full typecheck/lint, reliability/max-lines gates, and exact reviewed-tree verification passed.
  • Correctness evidence: deterministic tests assert exact bytes for macOS/Linux/Windows client-host combinations, Kitty active/inactive, trusted Droid, SSH/WSL/runtime/local ownership, legacy runtime PTY IDs, reattach, and missing-metadata fallback. The Linux SSH relay run independently captured the two expected byte sequences above.
  • Provider/platform coverage: local, daemon, SSH, WSL, and paired runtime are covered deterministically across simulated macOS/Linux/Windows cells. A macOS client to live Linux SSH PTY is covered end to end.
  • Residual gaps: no live Windows PTY, WSL, paired-runtime, paired-web, restore/replay, or real Droid-binary artifact was available. Windows-specific behavior remains covered deterministically and by the existing Windows-only Electron byte oracle when run on Windows.
  • Promotion status: partial/experimental. Live Windows evidence and stable CI/flake history are still required before promoting the gate.
  • Rollback/demotion rule: demote or follow up if the Windows byte test silently skips/flakes, routing uses output/title heuristics, active Kitty mode stops authorizing CSI-u, or any ordinary-key IPC/scan/polling/lifecycle work appears.

Security audit

No auth, secrets, dependencies, filesystem paths, command construction, telemetry, or new IPC behavior. Existing trusted platform and pane metadata select between two fixed terminal byte sequences.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds terminal input host platform resolution using SSH connection metadata, runtime host status, or the client platform. Terminal shortcut resolution now accepts a host-platform callback and uses it for Shift+Enter input encoding. Keyboard handlers provide the resolved platform for the active pane, and tests cover runtime, SSH, local fallback, and Windows-host behavior from macOS.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main change: routing Shift+Enter by the PTY host.
Description check ✅ Passed The description is mostly complete and covers summary, screenshots, testing, and security, though the AI Review Report and Notes sections are not explicit.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1a0fdcdb-28c5-426c-82bb-cc778cb23c1e

📥 Commits

Reviewing files that changed from the base of the PR and between e4c7aab and 1f06d7f519250ada2368da11e003e37f7693e0ab.

📒 Files selected for processing (5)
  • src/renderer/src/components/terminal-pane/keyboard-handlers.ts
  • src/renderer/src/components/terminal-pane/terminal-input-host-platform.test.ts
  • src/renderer/src/components/terminal-pane/terminal-input-host-platform.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.test.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts

@bbingz
bbingz force-pushed the fix/remote-windows-shift-enter branch from 1381546 to 98ae41d Compare July 10, 2026 10:07

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-input-host-platform.test.ts (1)

36-43: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider simplifying the conditional type assertion.

The extends Map<string, infer T> ? T : never pattern on line 41 is correct but unnecessarily verbose for a test fixture. A simpler as any or extracting a local type alias would improve readability without losing meaning.

♻️ Optional simplification
           runtimeStatusByEnvironmentId: new Map([
             [
               'windows-box',
-              {
-                status: { hostPlatform: 'win32' }
-              } as AppState['runtimeStatusByEnvironmentId'] extends Map<string, infer T> ? T : never
+              { status: { hostPlatform: 'win32' } } as any
             ]
           ])

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c38a5797-a15a-4762-ac5d-6c9e0a5b7abb

📥 Commits

Reviewing files that changed from the base of the PR and between 138154672c9da7850543d26ce8265446e6753f09 and 98ae41dbd272987535f68b602c7461fffeafc27b.

📒 Files selected for processing (5)
  • src/renderer/src/components/terminal-pane/keyboard-handlers.ts
  • src/renderer/src/components/terminal-pane/terminal-input-host-platform.test.ts
  • src/renderer/src/components/terminal-pane/terminal-input-host-platform.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.test.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.test.ts
  • src/renderer/src/components/terminal-pane/terminal-input-host-platform.ts
  • src/renderer/src/components/terminal-pane/keyboard-handlers.ts

@bbingz
bbingz force-pushed the fix/remote-windows-shift-enter branch from 21495f8 to 3577184 Compare July 11, 2026 11:21
bbingz and others added 6 commits July 12, 2026 19:35
# Conflicts:
#	src/renderer/src/components/terminal-pane/keyboard-handlers.ts
#	src/renderer/src/components/terminal-pane/terminal-input-host-platform.test.ts
#	src/renderer/src/components/terminal-pane/terminal-input-host-platform.ts
#	src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts

@Jinwoo-H Jinwoo-H 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.

Thanks for the cross-OS fix. Maintainer review integrated this with current main and tightened the routing contract:

  • active Kitty keyboard protocol authorizes CSI-u on every host
  • trusted Droid remains an additional Windows-only authorization
  • active SSH/runtime/local PTY ownership survives worktree-host changes and reattach
  • 208 focused tests, full typecheck/lint, reliability gates, and a live Linux SSH relay raw-byte check passed

The final independent review is clean; remaining live Windows/WSL/runtime gaps are documented in the PR proof section.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: adaf47b6-9369-4bd1-964d-4795f68b2e57

📥 Commits

Reviewing files that changed from the base of the PR and between 21495f896aeea1636cf1d59d89d9b7a75431e702 and a138ef9.

📒 Files selected for processing (1)
  • config/reliability-gates.jsonc

@coderabbitai coderabbitai 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.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: adaf47b6-9369-4bd1-964d-4795f68b2e57

📥 Commits

Reviewing files that changed from the base of the PR and between 21495f896aeea1636cf1d59d89d9b7a75431e702 and a138ef9.

📒 Files selected for processing (1)
  • config/reliability-gates.jsonc
🛑 Comments failed to post (1)
config/reliability-gates.jsonc (1)

2243-2250: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Record evidence for the newly added host-routing command.

The sole evidence entry runs the 22-file command at Line 2246, not the new keyboard-handlers, remote-runtime-pty-transport, and terminal-input-host-platform command at Line 2049. Add its actual run record, or narrow the executed-coverage claims, so the gate remains auditable.

@Jinwoo-H
Jinwoo-H merged commit d197c5b into stablyai:main Jul 13, 2026
1 check passed
OrcaWin added a commit to OrcaWin/orca that referenced this pull request Jul 16, 2026
… Bash) (stablyai#7620)

Shift+Enter still submitted instead of inserting a newline when Droid ran in
Git Bash on Windows, even after the PowerShell fix (stablyai#7620/stablyai#8065/stablyai#8427).

On Windows, Orca sends Droid the kitty CSI-u byte (ESC [ 13;2u) for Shift+Enter
only when the active pane has fresh, trusted process evidence that Droid is the
foreground app; otherwise it falls back to the Codex-compatible ESC+CR, which
Droid decodes as a plain Enter and submits. That trusted evidence comes from a
confirming foreground read.

PowerShell triggers that read from its OSC 133 command-start event. Git Bash
(and cmd.exe) emit no OSC command boundary, and an Orca-launched agent delivers
its command programmatically (no typed-command inference), so a fresh Droid
spawn in those shells never earned routing trust -- leaving Shift+Enter on the
ESC+CR fallback forever.

Fix: on a fresh spawn into a no-OSC shell, seed the SAME command-start
confirmation the manually-typed launch path already uses
(paneForegroundAgentTracker.onCommandStarted). Its bounded retry ladder spans
Droid boot, and -- crucially -- a miss publishes shellForeground:false, so the
pane stays recoverable by later focus/reveal samples. (A visible-pty sample was
rejected here: on a pathologically slow boot its known-agent shell-confirm would
latch, clear launch identity, and permanently poison Shift+Enter for the rest of
the session.) A real OSC 133;C, if it arrives, simply supersedes this.

Verified on Windows 11 + Git Bash with the real Droid CLI and node-pty ConPTY:
- Droid's TUI treats ESC [ 13;2u as a newline (two-line composer) and ESC+CR as
  a submit -- exactly the reported bug and the fix's mechanism.
- droid.exe is a descendant of bash inside the ConPTY console process list (so
  the main-side scan resolves it) and becomes a live process ~0.8s after launch,
  well within the retry ladder.
Tests: regression test drives the real connectPanePty spawn path and asserts
csi-u; a slow-boot test exercises the shell->droid ladder transition; a
recoverability test proves a total-miss does NOT poison the pane (it fails
against the visible-pty approach and passes with onCommandStarted).
OrcaWin added a commit that referenced this pull request Jul 16, 2026
… Bash) (#7620) (#8948)

Shift+Enter still submitted instead of inserting a newline when Droid ran in
Git Bash on Windows, even after the PowerShell fix (#7620/#8065/#8427).

On Windows, Orca sends Droid the kitty CSI-u byte (ESC [ 13;2u) for Shift+Enter
only when the active pane has fresh, trusted process evidence that Droid is the
foreground app; otherwise it falls back to the Codex-compatible ESC+CR, which
Droid decodes as a plain Enter and submits. That trusted evidence comes from a
confirming foreground read.

PowerShell triggers that read from its OSC 133 command-start event. Git Bash
(and cmd.exe) emit no OSC command boundary, and an Orca-launched agent delivers
its command programmatically (no typed-command inference), so a fresh Droid
spawn in those shells never earned routing trust -- leaving Shift+Enter on the
ESC+CR fallback forever.

Fix: on a fresh spawn into a no-OSC shell, seed the SAME command-start
confirmation the manually-typed launch path already uses
(paneForegroundAgentTracker.onCommandStarted). Its bounded retry ladder spans
Droid boot, and -- crucially -- a miss publishes shellForeground:false, so the
pane stays recoverable by later focus/reveal samples. (A visible-pty sample was
rejected here: on a pathologically slow boot its known-agent shell-confirm would
latch, clear launch identity, and permanently poison Shift+Enter for the rest of
the session.) A real OSC 133;C, if it arrives, simply supersedes this.

Verified on Windows 11 + Git Bash with the real Droid CLI and node-pty ConPTY:
- Droid's TUI treats ESC [ 13;2u as a newline (two-line composer) and ESC+CR as
  a submit -- exactly the reported bug and the fix's mechanism.
- droid.exe is a descendant of bash inside the ConPTY console process list (so
  the main-side scan resolves it) and becomes a live process ~0.8s after launch,
  well within the retry ladder.
Tests: regression test drives the real connectPanePty spawn path and asserts
csi-u; a slow-boot test exercises the shell->droid ladder transition; a
recoverability test proves a total-miss does NOT poison the pane (it fails
against the visible-pty approach and passes with onCommandStarted).
@bbingz
bbingz deleted the fix/remote-windows-shift-enter branch August 1, 2026 00:47
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(terminal): route Shift+Enter by PTY host

* fix(terminal): resolve SSH platform from execution host

* fix(terminal): preserve restored runtime input routing

* fix(terminal): route Shift+Enter by PTY host

* fix(terminal): resolve SSH platform from execution host

* fix(terminal): preserve active PTY host routing

Co-authored-by: Orca <[email protected]>

* test(terminal): remove superseded host-routing cases

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Jinwoo-H <[email protected]>
Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… Bash) (stablyai#7620) (stablyai#8948)

Shift+Enter still submitted instead of inserting a newline when Droid ran in
Git Bash on Windows, even after the PowerShell fix (stablyai#7620/stablyai#8065/stablyai#8427).

On Windows, Orca sends Droid the kitty CSI-u byte (ESC [ 13;2u) for Shift+Enter
only when the active pane has fresh, trusted process evidence that Droid is the
foreground app; otherwise it falls back to the Codex-compatible ESC+CR, which
Droid decodes as a plain Enter and submits. That trusted evidence comes from a
confirming foreground read.

PowerShell triggers that read from its OSC 133 command-start event. Git Bash
(and cmd.exe) emit no OSC command boundary, and an Orca-launched agent delivers
its command programmatically (no typed-command inference), so a fresh Droid
spawn in those shells never earned routing trust -- leaving Shift+Enter on the
ESC+CR fallback forever.

Fix: on a fresh spawn into a no-OSC shell, seed the SAME command-start
confirmation the manually-typed launch path already uses
(paneForegroundAgentTracker.onCommandStarted). Its bounded retry ladder spans
Droid boot, and -- crucially -- a miss publishes shellForeground:false, so the
pane stays recoverable by later focus/reveal samples. (A visible-pty sample was
rejected here: on a pathologically slow boot its known-agent shell-confirm would
latch, clear launch identity, and permanently poison Shift+Enter for the rest of
the session.) A real OSC 133;C, if it arrives, simply supersedes this.

Verified on Windows 11 + Git Bash with the real Droid CLI and node-pty ConPTY:
- Droid's TUI treats ESC [ 13;2u as a newline (two-line composer) and ESC+CR as
  a submit -- exactly the reported bug and the fix's mechanism.
- droid.exe is a descendant of bash inside the ConPTY console process list (so
  the main-side scan resolves it) and becomes a live process ~0.8s after launch,
  well within the retry ladder.
Tests: regression test drives the real connectPanePty spawn path and asserts
csi-u; a slow-boot test exercises the shell->droid ladder transition; a
recoverability test proves a total-miss does NOT poison the pane (it fails
against the visible-pty approach and passes with onCommandStarted).
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