Repository navigation
fix(terminal): stop guessing that apps died and wiping their keyboard modes - #23584
Conversation
… modes The renderer wiped xterm's Kitty keyboard flags on every Ctrl+C, every live reattach, and every Windows agent turn end, though the app usually survives. xterm then encoded keys in legacy form while the pane mirror Orca's shortcut policy reads still held the negotiated flags, so Cmd+C, Shift+Enter, Option/Alt and IME commits disagreed with each other and with the app. - Delete the Ctrl+C wipe, the ConPTY agent-idle wipe, and the mirror reset on every PTY exit (it also ran on unverified host-loss exits). - Live reattach profiles no longer reset Kitty; every replay epilogue instead re-asserts the mirror's flags (pop-all, then the host-proven set; a bare pop while unproven), so a revealed xterm gets the live app's flags back. - Route every renderer-originated mode write through one scanning writer so xterm and the mirror always parse the same bytes: confirmed-shell reset, hibernate, cold restore, and a full process-boundary ground at fresh spawn. - Read Kitty flags as 0 where the protocol is withheld (ConPTY), since xterm ignores CSI u there but the mirror still scans it. - The dashboard popout restores snapshot flags as bytes so its xterm agrees.
Review follow-ups for the stop-guessing change: - The mirror takes a `kittyKeyboard` option from the xterm's advertisement and ignores CSI u when withheld, as xterm does, replacing a per-reader helper that any new reader could skip. Daemon/headless users keep the default. - Replay epilogues are writers (`writeReplayEpilogue`, `writeReattachReplayReset`) that take the sync or async xterm writer, so nothing that looks like a builder mutates the mirror. - An abandoned hidden restore re-asserts the mirror's kitty flags after the byte-gap reset: its discarded chunks were already scanned. - Tests pin a non-zero host restore (epilogue ends `=31u`, mirror 31), a withheld pane staying at 0, and the restart-in-place ground landing after the mirror reset; the epilogue test helper is now an exact builder.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe changes add Kitty keyboard-state restoration to terminal replay and snapshot handling. Reset profiles distinguish reattachment from confirmed-shell resets, and the mode tracker can ignore Kitty sequences when support is disabled. PTY replay and fresh-spawn paths update the tracker and write restore sequences. Dashboard previews use terminal-input capability when configuring the tracker and xterm. Tests cover PTY interrupts, reattachment, parked terminals, and preview replay. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to Reattaching a running app can clear its keyboard modes, while returning to a shell can leave those modes active. Resolve both state-transition failures before merging. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to A reconnect can adopt a still-running app after clearing the terminal’s keyboard modes, with no replay available to restore them. This can break input to that app. The observed effect is limited to the affected terminal; no new privilege boundary or verified security exploit was found. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 24b0f63b-d20e-479f-a18a-b72033954f66
📒 Files selected for processing (48)
src/main/daemon/daemon-pty-spawn-result.tssrc/main/daemon/terminal-mode-rehydrate-sequences.tssrc/main/providers/pty-spawn-result.tssrc/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsxsrc/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsxsrc/renderer/src/components/dashboard-popout/preview-terminal-options.tssrc/renderer/src/components/dashboard-popout/preview-terminal-snapshot-replay.test.tssrc/renderer/src/components/dashboard-popout/preview-terminal-snapshot-replay.tssrc/renderer/src/components/terminal-pane/layout-serialization.test.tssrc/renderer/src/components/terminal-pane/pty-connection-daemon-snapshot-replay.test.tssrc/renderer/src/components/terminal-pane/pty-connection-fresh-spawn-guards.test.tssrc/renderer/src/components/terminal-pane/pty-connection-hidden-codex-queries.test.tssrc/renderer/src/components/terminal-pane/pty-connection-hook-completion-side-effects.test.tssrc/renderer/src/components/terminal-pane/pty-connection-kitty-keyboard-restore.test.tssrc/renderer/src/components/terminal-pane/pty-connection-parked-ssh-snapshot.test.tssrc/renderer/src/components/terminal-pane/pty-connection-reattach-mode-reset.test.tssrc/renderer/src/components/terminal-pane/pty-connection-replay-payload-handling.test.tssrc/renderer/src/components/terminal-pane/pty-connection-stalled-hidden-restore.test.tssrc/renderer/src/components/terminal-pane/pty-connection-test-pane-fixtures.tssrc/renderer/src/components/terminal-pane/pty-connection-test-replay-epilogue.tssrc/renderer/src/components/terminal-pane/pty-connection-windows-keyboard-reset.test.tssrc/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.tssrc/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.tssrc/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-status.tssrc/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.tssrc/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.tssrc/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-abandon.tssrc/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-drain.tssrc/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-snapshot.tssrc/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.tssrc/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.tssrc/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.tssrc/renderer/src/components/terminal-pane/pty-connection/reattach-payload-session.tssrc/renderer/src/components/terminal-pane/pty-connection/reattach-payload-ssh-reconnect-model-paint.test.tssrc/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.tssrc/renderer/src/components/terminal-pane/pty-connection/ssh-snapshot-prepaint.tssrc/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.tssrc/renderer/src/components/terminal-pane/terminal-pane-lifecycle-primitives.tssrc/renderer/src/components/terminal-pane/terminal-pane-pane-input.tssrc/renderer/src/components/terminal-pane/terminal-replay-cursor-state.test.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.tssrc/shared/terminal-kitty-keyboard-mode-tracker.test.tssrc/shared/terminal-kitty-keyboard-mode-tracker.tssrc/shared/terminal-mode-reset-profiles.test.tssrc/shared/terminal-mode-reset-profiles.tstests/e2e/terminal-kitty-reattach-parity.spec.tstests/e2e/terminal-shortcuts.spec.ts
💤 Files with no reviewable changes (6)
- src/renderer/src/components/terminal-pane/terminal-pane-lifecycle-primitives.ts
- src/renderer/src/components/terminal-pane/pty-connection-fresh-spawn-guards.test.ts
- src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.ts
- src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
- src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-status.ts
- src/renderer/src/components/terminal-pane/terminal-pane-pane-input.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| // Why: a fresh spawn is a new process, so a restart-in-place must not | ||
| // inherit the old TUI's screen, mouse or kitty modes in xterm or the mirror. | ||
| session.kittyKeyboardModes.reset() | ||
| session.writeInputModeGround(PROCESS_BOUNDARY_GROUND) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Defer process-boundary grounding until the spawn result confirms a new process.
startFreshSpawn also accepts an isReattach result. src/main/daemon/daemon-pty-spawn-result.ts can return that result without a snapshot. In that case, this write clears the live app’s terminal modes before reattach, and no snapshot replay restores them. Preserve xterm’s state when connect() adopts an existing PTY.
There was a problem hiding this comment.
ℹ️ No critical issues — two defer-able observations below. The core mechanism is sound: I verified against xterm 6.1.0-beta.303 that
kittyKeyboardSet/Query/Push/Popearly-return whenvtExtensions.kittyKeyboardis falsy and that the alt-screen swap is unconditional, so the new mirror's withheld-protocol gate and screen-swap model match xterm exactly.
Reviewed changes
- Removed the three "guessed death" Kitty wipes — the Ctrl+C
RESET_KITTY_KEYBOARD_PROTOCOLwrite (resetTerminalKeyboardProtocolAfterInterrupt, its export, and its call interminal-pane-pane-input.ts), the native-Windows ConPTY idle override (session.idleAgentTerminalModeResetset indirect-ssh-retry-status.ts), and the PTY-exit mirrorreset()inpty-exit-hibernate.ts. - Dropped Kitty from every reattach profile (
POST_REPLAY_REATTACH_RESET,_KEEP_MOUSE,POST_REPLAY_LIVE_AGENT_REATTACH_RESET,buildPostReplayLiveAgentReattachReset) and addedCONFIRMED_SHELL_MODE_RESET= reattach reset + kitty reset for the proven-return-to-shell path. - New replay epilogue restores host-proven flags —
buildKittyKeyboardRestore(provenFlags)emits a pop-all (\x1b[<99u) alone when unproven, plus\x1b[=Nuwhen proven;session.writeReplayEpiloguescans the profile into the mirror first (so?1049l's screen swap is reflected), then the restore, then writesprofile + restoreto xterm so both records parse identical bytes. - One writer for renderer-originated mode bytes —
session.writeInputModeGround/writeReattachReplayReset; every remaining reset (host command-finished ground, confirmed shell, fresh process, cold restore, hibernate, abandoned hidden-restore gap) now routes through the mirror. - Restart in place now writes the full process-boundary ground (
PROCESS_BOUNDARY_GROUND) instead of only resetting the mirror, clearing the dead TUI's alt screen / mouse / kitty state in xterm too. - Withheld-protocol panes —
TerminalKittyKeyboardModeTrackertakes{ kittyKeyboard }and ignoresCSI u; panes derive it fromterminal.options.vtExtensions.kittyKeyboard === true, and the dashboard preview frompreviewAdvertisesKittyKeyboard(...), matching how each xterm was configured. - Tests — new
pty-connection-kitty-keyboard-restore.test.tsand e2eterminal-kitty-reattach-parity.spec.ts; the Ctrl+C shortcut tests rewritten to assert a surviving app keeps flags 31 and a killed app is grounded to 0; many unit tests migrated to a sharedreplayEpilogue(profile, provenFlags?)helper.
ℹ️ A comment in a daemon test now contradicts the code
src/main/daemon/headless-emulator.test.ts:433 still explains the rehydrateSequences assertion with "POST_REPLAY_REATTACH_RESET's deliberate kitty reset must stay authoritative for renderer replays." This PR deleted that reset, so the stated rationale is gone and a future reader may look for a kitty reset that no longer exists. The test's assertions are unaffected; only the comment is stale. Nothing to change in the PR's own files — just worth updating while the context is fresh.
Technical details
# Stale rationale after the kitty reset removal
## Affected sites
- `src/main/daemon/headless-emulator.test.ts:432-441` — the `'never pushes kitty flags into rehydrateSequences'` test cites a reattach kitty reset that `terminal-mode-reset-profiles.ts` no longer emits.
## Required outcome
- The comment reflects the current contract: `rehydrateSequences` omits kitty pushes because renderers re-assert the snapshot's proven flags in their replay epilogue, not because a reattach reset overrides them.ℹ️ Nothing pins xterm's ignore-when-withheld behaviour
The change now relies on xterm silently ignoring CSI = N u / CSI < u on panes where vtExtensions.kittyKeyboard is withheld (ConPTY), so the restore bytes stay inert on both xterm and the mirror. The new tracker test only proves the mirror's half; if a future xterm upgrade stopped gating those handlers on the option, withheld panes would desync with no unit test failing. A small @xterm/headless test (vtExtensions: { kittyKeyboard: false }, write \x1b[=31u, assert the active flags stay 0) would lock the assumption cheaply.
Technical details
# Unpinned external contract
## Affected sites
- `src/shared/terminal-kitty-keyboard-mode-tracker.test.ts:348-356` — asserts only the mirror ignores kitty when withheld.
- `src/renderer/src/components/dashboard-popout/preview-terminal-snapshot-replay.ts` / `pty-connection/fresh-spawn-follow-reset.ts` — write `buildKittyKeyboardRestore(...)` into withheld xterms on the assumption xterm drops them.
## Required outcome
- At least one test exercises a real xterm configured with `vtExtensions.kittyKeyboard: false` and confirms the restore bytes leave its kitty flags at 0.
## Suggested approach (optional)
- Reuse the existing `@xterm/headless` setup in `terminal-snapshot-replay-paint.test.ts`, which already reads `_core.coreService.kittyKeyboard.flags`.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…undary - Reattach callers write `chooseReattachReplayReset(...)` through `writeReplayEpilogue`, dropping the second writer from the session. - Fresh spawn and cold restore rely on their scanned ground alone: it leaves the mirror known at 0 with a proven baseline, so the extra reset() was dead.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Split the reattach reset wrapper into a chooser and one writer —
session.writeReattachReplayResetand the localchooseReattachReplayResetclosure became a publicsession.chooseReattachReplayReset(...)plus an explicitsession.writeReplayEpilogue(profile, write?), with every reattach call site updated; the emitted bytes are unchanged. - Dropped the redundant Kitty
reset()on restart in place and cold restore —writeInputModeGround(PROCESS_BOUNDARY_GROUND)/writeInputModeGround(POST_REPLAY_MODE_RESET)already scan a profile that carriesCSI < 99 u CSI = 0 u(and, for the ground,?1049l), so the mirror ends grounded on the active screen off the alternate screen without the explicit reset. - Updated the session-mock fixtures and the fresh-spawn mirror test to the new surface; the mirror test now asserts the end state (
snapshotFlags === 0,isAlternateScreen === false) rather than the oldreset()-before-scan()invocation order.
I checked the two behavioural edges of dropping reset(): for a withheld (kittyKeyboard: false) tracker the mirror cannot leave flags 0 anyway (every Kitty feed is gated), and for a Kitty-capable tracker the scan re-proves 0 and baselineProven. The profile literals remain pinned byte-for-byte in terminal-mode-reset-profiles.test.ts, so the grounding these paths rely on is still covered.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 6834aa44-1037-4620-b22b-37f31fbb973c
📒 Files selected for processing (9)
src/renderer/src/components/terminal-pane/pty-connection-kitty-keyboard-restore.test.tssrc/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.tssrc/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.tssrc/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.tssrc/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.tssrc/renderer/src/components/terminal-pane/pty-connection/reattach-payload-session.tssrc/renderer/src/components/terminal-pane/pty-connection/reattach-payload-ssh-reconnect-model-paint.test.tssrc/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.tssrc/renderer/src/components/terminal-pane/pty-connection/ssh-snapshot-prepaint.ts
💤 Files with no reviewable changes (1)
- src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| } | ||
|
|
||
| /** Picks the post-replay reset profile for a reattach; the caller writes it via writeReplayEpilogue. */ | ||
| session.chooseReattachReplayReset = ( |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -u
printf '%s\n' '--- changed file diff ---'
git diff --unified=60 7a24d3d335e7e03437000d560a52248e180051b9 16d5652193de3f3bd2024f98041bd45f803006f0 -- src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
printf '%s\n' '--- target file outline ---'
ast-grep outline src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
printf '%s\n' '--- target implementation ---'
sed -n '1,260p' src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
printf '%s\n' '--- ownership and snapshot references ---'
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' "terminalOwner|kitty.*[Ff]lag|kittyFlags|chooseReattachReplayReset|writeReplayEpilogue|reattachReplayResetSequence" src
printf '%s\n' '--- candidate snapshot files ---'
git ls-files | rg 'pty|snapshot|terminal-mode|daemon-pty-spawn-result'Repository: stablyai/orca
Length of output: 41873
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/architecture /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings
Length of output: 47908
🏁 Script executed:
git diff --unified=60 7a24d3d335e7e03437000d560a52248e180051b9 16d5652193de3f3bd2024f98041bd45f803006f0 -- src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
printf '\n--- refs ---\n'
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' "terminalOwner|kitty.*[Ff]lag|kittyFlags|chooseReattachReplayReset|writeReplayEpilogue|reattachReplayResetSequence" src
printf '\n--- files ---\n'
git ls-files | rg 'pty|snapshot|terminal-mode|daemon-pty-spawn-result'Repository: stablyai/orca
Length of output: 41335
🏁 Script executed:
git diff --unified=40 7a24d3d335e7e03437000d560a52248e180051b9 16d5652193de3f3bd2024f98041bd45f803006f0 -- src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
printf '\n--- ownership refs ---\n'
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' 'terminalOwner|kittyFlags|chooseReattachReplayReset|writeReplayEpilogue' srcRepository: stablyai/orca
Length of output: 31271
🏁 Script executed:
pwd; sed -n '1,220p' src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.tsRepository: stablyai/orca
Length of output: 8497
🏁 Script executed:
#!/bin/bash
set -u
for spec in \
'src/main/daemon/session-output-plane.ts:120:180' \
'src/main/daemon/terminal-armed-input-modes.ts:1:180' \
'src/main/daemon/terminal-snapshot.ts:1:80' \
'src/main/daemon/daemon-pty-buffer-snapshots.ts:1:100' \
'src/main/runtime/rpc/methods/terminal/terminal-snapshot-payload.ts:1:80' \
'src/main/daemon/daemon-pty-spawn-result.ts:285:335' \
'src/main/daemon/terminal-shell-armed-input-mode-recovery.test.ts:250:330' \
'src/main/daemon/session-shell-recovery.test.ts:40:105'
do
file=${spec%%:*}; rest=${spec#*:}; start=${rest%%:*}; end=${rest##*:}
printf '\n--- %s:%s-%s ---\n' "$file" "$start" "$end"
sed -n "${start},${end}p" "$file"
done
printf '\n--- ownership/flag writes ---\n'
rg -n -C 4 --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
'readTerminalOwner|readKitty|kitty.*flags|owner.*shell|terminalOwner.*shell|shell.*owner' \
src/main/daemon src/main/runtime src/main/ipc/pty src/shared/terminal-armed-input-modes.tsRepository: stablyai/orca
Length of output: 42533
🏁 Script executed:
sed -n '1,180p' src/main/daemon/terminal-armed-input-modes.ts; sed -n '120,180p' src/main/daemon/session-output-plane.ts; sed -n '250,330p' src/main/daemon/terminal-shell-armed-input-mode-recovery.test.tsRepository: stablyai/orca
Length of output: 11313
🏁 Script executed:
#!/bin/bash
set -u
for spec in \
'src/shared/terminal-mode-reset-profiles.ts:1:180' \
'src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts:70:115' \
'src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts:185:220' \
'src/renderer/src/runtime/remote-runtime-terminal-snapshot-state.ts:85:125' \
'src/main/runtime/orca-runtime-tests/headless-snapshots.spec.ts:451:490'
do
file=${spec%%:*}; rest=${spec#*:}; start=${rest%%:*}; end=${rest##*:}
printf '\n--- %s:%s-%s ---\n' "$file" "$start" "$end"
sed -n "${start},${end}p" "$file"
done
printf '\n--- snapshot flag seeding and reset profile uses ---\n'
rg -n -C 5 --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
'snapshotKittyKeyboardFlags|kittyKeyboardFlags|seed.*Kitty|set.*Kitty|POST_REPLAY_DEAD_TUI_RESET|POST_REPLAY_MODE_RESET' \
src/renderer/src/components/terminal-pane src/renderer/src/runtime src/sharedRepository: stablyai/orca
Length of output: 42121
🏁 Script executed:
sed -n '1,180p' src/shared/terminal-mode-reset-profiles.ts; sed -n '70,115p' src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts; sed -n '451,490p' src/main/runtime/orca-runtime-tests/headless-snapshots.spec.tsRepository: stablyai/orca
Length of output: 13650
🏁 Script executed:
#!/bin/bash
set -u
sed -n '1,250p' src/shared/terminal-kitty-keyboard-mode-tracker.ts
printf '\n--- reset profile tests ---\n'
sed -n '20,145p' src/shared/terminal-mode-reset-profiles.test.ts
printf '\n--- snapshot kitty application ---\n'
sed -n '130,205p' src/renderer/src/components/terminal-pane/pty-connection/hidden-output-seq-and-skip.tsRepository: stablyai/orca
Length of output: 19459
🏁 Script executed:
sed -n '1,250p' src/shared/terminal-kitty-keyboard-mode-tracker.ts; sed -n '20,145p' src/shared/terminal-mode-reset-profiles.test.ts; sed -n '130,205p' src/renderer/src/components/terminal-pane/pty-connection/hidden-output-seq-and-skip.tsRepository: stablyai/orca
Length of output: 19394
Reset Kitty flags for shell-owned snapshots.
terminalOwner: 'shell' does not imply that Kitty flags are zero. The snapshot path can publish poisoned Kitty state with shell ownership, and applySnapshotKittyKeyboardModes restores those flags before writeReplayEpilogue. Both shell branches use profiles without RESET_KITTY_KEYBOARD_PROTOCOL, so the epilogue can reassert the flags on the shell. Use CONFIRMED_SHELL_MODE_RESET for normal-screen snapshots. For alternate-screen snapshots, preserve ?1049l but clear Kitty state before and after the switch.
🐛 Suggested fix
buildPostReplayLiveAgentReattachReset,
+ CONFIRMED_SHELL_MODE_RESET,
POST_REPLAY_DEAD_TUI_RESET,
POST_REPLAY_MODE_RESET,
POST_REPLAY_REATTACH_RESET,
POST_REPLAY_REATTACH_RESET_KEEP_MOUSE,
- buildKittyKeyboardRestore
+ buildKittyKeyboardRestore,
+ RESET_KITTY_KEYBOARD_PROTOCOL
} from '../../../../../shared/terminal-mode-reset-profiles'
...
}
if (terminalOwner === 'shell') {
- return (isAlternateScreen ?? session.kittyKeyboardModes.isAlternateScreen)
- ? POST_REPLAY_DEAD_TUI_RESET
- : POST_REPLAY_REATTACH_RESET
+ const alternateScreen =
+ isAlternateScreen ?? session.kittyKeyboardModes.isAlternateScreen
+ return alternateScreen
+ ? `${RESET_KITTY_KEYBOARD_PROTOCOL}${POST_REPLAY_DEAD_TUI_RESET}${RESET_KITTY_KEYBOARD_PROTOCOL}`
+ : CONFIRMED_SHELL_MODE_RESET
}
ELI5
Programs like Codex and Claude Code can switch the terminal into a richer keyboard mode, so they can tell keys like Shift+Enter apart. Orca used to switch that mode off whenever it guessed the program might have died: on every Ctrl+C, on reconnect, and when an agent went idle on Windows. Usually the program was still running, so Orca's record of the keyboard mode and the terminal's real state stopped matching, and shortcuts broke. Now Orca only resets keyboard modes when it knows the program is gone.
What Changed
Before:
After:
Mechanism:
CSI < 99 u, thenCSI = N u).TerminalKittyKeyboardModeTracker), so the two can't diverge.Why
Other terminals we checked (VS Code, herdr, cmux) never reset keyboard modes on Ctrl+C. The best of them reset at the shell prompt, and Orca's host already does that, with a stricter proof. The OS gives no signal when a program dies, so any automatic reset is a guess. Each alternative we tried traded one heuristic for another:
exec bash;This PR removes the guesses instead. It's the prerequisite for letting Cmd+C reach apps like Codex so they can copy their own highlighted text (#22950).
Accepted trade-off: a program that crashes somewhere the host can't see the command end keeps its modes on until the user resets the terminal, as in the terminals above. That means no shell hooks, after
exec bash, or inside a manualssh. Today, Ctrl+C clears the Kitty mode in that case. A follow-up PR adds a "Reset terminal" action routed through the host.Linked Issue
Related to #9727. This is groundwork for #22950.
Visual Proof
N/A: a keyboard-protocol state change with no visual difference. It's covered by e2e tests that read the pane's keyboard flags. On the old code:
Testing
New tests:
terminal-kitty-reattach-parity: after park/reveal, xterm and the mirror both keep the app's flags.CSI < 99 u CSI = 31 u;Results:
repro-13767real-PTY timeouts, which also fail on the base commit.terminal-shortcuts,terminal-option-composed-ascii, both golden agent specs,terminal-reattach-mouse-mode-leakand the new parity spec.electron-headless) atb9552f240bb:terminal-windows-conpty-keyboard-reset: 1 passed.terminal-shortcuts: 6 passed, 4 skipped. All four skips are macOS/Linux-only by design.Review
Behaviour changes worth checking:
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)