Skip to content

fix(terminal): stop guessing that apps died and wiping their keyboard modes - #23584

Merged
Jinwoo-H merged 4 commits into
mainfrom
feat/terminal-stops-guessing-input-modes
Sep 28, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
feat/terminal-stops-guessing-input-modes

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​585 $\color{#cf222e}{\Huge{\mathbf{−}}}$​194 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​391
Prod 27 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​143 $\color{#cf222e}{\Huge{\mathbf{−}}}$​120 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​23

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:

  • Pressing Ctrl+C in an agent that keeps running (Codex, Claude Code) erased its keyboard mode in the terminal, but not in Orca's shortcut code. Afterwards Shift+Enter, Option/Alt keys and IME handling could send the wrong bytes.
  • Switching away from a tab and back, or reloading, did the same.
  • On Windows, Grok lost its keyboard mode after every turn.

After:

  • The app keeps its keyboard mode until it exits.
  • Reconnect restores the app's real flags.
  • Orca's record and the terminal's always agree.

Mechanism:

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:

  • a per-terminal "host cleans up here" flag, which went stale after exec bash;
  • checking on every keystroke;
  • turning on shell hooks in every terminal.

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 manual ssh. 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:

  • the surviving-app Ctrl+C test fails (expected 31, received 0);
  • park/reveal parity fails (expected 5, received 0).

Testing

  • Automated tests added/updated
  • I manually tested these changes locally

New tests:

  • e2e terminal-kitty-reattach-parity: after park/reveal, xterm and the mirror both keep the app's flags.
  • e2e, rewritten Ctrl+C test:
    • an app that traps SIGINT keeps flags 31, and ETX is still sent;
    • an app killed by Ctrl+C is grounded to 0 by the host.
  • Unit:
    • reattach restores exactly CSI < 99 u CSI = 31 u;
    • withheld Windows panes stay at 0;
    • restart in place writes the process-boundary reset;
    • a relay-redelivered push followed by one pop leaves both records at 0.

Results:

  • vitest: about 29.9k tests passed across the terminal, daemon, runtime and provider suites. The only failures are two repro-13767 real-PTY timeouts, which also fail on the base commit.
  • e2e (macOS headless): 19 passed and 2 skipped (Windows-only) across terminal-shortcuts, terminal-option-composed-ascii, both golden agent specs, terminal-reattach-mouse-mode-leak and the new parity spec.
  • Windows (ConPTY, electron-headless) at b9552f240bb:
    • 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:

  • Hidden-pane restore: it now pops xterm's whole Kitty stack before setting, instead of leaving the stack alone. That gives up a shell-under-agent stack frame in exchange for xterm and the mirror agreeing.
  • Windows panes without Kitty support: Orca's Shift+Enter and Ctrl+Enter now send legacy bytes to apps that pushed Kitty flags without it being advertised. xterm ignores those pushes there, so this is now consistent. Grok keeps Kitty advertised, and Droid's CSI-u path doesn't read the mirror.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and 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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

… 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.
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

The 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 16d56

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 Review

Security architecture risk: 🟡 Moderate · up to 16d56

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

  • Medium · reliability · inferred: Fresh-spawn startup now clears xterm’s keyboard modes before it knows whether the connection will create a process or adopt a live PTY. A snapshotless, replayless reattach has no subsequent mode restoration, so the running app and terminal can disagree about keyboard input.
Security review details

Security Blast Radius

  • inferred — The identified mode-clear failure affects the terminal pane adopting the PTY. The inspected interface and replay writer do not add cross-process authority or a new PTY-input channel.

Trust Boundaries and Controls

  • observed — Connection-result replay may contain host-produced terminal bytes, but the changed restoration hooks write to the renderer terminal through the replay path; stale-attempt checks constrain when that replay can complete.

Resilience and Maintainability Implications

  • observed — The replay epilogue scans its reset profile before deriving and writing restored flags, and the shared parity test checks mirror and xterm behavior after repeated Kitty pushes. That counterevidence covers replay-bearing restores, not a reattach without a replay payload.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 35 functions across 42 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately describes the main change: removing heuristic keyboard-mode resets when applications may still be running.
Description check ✅ Passed The description is complete and aligned with the template. It explains the user impact, mechanism, rationale, linked issues, testing, behavior changes, platform considerations, and checklist status. T…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 24b0f63b-d20e-479f-a18a-b72033954f66

📥 Commits

Reviewing files that changed from the base of the PR and between a174a08 and b9552f2.

📒 Files selected for processing (48)
  • src/main/daemon/daemon-pty-spawn-result.ts
  • src/main/daemon/terminal-mode-rehydrate-sequences.ts
  • src/main/providers/pty-spawn-result.ts
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
  • src/renderer/src/components/dashboard-popout/preview-terminal-options.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-snapshot-replay.test.ts
  • src/renderer/src/components/dashboard-popout/preview-terminal-snapshot-replay.ts
  • src/renderer/src/components/terminal-pane/layout-serialization.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-daemon-snapshot-replay.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-fresh-spawn-guards.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-hidden-codex-queries.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-hook-completion-side-effects.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-kitty-keyboard-restore.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-parked-ssh-snapshot.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-reattach-mode-reset.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-replay-payload-handling.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-stalled-hidden-restore.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-test-pane-fixtures.ts
  • src/renderer/src/components/terminal-pane/pty-connection-test-replay-epilogue.ts
  • src/renderer/src/components/terminal-pane/pty-connection-windows-keyboard-reset.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.ts
  • src/renderer/src/components/terminal-pane/pty-connection/direct-ssh-retry-status.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-abandon.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-snapshot.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-ssh-reconnect-model-paint.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/ssh-snapshot-prepaint.ts
  • src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-lifecycle-primitives.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-pane-input.ts
  • src/renderer/src/components/terminal-pane/terminal-replay-cursor-state.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/shared/terminal-kitty-keyboard-mode-tracker.test.ts
  • src/shared/terminal-kitty-keyboard-mode-tracker.ts
  • src/shared/terminal-mode-reset-profiles.test.ts
  • src/shared/terminal-mode-reset-profiles.ts
  • tests/e2e/terminal-kitty-reattach-parity.spec.ts
  • tests/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)

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.

🎯 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.

@pullfrog pullfrog 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.

ℹ️ 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/Pop early-return when vtExtensions.kittyKeyboard is 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_PROTOCOL write (resetTerminalKeyboardProtocolAfterInterrupt, its export, and its call in terminal-pane-pane-input.ts), the native-Windows ConPTY idle override (session.idleAgentTerminalModeReset set in direct-ssh-retry-status.ts), and the PTY-exit mirror reset() in pty-exit-hibernate.ts.
  • Dropped Kitty from every reattach profile (POST_REPLAY_REATTACH_RESET, _KEEP_MOUSE, POST_REPLAY_LIVE_AGENT_REATTACH_RESET, buildPostReplayLiveAgentReattachReset) and added CONFIRMED_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[=Nu when proven; session.writeReplayEpilogue scans the profile into the mirror first (so ?1049l's screen swap is reflected), then the restore, then writes profile + restore to 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 — TerminalKittyKeyboardModeTracker takes { kittyKeyboard } and ignores CSI u; panes derive it from terminal.options.vtExtensions.kittyKeyboard === true, and the dashboard preview from previewAdvertisesKittyKeyboard(...), matching how each xterm was configured.
  • Tests — new pty-connection-kitty-keyboard-restore.test.ts and e2e terminal-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 shared replayEpilogue(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`.

Pullfrog  | Fix it ➔ | View workflow run | Using 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.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Split the reattach reset wrapper into a chooser and one writer — session.writeReattachReplayReset and the local chooseReattachReplayReset closure became a public session.chooseReattachReplayReset(...) plus an explicit session.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 carries CSI < 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 old reset()-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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 6834aa44-1037-4620-b22b-37f31fbb973c

📥 Commits

Reviewing files that changed from the base of the PR and between b9552f2 and 16d5652.

📒 Files selected for processing (9)
  • src/renderer/src/components/terminal-pane/pty-connection-kitty-keyboard-restore.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-follow-reset.ts
  • src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-session.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-ssh-reconnect-model-paint.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.ts
  • src/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 = (

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.

🎯 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' src

Repository: 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.ts

Repository: 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.ts

Repository: 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.ts

Repository: 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/shared

Repository: 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.ts

Repository: 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.ts

Repository: 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.ts

Repository: 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
     }

@Jinwoo-H
Jinwoo-H merged commit 3eac4d9 into main Sep 28, 2026
56 checks passed
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.

1 participant