Skip to content

fix(terminal): keep keys typed before a pane's terminal exists - #33281

Merged
nwparker merged 5 commits into
mainfrom
nwparker/queue-pre-pty-input
Oct 25, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/queue-pre-pty-input

Conversation

@nwparker

@nwparker nwparker commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​316 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​316
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53

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:

  • Agent and other startup-work panes still drop keys typed before the terminal exists. That covers agent panes, setup and issue-command panes, and panes that resume an agent with --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.
  • Panes that main starts in the layout-owner build keep today's behaviour. That build is switched off in shipped builds. There, main picks the launch and this window can't see it.
  • Deferred splits hold keys exactly as before. A deferred split is one that waits on its inherited working directory, or is remounted with keys handed off from before the remount. It holds keys whether or not it has startup work, as on main.

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.ts now 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.
  • To decide whether a resume will happen, it uses the same read-only check the resume builder uses (findColdRestoreResumeSource, split out of cold-restore-resume-startup.ts), so the two can't drift.
  • Paired-server panes use a separate transport that already holds input before its terminal binds, so they're unchanged.

The buffer's existing limits and teardown rules still apply:

  • Bounded: at most 1024 entries and a few clipboard-sized pastes. Input past the limit is rejected, just as it was before this change.
  • Dropped on failure: if the spawn or attach fails, or is abandoned (for example, deferred to sleep), the held keys are discarded with a warning.
  • Dropped on close: closing or destroying the pane clears the buffer.
  • Unchanged once live: after the first successful bind the buffer is spent, and input goes straight to the terminal as before.

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 new releasePreconnectInput option. 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:

    • A plain pane holds input before its PTY exists. This fails on main.
    • A slept plain pane drops its held input. This fails on main.
    • Panes with a startup command, a sleeping-agent resume, a live-entry resume, or a main-owned start don't hold input.
    • A deferred split holds input even with startup work, and keeps it through a deliberate sleep, both as before.
  • pty-transport-input-write.test.ts:

    • Keys typed before and during a slow SSH spawn arrive in order once it binds, and later input goes straight through.
    • Held keys are dropped, not flushed, when the recheck fails at bind time. This test fails without the check.
  • 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 full terminal-pane + pane-manager suites 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Follow-up (separate PR):
    • Keys typed into agent panes before the agent is ready will be delivered as an unsubmitted draft.
    • Possible existing race: a deferred split with startup work may flush its held keys ahead of its startup command. This PR doesn't change that path.
  • Not changed here: a 30 s wait before a WSL pane can spawn when its Codex home is Orca-managed. Launch prep waits on a Codex app-server hook-trust session (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.
  • SSH: SSH panes use the same transport. They get ordinary writes only, with no acknowledged writes, which matches their existing behaviour.
  • Mobile: the presence-lock and stale-Codex-pane checks run before buffering, so they still drop input.

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)

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent 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: 30f96cce-8c0e-4371-9ac9-4f3b4b8ae926
Commits

Reviewing files that changed from the base of the PR and between 7aba79f and 4e25315.

Files selected for processing: 6
  • src/renderer/src/components/terminal-pane/pty-connection-preconnect-input.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-transport-options.ts
  • src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.ts
  • src/renderer/src/components/terminal-pane/pty-transport-input-write.test.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/pty-transport.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.

Walkthrough

Pane transport options now select when to buffer input until the first PTY connection binds. The transport rechecks a release predicate before flushing and drops held input when the predicate returns false. The worktree wake path abandons held input on its first wait unless the session is a deferred split. Tests cover buffering conditions, release decisions, deliberate sleep, and SSH input ordering.

Priority: Normal

Merge Risk: Moderate · up to 4e253

Input intended for an agent could run in a replacement shell. Exclude incomplete live agent entries from buffering before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main behavior change: preserving keys typed before a terminal exists.
Description check Passed The description is detailed and covers the user impact, implementation, rationale, testing, scope, limitations, and checklist. It marks the linked issue as N/A despite the template normally requiring …
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.
Full details: Description check

Explanation

The description is detailed and covers the user impact, implementation, rationale, testing, scope, limitations, and checklist. It marks the linked issue as N/A despite the template normally requiring an issue link, but the PR states that it is an internal change and the remaining required sections are substantially complete.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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
  • 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
Commits

Reviewing files that changed from the base of the PR and between 6b46940 and 7aba79f.

Files selected for processing: 8
  • src/renderer/src/components/terminal-pane/pty-connection-preconnect-input.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.ts
  • src/renderer/src/components/terminal-pane/pty-connection/main-pane-start-wait.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/main-pane-start-wait.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pane-transport-options.ts
  • src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.ts
  • src/renderer/src/components/terminal-pane/pty-transport-input-write.test.ts
  • src/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) &&

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.

Major · Functional Correctness · Quick win

🔎 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 {

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