Repository navigation
fix(terminal): keep keys typed before a pane's terminal exists - #33281
Conversation
|
No actionable comments were generated in the recent review.
|
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
4f8585b7-9b0c-4a0d-a2cc-b8138560ac24
Files selected for processing: 8-
src/renderer/src/components/terminal-pane/pty-connection-preconnect-input.test.tssrc/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.tssrc/renderer/src/components/terminal-pane/pty-connection/main-pane-start-wait.test.tssrc/renderer/src/components/terminal-pane/pty-connection/main-pane-start-wait.tssrc/renderer/src/components/terminal-pane/pty-connection/pane-transport-options.tssrc/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.tssrc/renderer/src/components/terminal-pane/pty-transport-input-write.test.tssrc/renderer/src/components/terminal-pane/pty-transport-types.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
| return ( | ||
| !session.paneStartup && | ||
| !session.getSleepingRecordForPane(state) && | ||
| !findColdRestoreResumeSource(session, state) && |
There was a problem hiding this comment.
🔎 Supported by static analysis
-
Script executed:
#!/bin/bash # Inspect the pane-start assignments and live-status guards without running repository code. rg -n -C 5 'paneStartup|agentStatusByPaneKey|buildPaneTransportOptions|findColdRestoreResumeSource' \ src/renderer/src/components/terminal-pane/pty-connection
Repository: stablyai/orca
Length of output: 42392
Script executed:
set -o pipefail printf '%s\n' '--- cold restore helper ---' sed -n '1,180p' src/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.ts printf '%s\n' '--- transport and session startup references ---' rg -n -F --glob '*.ts' -e 'buildPaneTransportOptions(' -e 'paneStartup =' -e 'startup:' -e 'initialAgentStatus' -e 'agentStatusByPaneKey' src/renderer/src/components/terminal-pane src/renderer/src/store src/shared | head -n 260 printf '%s\n' '--- relevant session type and connect entry ---' rg -n -F --glob '*.ts' -e 'export type ConnectPanePtySession' -e 'interface ConnectPanePtySession' -e 'createConnectPanePtySession' -e 'connectPanePty' src/renderer/src/components/terminal-pane/pty-connection
Repository: stablyai/orca
Length of output: 44751
Script executed:
set -o pipefail printf '%s\n' '--- cold restore call sites ---' rg -n -C 8 -F --glob '*.ts' -e 'buildColdRestoreAgentResumeStartup' -e 'findColdRestoreResumeSource' -e 'deferredColdRestore' -e 'coldRestore' src/renderer/src/components/terminal-pane/pty-connection | head -n 360 printf '%s\n' '--- pane connection construction and startup input ---' rg -n -C 10 -F --glob '*.ts' -e 'connectPanePty(' -e 'createConnectPanePtySession' -e 'startup: deps.startup' -e 'startup:' src/renderer/src/components/terminal-pane | head -n 360 printf '%s\n' '--- status entry writes and providerSession updates ---' rg -n -C 6 -F --glob '*.ts' -e 'setAgentStatus' -e 'recordAgentProviderSession' -e 'providerSession:' src/renderer/src/store src/renderer/src/components/terminal-pane | head -n 420
Repository: stablyai/orca
Length of output: 42013
Script executed:
set -o pipefail printf '%s\n' '--- provider-session action ---' sed -n '1,240p' src/renderer/src/store/slices/agent-status-provider-session-actions.ts printf '%s\n' '--- status action and launch setup ---' sed -n '1,180p' src/renderer/src/store/slices/agent-status-launch-actions.ts rg -n -C 10 -F --glob '*.ts' -e 'function createAgentStatusActions' -e 'setAgentStatus:' -e 'setAgentStatus (' -e 'setAgentStatus(' src/renderer/src/store/slices | head -n 260 printf '%s\n' '--- deferred reattach setup ---' sed -n '1,130p' src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-connect.ts printf '%s\n' '--- no-provider cold-restore tests ---' rg -n -C 12 -F --glob '*cold-restore*' -e 'providerSession' -e 'startup: null' -e 'without' -e 'missing' src/renderer/src/components/terminal-pane src/renderer/src/store | head -n 320
Repository: stablyai/orca
Length of output: 42501
Script executed:
set -o pipefail printf '%s\n' '--- setAgentStatus implementation ---' rg -n -C 12 -F --glob '*.ts' -e 'setAgentStatus:' -e 'setAgentStatus =' -e 'setAgentStatus (' -e 'setAgentStatus(' src/renderer/src/store/slices/agent-status* | head -n 320 printf '%s\n' '--- focused preconnect tests ---' sed -n '1,240p' src/renderer/src/components/terminal-pane/pty-connection-preconnect-input.test.ts printf '%s\n' '--- focused cold restore test names and no-session fixtures ---' rg -n -C 8 -F --glob 'pty-connection-cold-restore-agent-resume.spec.ts' -e 'providerSession' -e 'agentStatusByPaneKey' -e 'startup:' -e 'it(' src/renderer/src/components/terminal-pane
Repository: stablyai/orca
Length of output: 41552
Script executed:
set -o pipefail printf '%s\n' '--- preconnect test cases ---' nl -ba src/renderer/src/components/terminal-pane/pty-connection-preconnect-input.test.ts | sed -n '100,190p' printf '%s\n' '--- live status action implementation ---' rg -n -l -F --glob '*.ts' 'createAgentStatusLiveActions' src/renderer/src/store/slices file=$(rg -l -F --glob '*.ts' 'createAgentStatusLiveActions' src/renderer/src/store/slices | head -n 1) test -n "$file" && nl -ba "$file" | sed -n '1,260p'
Repository: stablyai/orca
Length of output: 9641
Script executed:
set -o pipefail nl -ba src/renderer/src/store/slices/agent-status-live-actions.ts | sed -n '1,300p'
Repository: stablyai/orca
Length of output: 7900
Script executed:
set -o pipefail printf '%s\n' '--- status payload and entry construction ---' rg -n -C 8 -F --glob '*.ts' -e 'export type AgentStatusPayload' -e 'interface AgentStatusPayload' -e 'providerSession' src/renderer/src/store/slices/agent-status-contract.ts src/renderer/src/store/slices/agent-status-live-entry-builder.ts | head -n 260
Repository: stablyai/orca
Length of output: 17827
Exclude every non-done live agent entry from input buffering.
findColdRestoreResumeSource returns null when the live entry has no valid providerSession. The current guard can then enable bufferInputUntilConnect for that live agent when no startup or sleeping record exists. The buffered input can reach the replacement plain shell.
🐛 Suggested fix
-
--- "a/src/renderer/src/components/terminal-pane/pty-connection/pane-transport-options.ts" +++ "b/src/renderer/src/components/terminal-pane/pty-connection/pane-transport-options.ts" @@ -12,15 +12,17 @@ * resume (sleeping record or live status entry), so a typed prompt would run as a shell command or * corrupt the launch line. A pane main starts is excluded too: main picks its launch, unseen here. */ function holdsInputUntilConnect(session: ConnectPanePtySession): boolean { const state = useAppStore.getState() + const liveAgentEntry = state.agentStatusByPaneKey[session.cacheKey] return ( !session.paneStartup && !session.getSleepingRecordForPane(state) && + !(liveAgentEntry && liveAgentEntry.state !== 'done') && !findColdRestoreResumeSource(session, state) && !mainStartsPane(session) ) } /** The spawn/attach options a pane hands its PTY transport. */ export function buildPaneTransportOptions(session: ConnectPanePtySession): IpcPtyTransportOptions {
ELI5
If you start typing in a terminal before it has finished starting, Orca now holds those keys and sends them once the terminal is ready. Before this change, those keys were thrown away.
What Changed
Before: keys typed into a plain shell before its terminal process existed were thrown away. A common case is the first command typed into the first terminal of a freshly started app, while a cold host (for example, a WSL distro) is still starting the shell.
After: in a plain shell pane, keys typed before the terminal exists are kept. They're delivered in the order they were typed, as soon as the terminal binds. That's the only behaviour change here.
These panes keep today's behaviour:
--resume, from either a sleeping record or a live agent-status entry. Their startup command is written after the shell reports ready, so held keys would land first. A prompt typed during a slow agent start (make the tests pass⏎) would run as a shell command. Without Enter, the text would corrupt the launch line. Delivering keys correctly to agent panes is a separate follow-up.Mechanism: each terminal pane already had a bounded "hold input until connected" buffer in its local transport (
pty-preconnect-input-buffer.ts). Until now it was only switched on for deferred splits.pane-transport-options.tsnow also switches it on for a pane with no startup command, no agent resume and no main-owned start. That covers local, WSL and SSH panes, which all use this transport.findColdRestoreResumeSource, split out ofcold-restore-resume-startup.ts), so the two can't drift.The buffer's existing limits and teardown rules still apply:
Recheck at flush time: whether a pane holds keys is decided when its transport is built, but the resume decision is read again later, at reattach. If a resumable agent entry or sleeping record shows up in between, held keys must not run ahead of
--resume. So when held keys are about to flush, the transport re-runs the same check through a newreleasePreconnectInputoption. If startup work or a resume source has appeared by then, the keys are dropped with a warning instead of flushed. Deferred splits always pass this check, so they flush exactly as on main.Deliberately slept workspaces: a newly held plain shell in a slept workspace drops its held keys when it starts waiting for the wake (
run-deferred-connect.ts). Otherwise keys typed while it sleeps would run in the shell the wake reattaches. Deferred splits aren't affected.Why
Reusing the existing buffer means one tested mechanism for ordering, limits, acknowledged writes and teardown. A second queue would duplicate all of that. Limiting the new holding to plain shells keeps typed text from ever being run ahead of a startup command. I considered buffering only while a spawn request is actually in flight. That misses the time before the request is sent, such as the pane waiting for its first fit. Keys typed in that window were also being lost.
Linked Issue
N/A (internal).
Visual Proof
N/A: there's nothing new on screen. The change is that typed keys arrive instead of disappearing. Unit tests cover it (below).
Testing
New
pty-connection-preconnect-input.test.ts:pty-transport-input-write.test.ts:pty-connection-preconnect-input.test.ts: when a resume source lands after the transport is built, the recheck fails. A deferred split still passes the recheck after startup work appears.These existing tests still cover spawn failure, pane destroy, limits, and acknowledged-write ordering.
pnpm tc,pnpm run check:code-quality:changed, and the fullterminal-pane+pane-managersuites pass. Under heavy machine load, a few unrelated timer-based files timed out; they pass when run on their own.Platforms: macOS unit tests only. Not run manually on Windows, WSL or a live SSH host.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Notes
WSL_GRANT_TIMEOUT_MS). This PR makes keys typed into plain shells survive that wait, but it doesn't shorten the wait. The WSL path needs trust on disk before Codex starts, so bounding it safely means redesigning the order of trust writes. That's a separate change.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)