Skip to content

fix(terminal): route Droid Shift+Enter to CSI-u in no-OSC shells (Git Bash) (#7620) - #8948

Merged
OrcaWin merged 1 commit into
stablyai:mainfrom
OrcaWin:fix/droid-shift-enter-git-bash-7620
Jul 16, 2026
Merged

OrcaWin merged 1 commit into
stablyai:mainfrom
OrcaWin:fix/droid-shift-enter-git-bash-7620

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes the remaining half of #7620: Droid's Shift+Enter still submitted instead of inserting a newline when Droid runs in Git Bash on Windows. PowerShell was fixed in #7620/#8065/#8427; this PR covers Git Bash (and cmd.exe).

Reported in #7620 (comment) ("Droid's Shift+Enter now works in PowerShell, but it still doesn't work in Git Bash.")

Root cause

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 (resolveWindowsShiftEnterEncoding → routingTrusted: true). Otherwise it falls back to the Codex-compatible ESC + CR, which Droid decodes as a plain Enter → submit.

That trust is established by a confirming foreground read (confirmForegroundProcess). The read is only triggered proactively by an OSC 133 command-start event:

  • PowerShell emits OSC 133 (via Orca's shell integration), so launching Droid fires the confirming read → routingTrusted → CSI-u. ✅
  • Git Bash / cmd.exe emit no OSC command boundary. And an Orca‑launched agent delivers its command programmatically (transport.sendInput('droid\r')), which bypasses typed‑command inference. So a fresh Droid spawn in a no‑OSC shell never earned routing trust and Shift+Enter stayed on the ESC+CR fallback forever. ❌

The fresh-spawn code path even documented the (wrong) assumption:

// Why: fresh spawns receive future OSC command-start events; only adopted or
// restored PTYs may already be inside Codex with no new foreground signal.
if (options.sampleVisibleForegroundAgent === true) { … }

Manually typing droid works in Git Bash (typed-command inference schedules the read), which is why the bug looked intermittent — it bites the common launched-agent path.

Fix

On a fresh spawn, sample the foreground process when the pane expects a launch agent, not only on adopt/restore. This is the no‑OSC analog of the OSC 133 command‑start read:

  • Its bounded confirmation retry ladder (reads at ~0.35s / 1.55s / 7.55s) spans Droid's boot.
  • If a real OSC 133;C does arrive (PowerShell), it still supersedes this via onCommandStarted (no double-publish).
  • Gated on paneExpectsLaunchAgent, so plain (non-agent) shell spawns add no extra process read — no perf change there.
-    // Why: fresh spawns receive future OSC command-start events; only adopted or
-    // restored PTYs may already be inside Codex with no new foreground signal.
-    if (options.sampleVisibleForegroundAgent === true) {
+    // …no-OSC shells (Git Bash, cmd.exe) never emit a command-start…
+    const shouldSampleFreshSpawnLaunchAgent =
+      options.seedInitialAgentStatus === true &&
+      paneExpectsLaunchAgent(useAppStore.getState())
+    if (options.sampleVisibleForegroundAgent === true || shouldSampleFreshSpawnLaunchAgent) {
       sampleVisiblePaneForegroundAgent()
     }

The security model is preserved: trust still comes only from a fresh confirmForegroundProcess scan (with ConPTY process-membership filtering), never from stale launch/hook metadata.

Evidence (verified on Windows 11 + Git Bash, real Droid 0.170.0)

1. Main-side detection already works for Git Bash. Driving the real node-pty ConPTY + node-pty's conpty_console_list_agent (the same code readWindowsConptyProcessIds uses):

=== DESCENDANTS of bash ===
  pid=9948 bash.exe → 9952 bash.exe → 7868 bash.exe → 8932 droid.exe
=== GetConsoleProcessList(bash) === {"list":[10220,8932,7868,9952,9948]}
=== droid processes ===
  pid=8932 name=droid.exe inConsoleProcessList=true   cmd=C:\Users\neil\bin\droid.exe

So the foreground scan resolves droid.exe; the problem was purely that the renderer never triggered the read.

2. Timing is covered. droid.exe becomes a live process ~760 ms after launch — well inside the retry ladder, so the +1.55s read catches it.

3. Regression test drives the real connectPanePty spawn path. With the fix it resolves csi-u; reverting the source change makes it fail with alt-enter:

# without fix
REPRO encoding: alt-enter   → test FAILS
# with fix
REPRO encoding: csi-u       → test PASSES

Testing

  • New test: confirms an Orca-launched Droid fresh spawn in a no-OSC shell (Git Bash) — fails without the fix, passes with it.
  • pty-connection.test.ts — 444 passed (full suite).
  • terminal-windows-shift-enter / terminal-shortcut-policy / keyboard-handlers / pane-foreground-agent-tracker — 96 passed.
  • oxlint clean; tsc (web project) clean.

User-facing trade-offs / notes

  • One extra foreground read per agent launch in no-OSC shells (Git Bash, cmd.exe). This is the same read PowerShell already performs via OSC 133, so it's parity, not new cost — and it's one-shot per launch, gated to agent panes.
  • Slow-boot edge case: if Droid takes longer than the ~7.5s retry ladder to appear as a process (measured ~760ms here, so not expected), the first Shift+Enter could still fall back until a later trigger (focus / reveal / plain Enter) re-samples. The existing reactive triggers cover that tail; no regression versus today.
  • Background-launched agents (pane not visible at spawn) are unchanged: they still earn trust on reveal via noteVisibilityResume.
  • Not limited to Droid — any agent with a Windows CSI-u encoding benefits; agents without one (Codex, etc.) keep alt-enter exactly as before.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Fresh PTY binding now resolves the expected TUI launch agent and seeds command-start confirmation when visible foreground sampling is not requested, covering shells without OSC 133 command-start signals. Tests cover immediate and delayed Droid foreground confirmation, bounded retry exhaustion, benign misses, focus-based recovery, trusted routing state, and Shift+Enter encoding.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing required template sections, especially Screenshots, AI Review Report, Security Audit, and Notes. Add the missing sections, including a screenshot/no-visual-change note, an AI review summary, a security audit, and notes that cover cross-platform behavior.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly matches the change: it fixes Droid Shift+Enter routing for no-OSC shells on Windows.
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.

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.

… 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
OrcaWin force-pushed the fix/droid-shift-enter-git-bash-7620 branch from 2712e85 to 45b0d30 Compare July 16, 2026 04:39

@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: a8d5ad93-4c86-4a7f-b236-2c65c9b23574

📥 Commits

Reviewing files that changed from the base of the PR and between 2712e85fa288dabe36ab5d9cc461bbfb92f6f1b1 and 45b0d30.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts

Comment on lines +1898 to +1908
const resolveExpectedLaunchTuiAgent = (): TuiAgent | null => {
const state = useAppStore.getState()
const tab = (state.tabsByWorktree[deps.worktreeId] ?? []).find(
(candidate) => candidate.id === deps.tabId
)
const candidate =
tab?.launchAgent ??
paneStartup?.launchAgent ??
paneStartup?.initialAgentStatus?.agent ??
state.agentLaunchConfigByPaneKey[cacheKey]?.identity.agentType
return isTuiAgent(candidate) ? candidate : null

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.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

Do not seed from tab-shared launch metadata.

tab.launchAgent can leak across split panes, as noted at Line 2054. A fresh generic sibling will therefore run the bounded process-read ladder despite not launching an agent, contradicting the stated no-extra-read guarantee for non-agent shells. Resolve from pane-scoped startup/registered launch identity, and add a negative split-pane test.

Proposed adjustment
     const candidate =
-      tab?.launchAgent ??
-      paneStartup?.launchAgent ??
+      paneStartup?.launchAgent ??
       paneStartup?.initialAgentStatus?.agent ??
       state.agentLaunchConfigByPaneKey[cacheKey]?.identity.agentType

Also applies to: 2766-2769

@OrcaWin
OrcaWin merged commit 9f8b254 into stablyai:main Jul 16, 2026
2 checks passed
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.

1 participant