Repository navigation
fix(terminal): clear the Kitty input mirror when a shell is confirmed - #23483
Conversation
There was a problem hiding this comment.
ℹ️ No critical issues — one documentation nitpick.
Reviewed changes
- Confirmed-shell reset now feeds the Kitty mirror —
onConfirmedShellForegroundscansPOST_REPLAY_REATTACH_RESETthroughTerminalKittyKeyboardModeTrackerimmediately before replaying the same bytes into xterm, so shortcut policy stops encoding for the dead app whenever the reset itself is applied. - Tracker class doc corrected — the comment now names the reset paths that actually reach the mirror (Windows ConPTY agent-idle reset and confirmed-shell reset) instead of claiming it is fed only by application output.
- Integration test — asserts the mirror reads
5after a chunk-split\x1b[>5uand0after the confirmed-shell disarm; this is the assertion that fails without the fix. - Headless-xterm agreement test — a real
@xterm/headlessterminal and the tracker both land on0when the reset interrupts a split live Kitty push on the alternate screen. - Test deps type tightened —
paneKittyKeyboardModesRefnow matches the productionMap<number, TerminalKittyKeyboardModeTracker>(pty-connection-types.ts:80).
ℹ️ Nitpicks
src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.ts:165still says the mirror is "fed only from application output ... never from renderer-generated resets". The tracker's updated class comment and this change now contradict that; worth updating it in the same pass.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughConfirmed-shell handling now flushes queued terminal output before it scans post-replay reset bytes with the Kitty keyboard mode tracker and replays them to the terminal. Tests cover split Kitty keyboard sequences and verify that confirmed-shell cleanup clears tracked flags while a still-live agent retains them. The connection test dependency type now uses Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to A narrow synchronized foreground-output case can still deliver Kitty mode-setting bytes after shell cleanup, potentially affecting terminal keyboard behavior. Fix or explicitly accept this before merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change fixes a shell input-mode mismatch in the normal path. A narrower case may remain when terminal output is deliberately held during shell confirmation: older output could arrive after the reset and leave the two mode records out of sync. This appears limited to an affected pane and has not been demonstrated end to end. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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: 8e88f081-6563-43b7-a8ba-3fd8c496254a
📥 Commits
Reviewing files that changed from the base of the PR and between f72079b and 6056428c924b91e406e434001cc3ddd18adf69d6.
📒 Files selected for processing (5)
src/renderer/src/components/terminal-pane/pty-connection-command-finished-cleanup.test.tssrc/renderer/src/components/terminal-pane/pty-connection-test-deps.tssrc/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.tssrc/shared/terminal-kitty-keyboard-mode-tracker.test.tssrc/shared/terminal-kitty-keyboard-mode-tracker.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
6056428 to
30e6233
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Flush before the confirmed-shell reset —
onConfirmedShellForegroundnow drains the pane's queued scheduler output (flushTerminalOutput) before scanningPOST_REPLAY_REATTACH_RESETinto the mirror and replaying it into xterm, so a hidden pane's stale agent bytes reach xterm ahead of the disarm instead of re-arming Kitty modes after it. - Queued-output ordering test — a hidden pane with a live Kitty push still in the background queue asserts that replaying the captured xterm writes in order leaves both the mirror and xterm at
0; I confirmed it fails with the flush removed (xtermView.flagsbecomes5). - Split-sequence headless test — the tracker agrees with a real
@xterm/headlessterminal when the reset interrupts a chunk-split live Kitty push on the alternate screen. - Existing disarm tests tightened — the confirmed-death and live-agent cases now assert the mirror reads
5while armed and0after the confirmed-shell disarm. - Tracker class doc — now names the feeds actually routed through the mirror (application output, snapshot restores, the ConPTY agent-idle and confirmed-shell resets).
One pre-existing documentation nit remains open and unaddressed (non-blocking): connect-pane-pty.ts:165-168 still describes the mirror as "fed only from application output ... never from renderer-generated resets", which the tracker's updated class comment now contradicts — the confirmed-shell reset is renderer-generated and does feed the mirror. Carrying it forward rather than re-flagging.
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: fe68f575-e2fe-4189-9b46-fedc0004fb53
📥 Commits
Reviewing files that changed from the base of the PR and between 6056428c924b91e406e434001cc3ddd18adf69d6 and 30e6233e6b14410168e921fa7e78db80eb6d2fb0.
📒 Files selected for processing (3)
src/renderer/src/components/terminal-pane/pty-connection-command-finished-cleanup.test.tssrc/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.tssrc/shared/terminal-kitty-keyboard-mode-tracker.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/shared/terminal-kitty-keyboard-mode-tracker.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
| @@ -181,6 +182,10 @@ export function installPaneAgentIdentity(session: ConnectPanePtySession): void { | |||
| // Why: a hard-killed agent leaves mouse/focus/kitty modes armed, and the | |||
| // surviving shell then receives pointer moves as typed SGR reports; the | |||
| // replay guard keeps xterm's auto-replies from leaking to the shell. | |||
| // The input mirror scans the same bytes so shortcuts stop encoding for the dead app; | |||
| // draining queued output first keeps both in stream order. | |||
| flushTerminalOutput(session.pane.terminal) | |||
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
sed -n '145,210p' src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
sed -n '1,220p' src/renderer/src/lib/pane-manager/pane-terminal-output-scheduler.ts
rg -n 'flushTerminalOutput|foregroundHold|holdTerminal|coalesc|release.*[Hh]old' src/renderer/src/components/terminal-pane src/renderer/src/lib/pane-managerRepository: stablyai/orca
Length of output: 43611
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- flusher ---'
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-flusher.ts
printf '%s\n' '--- writer ---'
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-writer.ts
printf '%s\n' '--- foreground queue state ---'
cat -n src/renderer/src/lib/pane-manager/pane-terminal-foreground-queue-state.ts
printf '%s\n' '--- queue registry relevant definitions ---'
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-queue-registry.ts | sed -n '1,230p'
printf '%s\n' '--- queue backlog relevant release ---'
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-queue-backlog.ts | sed -n '1,180p'
printf '%s\n' '--- drain ---'
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-drain.ts | sed -n '1,260p'
printf '%s\n' '--- foreground output scan ---'
cat -n src/renderer/src/components/terminal-pane/pty-connection/foreground-output-scan.ts
printf '%s\n' '--- write path ---'
cat -n src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts | sed -n '1,180p'
printf '%s\n' '--- identity tests and foreground setup references ---'
rg -n -C 8 'onConfirmedShellForeground|confirmed shell|foregroundHold|coalesceForeground|POST_REPLAY_REATTACH_RESET|kittyKeyboardModes' src/renderer/src/components/terminal-pane/pty-connection* src/renderer/src/lib/pane-manager/*foreground*test.tsRepository: stablyai/orca
Length of output: 43260
🏁 Script executed:
#!/bin/bash
set -e
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-flusher.ts
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-writer.ts
cat -n src/renderer/src/lib/pane-manager/pane-terminal-foreground-queue-state.ts
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-queue-registry.ts | sed -n '1,230p'
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-queue-backlog.ts | sed -n '1,180p'
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-drain.ts | sed -n '1,260p'
cat -n src/renderer/src/components/terminal-pane/pty-connection/foreground-output-scan.ts
cat -n src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts | sed -n '1,180p'
rg -n -C 8 'onConfirmedShellForeground|confirmed shell|foregroundHold|coalesceForeground|POST_REPLAY_REATTACH_RESET|kittyKeyboardModes' src/renderer/src/components/terminal-pane/pty-connection* src/renderer/src/lib/pane-manager/*foreground*test.tsRepository: stablyai/orca
Length of output: 41995
🏁 Script executed:
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-flusher.ts; cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-writer.ts; cat -n src/renderer/src/lib/pane-manager/pane-terminal-foreground-queue-state.ts; cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-queue-backlog.ts; cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-drain.ts; cat -n src/renderer/src/components/terminal-pane/pty-connection/foreground-output-scan.ts; cat -n src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts | sed -n '1,180p'; rg -n -C 8 'onConfirmedShellForeground|confirmed shell|foregroundHold|coalesceForeground|POST_REPLAY_REATTACH_RESET|kittyKeyboardModes' src/renderer/src/components/terminal-pane/pty-connection* src/renderer/src/lib/pane-manager/*foreground*test.tsRepository: stablyai/orca
Length of output: 42859
🏁 Script executed:
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-flusher.ts
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-writer.ts
cat -n src/renderer/src/lib/pane-manager/pane-terminal-foreground-queue-state.ts
cat -n src/renderer/src/lib/pane-manager/pane-terminal-output-drain.tsRepository: stablyai/orca
Length of output: 30106
🏁 Script executed:
set -e
printf '%s\n' '--- replay guard ---'
cat -n src/renderer/src/components/terminal-pane/replay-guard.ts
printf '%s\n' '--- replay call sites and terminal write bindings ---'
rg -n -C 12 'function replayIntoTerminal|export .*replayIntoTerminal|replayIntoTerminal|writeReplayData|writePtyOutputToXterm' src/renderer/src/components/terminal-pane src/renderer/src/lib/pane-manager
printf '%s\n' '--- confirmed-shell lifecycle and tests ---'
rg -n -C 18 'onConfirmedShellForeground|confirmForegroundProcess|confirmedShell|POST_REPLAY_REATTACH_RESET|kitty.*enable|kittyKeyboard' src/renderer/src/components/terminal-pane/pty-connection src/renderer/src/components/terminal-pane/*test.tsRepository: stablyai/orca
Length of output: 45653
🏁 Script executed:
set -e
cat -n src/renderer/src/components/terminal-pane/replay-guard.ts
rg -n -C 12 'function replayIntoTerminal|export .*replayIntoTerminal|replayIntoTerminal|writeReplayData|writePtyOutputToXterm' src/renderer/src/components/terminal-pane src/renderer/src/lib/pane-manager
rg -n -C 18 'onConfirmedShellForeground|confirmForegroundProcess|confirmedShell|POST_REPLAY_REATTACH_RESET|kitty.*enable|kittyKeyboard' src/renderer/src/components/terminal-pane/pty-connection src/renderer/src/components/terminal-pane/*test.tsRepository: stablyai/orca
Length of output: 45655
🏁 Script executed:
set -e
cat -n src/renderer/src/lib/pane-manager/pane-terminal-foreground-render-settle.ts
rg -n -C 12 'POST_REPLAY_REATTACH_RESET|kitty.*(enable|flag|mode)|\?1u|\?2004h|\?1004h|\?2026h|foregroundHold' src/renderer/src/components/terminal-pane/pty-connection/*test.ts src/renderer/src/lib/pane-manager/*test.tsRepository: stablyai/orca
Length of output: 42188
Drain held foreground output before applying the confirmed-shell reset.
When flushTerminalOutput sees a held or coalesced entry, it returns without writing the queued bytes. replayIntoTerminal then writes the reset directly to xterm, so the scheduler can drain the queued bytes after the reset. A Kitty enable in that held chunk can re-enable stale Kitty flags in xterm after the reset. The Kitty tracker was scanned before the chunk was queued, so this can leave xterm and the tracker out of sync.
Make the reset wait for the queued output, or add an ordered flush that preserves this sequence. Add a regression test with a held foreground chunk containing a Kitty enable sequence.
There was a problem hiding this comment.
Confirmed: flushTerminalOutput skips entries that are held or coalesced by synchronized-output framing, so on that path the reset can be scanned before a held frame reaches xterm. The mis-order only matters if the held frame itself changes Kitty flags, inside the window between the shell being confirmed and the frame releasing. Main is strictly worse here: it never clears the tracker at all. Draining held frames from this call site would mean breaking the synchronized-frame contract. The follow-up redesign moves this reset into the host's output stream, where ordering is exact by construction and this call site goes away. I'm noting it as a known limitation in the PR description.
There was a problem hiding this comment.
@Jinwoo-H, thanks for the clarification. I agree that forcing flushTerminalOutput to drain a held frame would break the synchronized-output contract. The Kitty ordering issue remains possible until the reset enters the host output stream, so I’ll leave this finding open as a known limitation. Would you like a follow-up issue for that redesign?
✏️ Learnings added
Learnt from: Jinwoo-H
Repo: stablyai/orca PR: 23483
File: src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts:187-187
Timestamp: 2026-09-28T05:00:17.683Z
Learning: In `src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts`, `flushTerminalOutput` does not drain output held or coalesced by synchronized-output framing. Forcing a drain at the confirmed-shell reset call site would break that framing contract. A held frame that changes Kitty flags can reach xterm after the renderer scans the reset with `TerminalKittyKeyboardModeTracker`, leaving their states out of sync. Moving the reset into the host output stream is the planned ordering fix.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
You are interacting with an AI system.
A confirmed return to the shell (a host foreground read proving the agent is gone) wrote the Kitty keyboard reset into xterm but not into the renderer's Kitty mode tracker. Shortcut policy reads the tracker, so after an agent died with Kitty flags armed on a host that does not ground the stream itself, Shift+Enter and other chords stayed CSI-u encoded for the plain shell. Scan the same reset bytes through the tracker before xterm parses them, so both records apply identical input. The tracker doc now states its rule: fed by application output and host-proven process boundaries, never renderer guesses. The Ctrl+C and reattach resets are unchanged.
30e6233 to
63ed223
Compare
…main screen's flags
…eset-clears-kitty-tracker
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Tracker per-screen reset assertion —
terminal-kitty-keyboard-mode-tracker.test.tsnow feeds\x1b[?1049lafter the confirmed-shell reset and asserts both the tracker and a real headless xterm report the parked main screen's flags (5), pinning thatscan()clears only the active alternate screen rather than resetting both records. - Mirror doc reword —
connect-pane-pty.tsnow defers toTerminalKittyKeyboardModeTrackerfor its feed list instead of claiming the mirror is fed only by application output; this resolves the prior review's open doc nit.
The merge commit d5847df contributed no net textual change to the PR's files. The tracker suite passes (29 tests).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
When Orca confirms that an agent died and the shell is back, it resets the terminal so the shell stops receiving the agent's special key codes. But Orca keeps a second record of which key format the program asked for, and that record wasn't reset. So after the crash, keys like Shift+Enter were still sent to the shell as agent-style codes. Now both records reset together.
What Changed
The renderer keeps two records of a pane's Kitty keyboard protocol state:
TerminalKittyKeyboardModeTracker, which shortcut policy reads. For example, it decides whether Shift+Enter becomes\x1b[13;2u.When the foreground tracker confirms a return to the shell after a real process read (#9608),
onConfirmedShellForegroundwrotePOST_REPLAY_REATTACH_RESETinto xterm only.\x1b[13;2uto the shell. Those hosts are SSH, sessions on a pre-update daemon, the local fallback, and paired runtimes.Why
scan()rather thanreset():reset()would move the tracker back to the main screen while xterm stays on a dead full-screen app's alternate screen.Linked Issue
N/A (follow-up to #9608)
Visual Proof
N/A: input-encoding state, covered by unit tests; nothing visible changes except which bytes Shift+Enter sends after a confirmed agent death.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Connection test: an agent arms Kitty flags, sent as a split sequence. After the confirmed shell, the tracker reads 0. On current
mainthis fails with "expected 5 to be +0". When the process read still shows the agent after a leaked 133;D, the flags stay armed.Queued output: a hidden pane has a Kitty push still queued when the shell is confirmed, and xterm and the tracker end equal. Without the flush this fails, because xterm gets the reset before the queued push.
Tracker test against a real headless xterm: the reset arrives in the middle of a split live Kitty push on the alternate screen, and xterm and the tracker agree on 0.
Suites: terminal-pane, dashboard-popout, and the shared Kitty and reset-profile suites all pass.
Gates:
pnpm run typecheck, oxfmt,check:code-quality:changedand the anti-slop lint pass.Review
Known limitation: on Windows, synchronized-output frames can be held briefly. Draining queued output skips a held frame, so if the shell is confirmed while one is held, the input mirror scans the reset before that frame reaches xterm. This only matters if the held frame itself changes Kitty flags. Main never clears the mirror at all. The planned host-side redesign moves this reset into the output stream and removes the gap.
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
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)