Repository navigation
Description
Bug: Pi Shift+Enter submits instead of newline in Orca terminal (Windows)
Operating system
Windows 11
Orca version
v1.4.168 (and all since v1.4.165 which merged #11769)
Summary
Running Pi in Orca terminal on Windows, Shift+Enter submits instead of newline in three cases: after tool subprocess churn, in restored panes (after restart), and when pi is typed in a shell. In every other terminal Shift+Enter works always. The bug is specific to Orca.
Root cause
Orca resolveWindowsShiftEnterEncoding gates on routingTrusted. When detection fails (tool churn, restored panes, npm-shim mismatch), the resolver returns alt-enter and Orca sends ESC+CR. Pi only reinterprets ESC+CR as shift+enter while its Kitty flag is ON, which flips OFF on the same tool churn. So the byte lands as enter = submit.
CSI-u is the only unconditional byte. Pi parseKey runs parseKittySequence first and unconditionally, no Kitty-flag check. CSI-u = shift+enter = newline in every state.
Three detection failure modes
B1 - tool subprocess churn: a tool spawns a child process, Kitty-keyboard flags reset, foreground trust drops.
B2 - npm-shim process mismatch: pi is an npm shim that execs node pi-coding-agent/dist/cli.js. expectedProcess pi never matches the node process. A typed-pi-in-shell pane is never tagged as Pi.
B3 - restored panes lose the launch tag: agentLaunchConfigByPaneKey is set at launch but is ephemeral, cleared on session transitions. After Orca restart, restored Pi panes have launchAgentType = null.
Local patch fix (title-based fallback)
Add a title-based fallback to getActivePaneWindowsShiftEnterEncoding in keyboard-handlers.ts. When foreground detection returns alt-enter (failed), read the pane OSC title (Pi sets it to Pi via OSC, stable across restore, tool churn, typed-in-shell), use Orca existing resolveCommittedTitleAgentType to recover the agent, and if that agent declares windowsShiftEnterEncoding csi-u (Pi, Droid), return csi-u. Raw shells (title is a cwd) keep the safe alt-enter default. Per-agent config respected. Conservative: foreground detection stays authoritative, title is only a fallback. Scope: 16 lines in one file.
Decent fix for the future (root-cause: reliable detection)
- Detect npm-shim agents by command line, not just process name. Today expectedProcess pi matches the process name, which is node. The agent-status inspector should resolve the shim by matching the command line (pi-coding-agent/dist/cli.js to pi, and likewise for claude, codex). This fixes B2.
- Make foreground detection sticky through tool-subprocess churn. Today a tool spawns a child process, the Kitty-keyboard-flag tracker resets, and foreground trust drops. The detected agent should be latched for the life of the pane. This fixes B1. (Open PR fix(terminal): keep Pi Shift+Enter on CSI-u #9713 attempts this.)
- Persist the launch tag across session restore. Today agentLaunchConfigByPaneKey is cleared on session transitions. Persist and restore it so restored Pi panes keep their tag. This fixes B3.
With those three, resolveWindowsShiftEnterEncodingForPane would return csi-u for Pi panes in every state, the existing three-way policy would send CSI-u, and Pi Shift+Enter would work reliably without any title fallback, while raw shells stay safe and per-agent config is respected.
Related
- [Bug] Shift+Enter submits instead of newline in Pi after running a tool (Windows + Git Bash) — Pi missing windowsShiftEnterEncoding #9703 original bug report
- fix(terminal): trust Pi CSI-u Shift+Enter on Windows (#9703) #11769 merged fix (added csi-u config + foreground detection, incomplete because detection unreliable in B1/B2/B3)
- fix(terminal): keep Pi Shift+Enter on CSI-u #9713 open PR (sticky foreground detection, addresses B1 not B2/B3)
- fix(terminal): stop IME newline defer holding Shift+Enter with no composition (#10203) #11778 closed (wrong layer, IME deferred-newline not the cause)
X handle: @itisvincent
Activity
itisvincent commentedon Aug 4, 2026
Lag root cause found: inputBatcher delays the byte when Pi is idle
The key observation
Root cause:
sendInputuses an input batcherOrca's
sendCapturedTerminalInputcallscapturedTransport.sendInput(data), which pushes the byte to aninputBatcher— a batching queue that coalesces input and flushes on a timer:When Pi is idle (no output streaming), the batcher has no active traffic to trigger a flush, so the Shift+Enter byte sits in the queue until the next flush cycle — causing the ~50-200ms lag.
When Pi is active (streaming output), the batcher flushes frequently (output data keeps the channel hot), so the Shift+Enter byte is flushed quickly — no lag.
Alt+J bypasses this entirely — it goes through xterm.js's native input path (direct
onData→ PTY write), which doesn't use the input batcher. That's why Alt+J is always fast regardless of Pi's idle/active state.Fix: use
sendInputImmediateinstead ofsendInputThe transport has a second method that bypasses the batcher:
The fix is one line in
sendCapturedTerminalInput:This sends the byte immediately (no batcher delay) when
sendInputImmediateis available, falling back to the batchedsendInputwhen it's not. This should make Shift+Enter as fast as Alt+J in all states (idle and active).Why this also explains the "lag gone when working" pattern
The user consistently observed: "the lag is gone when you [Pi] are working." This is because Pi's active output streaming keeps the input batcher flushed — the Shift+Enter byte rides the active flush cycle. When Pi goes idle, the batcher's flush cycle slows down, and the byte is delayed.
Combined with the title-based fallback
The title-based fallback (described above) fixes what byte is sent (CSI-u, which Pi parses unconditionally as
shift+enter). ThesendInputImmediatefix addresses how fast the byte is delivered (immediate, not batched). Together:Both are small, targeted changes in the renderer (
keyboard-handlers.ts/terminal-captured-input-dispatch.ts).fix(terminal): preserve Shift+Enter during routing confirmation
fix(terminal): preserve Shift+Enter during routing confirmation (#13598)
fix(terminal): preserve Shift+Enter during routing confirmation (stab…
fix(terminal): preserve Shift+Enter during routing confirmation (stab…
fix(terminal): preserve Shift+Enter during routing confirmation (stab…