Repository navigation
fix(terminal): route Droid Shift+Enter to CSI-u in no-OSC shells (Git Bash) (#7620) - #8948
Conversation
📝 WalkthroughWalkthroughFresh 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)
✅ Passed checks (4 passed)
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. Comment |
… 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).
2712e85 to
45b0d30
Compare
There was a problem hiding this comment.
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.tssrc/renderer/src/components/terminal-pane/pty-connection.ts
| 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 |
There was a problem hiding this comment.
🚀 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.agentTypeAlso applies to: 2766-2769
… 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).
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;2ufor 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-compatibleESC + 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:routingTrusted→ CSI-u. ✅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 theESC+CRfallback forever. ❌The fresh-spawn code path even documented the (wrong) assumption:
Manually typing
droidworks 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:
onCommandStarted(no double-publish).paneExpectsLaunchAgent, so plain (non-agent) shell spawns add no extra process read — no perf change there.The security model is preserved: trust still comes only from a fresh
confirmForegroundProcessscan (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 codereadWindowsConptyProcessIdsuses):So the foreground scan resolves
droid.exe; the problem was purely that the renderer never triggered the read.2. Timing is covered.
droid.exebecomes 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
connectPanePtyspawn path. With the fix it resolvescsi-u; reverting the source change makes it fail withalt-enter:Testing
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.oxlintclean;tsc(web project) clean.User-facing trade-offs / notes
noteVisibilityResume.alt-enterexactly as before.