Repository navigation
fix(terminal): send LF for Pi Shift+Enter to stop the CSI-u decode freeze (#10203) - #12299
itisvincent wants to merge 2 commits into
Conversation
…eeze (stablyai#10203) Pi binds Ctrl+J (0x0A) as a newline alias by default, so a 1-byte LF is a fast newline that stays distinct from Enter's CR (no submit, stablyai#9703). The previous csi-u encoding made Shift+Enter correct (newline, not submit) but Pi's CSI-u decode is visibly slower than the 2-byte Alt+J chord - surfacing as the brief input freeze reported in stablyai#10203. Add a 'lf' Windows Shift+Enter encoding that sends \n, and switch Pi to it. The encoding resolver still gates on routingTrusted, so this rides on the Pi Windows foreground detection added in stablyai#11769 (which recognizes both the npm and pnpm-virtual-store cli.js entrypoints). Agents without the override keep the legacy Esc+CR fallback unchanged; Droid stays on csi-u. Verified from source: a test with the reporter's real pnpm command line (E:\pnpm/global/5/.pnpm/@earendil-works+pi-coding-a_<hash>/.../dist/cli.js) is recognized as 'pi' by the foreground detection, so routingTrusted holds and the 'lf' encoding applies.
📝 WalkthroughWalkthroughThe change adds 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
…-scan misses (stablyai#9703 stablyai#10203) The encoding (csi-u/lf) only applied while routingTrusted held, so a single Shift+Enter newline was lost whenever the Windows foreground scan transiently missed the Pi node process during tool-subprocess churn - the 'sometimes not working' intermittency. Fall back to the pane's launch agent when live trust is missing, so a Pi-launched pane keeps its 'lf' encoding across a transient scan miss. shellForeground still fails closed when the agent has exited to a shell. This reverses the prior fail-closed-on-launch-only behavior (the resolver previously returned alt-enter for launch-only and while awaiting fresh trust); the trade-off is accepted because a single Shift+Enter newline byte routed to a stale launch agent is low-harm, whereas losing the newline every tool run is the reported bug.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-windows-shift-enter.test.ts (1)
18-24: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover Pi with an untrusted foreground signal.
The Pi test covers trusted Pi data and launch-only resolution. It does not prove that an untrusted foreground agent cannot override the Pi launch agent. Add a case with
foreground.agent: 'droid',routingTrusted: false, andlaunchAgentType: 'pi'. Assert'lf'.Proposed regression case
expect(resolveWindowsShiftEnterEncoding({ launchAgentType: 'pi' })).toBe('lf') + expect( + resolveWindowsShiftEnterEncoding({ + foreground: { agent: 'droid', routingTrusted: false, shellForeground: false }, + launchAgentType: 'pi' + }) + ).toBe('lf')
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5b91837f-514c-4bdc-a8d8-de9cc0c0fc70
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/terminal-windows-shift-enter.test.tssrc/renderer/src/components/terminal-pane/terminal-windows-shift-enter.ts
Runtime diagnostic confirmed the root causeInstalled the diagnostic build on Windows (v1.4.167 + a The encoding flickers between
After applying this PR (LF + launch fallback)The launch fallback makes the encoding always resolve to Remaining lag vs Alt+JConfirmed: the remaining ~10ms lag vs Alt+J is Orca's #11778 (IME defer) — wrong fix, should be closedThe IME deferred-newline path was NOT firing (no |
|
New finding: |
Closing this PR — LF approach was wrongAfter runtime diagnostic + analysis of Pi's
The correct fix is title-based fallback: when foreground detection fails (returns |
Summary
Fixes the freeze half of #10203 (and supersedes the
csi-uencoding #11769 set for Pi). After #11769, Pi's Shift+Enter correctly inserts a newline instead of submitting, but it is visibly slower than Alt+J — a brief input freeze before the newline lands. That freeze is the cost of Pi decoding the CSI-u sequence (\x1b[13;2u, 6 bytes), versus Alt+J's fast 2-byte\x1bjbinding.Fix
Send a 1-byte LF (
\n, 0x0A) for Pi's Shift+Enter instead of CSI-u. Pi binds Ctrl+J (0x0A) as a newline alias by default — so LF is a fast, reliable newline that:Adds a new
'lf'value towindowsShiftEnterEncoding, switches Pi to it, and routes it in the Shift+Enter policy. Droid stays oncsi-u; agents without an override keep the legacyEsc+CRfallback unchanged.Why this rides on #11769
The encoding resolver still gates on
routingTrusted, so'lf'only applies when the pane's foreground is trusted as Pi. #11769's Windows foreground detection (PI_AGENT_NODE_ENTRYPOINT_RE) is what makes that trust hold — and it covers both the npm path and the pnpm virtual-store path (verified below).Verification (from source)
pnpm typecheck— clean.pnpm exec vitest runon the changed suites — 134/134 pass, including a new policy test that Shift+Enter sends'\n'when the encoding is'lf', and an updated resolver test that Pi resolves to'lf'.pnpm exec oxlint+pnpm exec oxfmt --checkon changed files — clean.D:\programming\SDK\node\node.exe E:\pnpm/global/5/.pnpm/@earendil-works+pi-coding-a_<hash>/node_modules/@earendil-works/pi-coding-agent/dist/cli.js ...→
recognizeAgentProcessFromCommandLinereturns{ agent: 'pi', processName: 'pi' }(the regex matchesnode_modules/@earendil-works/pi-coding-agent/dist/cli.jsat the path tail). SoroutingTrustedholds and'lf'applies for pnpm-installed Pi, not just npm-installed.Relationship to #11778
My earlier #11778 tried to fix the freeze via the IME deferred-newline path, but that was the wrong target — the freeze is CSI-u decode cost, not an IME delay. This PR is the correct fix; #11778 can be closed.
Cross-platform / compatibility notes
piuses'lf'); other agents unchanged.windowsEncodingread), preserving the lazy-call-count behavior the existing tests assert.Reviewer checklist
Closes #10203
X handle: @itisvincent