Skip to content

[Bug]: Pi Shift+Enter submits instead of newline in Orca terminal (Windows) - title-based fallback fix + root-cause analysis #12541

Closed

Description

@itisvincent

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)

  1. 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.
  2. 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.)
  3. 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

X handle: @itisvincent

Activity

  1. itisvincent commented on Aug 4, 2026

    @itisvincent
    ContributorAuthor

    Lag root cause found: inputBatcher delays the byte when Pi is idle

    The key observation

    • Alt+J is always fast (even when Pi is idle)
    • Shift+Enter is fast when Pi is active, slow when Pi is idle
    • If the lag were in the PTY-to-Pi path (Pi's rendering), Alt+J would also lag
    • But Alt+J doesn't → the lag is in Orca's sendInput delivery path, not Pi's rendering

    Root cause: sendInput uses an input batcher

    Orca's sendCapturedTerminalInput calls capturedTransport.sendInput(data), which pushes the byte to an inputBatcher — a batching queue that coalesces input and flushes on a timer:

    sendInput(data) {
        if (!connected || !handle || recoveryBlocksIo()) return false;
        if (!data) return true;
        return inputBatcher.push(data);  // ← BATCHED — delayed flush
    }

    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 sendInputImmediate instead of sendInput

    The transport has a second method that bypasses the batcher:

    sendInputImmediate(data) {
        // ...
        inputBatcher.flush();  // flush immediately
        callRuntime("terminal.send", { text, ... });  // send directly
        return true;
    }

    The fix is one line in sendCapturedTerminalInput:

    // Before:
    return capturedTransport.sendInput(data);
    // After:
    return capturedTransport.sendInputImmediate?.(data) ?? capturedTransport.sendInput(data);

    This sends the byte immediately (no batcher delay) when sendInputImmediate is available, falling back to the batched sendInput when 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). The sendInputImmediate fix addresses how fast the byte is delivered (immediate, not batched). Together:

    1. Title fallback → always sends CSI-u for Pi panes → no more submit
    2. sendInputImmediate → sends immediately, no batcher delay → no more lag

    Both are small, targeted changes in the renderer (keyboard-handlers.ts / terminal-captured-input-dispatch.ts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions