Skip to content

fix(terminal): keep Pi Shift+Enter newline through detection gaps - #12618

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/bug-pi-shift-enter-submits-instead-of-newline-in
Aug 5, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/bug-pi-shift-enter-submits-instead-of-newline-in

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Aug 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Keep Windows Shift+Enter as a newline in Pi when foreground-process trust temporarily disappears during tool churn, typed launches, or pane restore.
  • Use only the active local Windows ConPTY pane's strict explicit agent title as the fallback; trusted process identity and confirmed shell state remain authoritative.
  • Record explicit routing revocation so a stale Pi/Droid title cannot re-enable CSI-u after exit, Ctrl+C, or focus reconfirmation.

ELI5

Orca already knew the right "newline" code for Pi, but it only used it while a short-lived process check said "this is definitely Pi." Tool runs and restarts can briefly hide Pi from that check, so Orca sent Pi the old Enter-like code and Pi submitted the message.

Now, during only that blind spot, Orca can also read the active pane's explicit "Pi" nameplate and keep sending the newline code. A real process check, a confirmed shell, or an explicit "stop trusting this pane" signal still wins, so ordinary shells and other agents keep their previous behavior.

Why this preserves both behaviors

  • Trusted foreground process evidence wins over the title.
  • Confirmed shell evidence wins over the title.
  • Exit/input/focus revocation blocks the title until a provider confirms the agent again.
  • The title is pane-local, so split siblings cannot inherit it.
  • Strict title parsing rejects cwd fragments such as C:\work\pi-project.
  • Only agents already configured for CSI-u (Pi/Droid) can opt into it; Codex and other agents retain Esc+Enter.
  • Title fallback is limited to local Windows ConPTY, where Orca has the process/shell confirmation lifecycle needed to retire stale titles. SSH, WSL, remote runtimes, macOS, and Linux retain the existing path.

Screenshots

No visual change.

Testing

  • pnpm lint — required static analysis CI passed every lint, freshness, localization, reliability, and max-lines stage.
  • pnpm typecheck
  • pnpm test — all 32 Node 24/26 test shards passed in required PR CI; the focused local suite passed 627/627.
  • pnpm build — Linux and Windows package jobs passed, including packaged CLI smoke tests.
  • Added high-quality regression tests for title fallback, authoritative process/shell precedence, explicit revocation, cwd false positives, unsupported agents, and Zustand persistence.

Proof

Red/green regression:

  • Before the implementation, the new tool-churn/restore title case failed: expected csi-u, received alt-enter.
  • After the implementation: 627/627 affected terminal, foreground lifecycle, shortcut, title-evidence, and store tests pass.

Commands:

  • pnpm exec vitest run --config config/vitest.config.ts ...terminal-windows-shift-enter.test.ts ...keyboard-handlers.test.ts ...terminal-shortcut-policy.test.ts ...pane-agent-evidence.test.ts ...pane-foreground-agent.test.ts ...pty-connection.test.ts — 627 passed after the final SSH/local boundary change.
  • pnpm run typecheck — node, CLI, and web typechecks pass.
  • Changed-file Oxlint, type-aware Oxlint, React Doctor lint, Oxfmt check, and git diff --check — pass.
  • pnpm run check:max-lines-ratchet — pass; no new bypasses.
  • pnpm run check:reliability-gates — 66 gates pass.
  • Required PR CI — 40 successful jobs, 1 expected E2E skip, and the final verify aggregator passed on fdfea2182d.

AI Review Report

Reviewed the regression against merged PR #11769 and closed PR #12299, then traced process trust, OSC titles, restored panes, no-OSC Git Bash/cmd lifecycle, split ownership, IME shortcut dispatch, and local/remote transports.

Main findings and actions:

  • Raw title fallback could undo the safety revocation added by fix(terminal): trust Pi CSI-u Shift+Enter on Windows (#9703) #11769; added routingRevoked and precedence tests.
  • Remote/SSH panes do not have local process confirmation to retire a stale title; limited fallback to local Windows ConPTY.
  • CodeRabbit requested proof that routingRevoked is stored, not just that Zustand replaces the map; added the direct value assertion.
  • Cross-platform review confirmed no shortcut labels, paths, shell commands, or Electron menu accelerators changed. macOS/Linux/WSL/SSH/remote runtime routing is unchanged.

Security Audit

Terminal OSC titles are untrusted process output. The fallback therefore:

  • uses the existing strict committed-title parser rather than substring matching;
  • is scoped to the active pane and local Windows ConPTY;
  • cannot override trusted process evidence, confirmed shell evidence, or explicit routing revocation;
  • only selects an existing allowlisted per-agent byte encoding and performs no command execution, path access, auth, secret, dependency, or IPC expansion.

No follow-up security work is required for this change.

Notes

  • User-visible effect is local Windows Pi/Droid terminal input only.
  • The issue comment's proposed sendInputImmediate change is intentionally out of scope: local IPC already drains in the same turn, while changing remote batching would broaden ordering/performance risk without fixing the incorrect-byte root cause.
  • Required PR CI must be green before merge.

Closes #12541

@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Windows Shift+Enter encoding resolution now accepts the active pane’s runtime title. Committed agent titles can select CSI-u encoding when trusted process evidence is unavailable. Trusted process and shell evidence remain authoritative. Revoked foreground-agent routing blocks title-based selection until reconfirmation. Foreground-agent state updates now track routingRevoked, with tests covering state replacement, reconfirmation, title precedence, and fallback behavior.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement issue #12541 through pane-local title fallback, authoritative evidence precedence, and routing revocation.
Out of Scope Changes check ✅ Passed The implementation and tests remain within the linked issue’s Windows Shift+Enter routing and detection-fallback scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title clearly describes the primary fix for Windows Pi Shift+Enter newline handling during detection gaps.
Description check ✅ Passed The description covers the required summary, screenshots, testing, AI review, security audit, and platform-specific notes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

🧹 Nitpick comments (1)
src/renderer/src/store/slices/pane-foreground-agent.test.ts (1)

31-37: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the stored revocation value.

The current assertion proves only that Zustand created a new mapping object. It does not prove that routingRevoked: true was stored.

Proposed test assertion
     expect(store.getState().paneForegroundAgentByPaneKey).not.toBe(first)
+    expect(
+      store.getState().paneForegroundAgentByPaneKey['tab-1:leaf-1'].routingRevoked
+    ).toBe(true)

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 186e6390-0a5b-48b0-aaf5-a7dd6254c4fe

📥 Commits

Reviewing files that changed from the base of the PR and between 5ed4573 and 732cccf340203a07d9765c4b458bf6d7e36a819d.

📒 Files selected for processing (7)
  • src/renderer/src/components/terminal-pane/keyboard-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/terminal-windows-shift-enter.test.ts
  • src/renderer/src/components/terminal-pane/terminal-windows-shift-enter.ts
  • src/renderer/src/store/slices/pane-foreground-agent.test.ts
  • src/renderer/src/store/slices/pane-foreground-agent.ts

@OrcaWin
OrcaWin force-pushed the OrcaWin/bug-pi-shift-enter-submits-instead-of-newline-in branch from 732cccf to fdfea21 Compare August 5, 2026 02:00
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@OrcaWin

OrcaWin commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed in fdfea21: the test now asserts the stored routingRevoked value directly. I also tightened the title fallback to local Windows ConPTY only after re-auditing SSH/remote title retirement, and updated the PR body with the required template, AI review, security audit, screenshots, ELI5, and proof sections.

@OrcaWin
OrcaWin merged commit 7287ca8 into main Aug 5, 2026
42 checks passed
@OrcaWin

OrcaWin commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Follow-up: universal Shift+Enter compatibility audit

Conclusion

I recommend keeping this PR's capability/evidence-based routing unchanged. I do not recommend replacing it with one universal Shift+Enter byte sequence.

One correction to the original analysis: CSI-u is not Pi's only state-independent representation. Pi also accepts xterm modifyOtherKeys (ESC [ 27 ; 2 ; 13 ~) whether Kitty keyboard mode is active or inactive. That looked like a promising universal fallback, but current Codex rejects it, so it does not change the implementation decision.

The current abstraction remains the right one: Pi and Droid declare their Windows CSI-u requirement through TUI_AGENT_CONFIG; trusted foreground/shell/revocation evidence controls when that capability applies; other applications retain their compatible path. This is capability routing, not a Pi-only conditional.

ELI5

There is no single universal "Shift+Enter" code for terminal apps. It is more like several electrical plug shapes: Pi understands two of them, Codex understands a different overlapping set, and some older apps mistake the modern one for text or ignore it. Orca therefore has to choose the plug that the active program has proven it understands.

Reference implementation findings

  • Ghostty uses CSI-u while Kitty keyboard mode is active and xterm modifyOtherKeys in legacy mode.
  • VS Code enables Kitty support and uses a PowerShell-specific synthetic F12,c sequence plus a matching PSReadLine handler where ordinary VT input is insufficient.
  • Wave sends LF for Shift+Enter.
  • Superset sends Esc+CR.
  • Tabby delegates the decision to xterm.

The mature implementations do not converge on one byte sequence; they negotiate, expose mappings, or add application/shell-specific integration.

Proof

Runtime check against @earendil-works/pi-tui 0.83.0:

Input Kitty inactive Kitty active
CSI-u ESC [ 13 ; 2 u shift+enter shift+enter
modifyOtherKeys ESC [ 27 ; 2 ; 13 ~ shift+enter shift+enter
Esc+CR alt+enter shift+enter
LF enter shift+enter

The same ordering was checked in Pi TUI 0.81.1: CSI-u and modifyOtherKeys are parsed before Kitty-state-dependent legacy mappings.

Current Codex uses its pinned Crossterm parser for Unix VT input. A sequence ending in ~ is routed to parse_csi_special_key_code; its first parameter must be one of the supported numbered special keys. modifyOtherKeys begins with key number 27, which is not supported there, so ESC [ 27 ; 2 ; 13 ~ returns a parse error instead of Shift+Enter. Codex's own keyboard-mode code also notes that xterm-style modified-key sequences are not parsed consistently and cannot enable modifyOtherKeys through the legacy Windows API.

Therefore every proposed universal encoding has a demonstrated incompatibility:

  • CSI-u regresses CSI-u-blind applications.
  • Esc+CR is Alt+Enter in Pi when Kitty state is inactive.
  • LF is Enter in Pi when Kitty state is inactive.
  • modifyOtherKeys works in Pi but fails Codex.
  • Negotiation alone does not cover the Windows ConPTY/tool-churn gap fixed by this PR.

No code follow-up is recommended from this audit.

@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…2618)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
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.

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

3 participants