Repository navigation
fix(terminal): keep keys typed into a starting agent pane as an unsubmitted draft - #33315
Conversation
Walkthrough
Priority: Merge Risk:
|
dcd3566 to
f8a7e67
Compare
There was a problem hiding this comment.
Actionable comments posted: 2

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:
56595639-b356-4c83-852d-6bd5bd1482ee
Commits-
Reviewing files that changed from the base of the PR and between c4c41ac and dcd3566b27b8fae9a685c4a1e77fee80f5af240c.
Files selected for processing: 13-
src/renderer/src/components/terminal-pane/agent-pre-ready-typed-draft.test.tssrc/renderer/src/components/terminal-pane/pty-connection-preconnect-input.test.tssrc/renderer/src/components/terminal-pane/pty-connection/agent-pre-ready-typed-draft.tssrc/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.tssrc/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.tssrc/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.tssrc/renderer/src/components/terminal-pane/pty-connection/pane-transport-options.tssrc/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.tssrc/renderer/src/components/terminal-pane/pty-connection/read-pane-size.tssrc/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.tssrc/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.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; 1 remain after this review.
-
| if (wasUserInput) { | ||
| draft = appendTypedDraftText(draft, data, PTY_PRECONNECT_INPUT_MAX_CODE_UNITS) | ||
| } |
There was a problem hiding this comment.
🔎 Supported by static analysis
-
Script executed:
#!/bin/bash # Find producers and consumers of the remount handoff. rg -nP -C4 'onPreconnectInput|PtyPreconnectInputEntry' src/renderer/src --type=ts -g '!**/*.test.ts'
Repository: stablyai/orca
Length of output: 23043
Script executed:
set -o pipefail printf '%s\n' '--- agent-pre-ready-typed-draft.ts ---' nl -ba src/renderer/src/components/terminal-pane/pty-connection/agent-pre-ready-typed-draft.ts printf '%s\n' '--- terminal-pane-pane-created.ts relevant block ---' nl -ba src/renderer/src/components/terminal-pane/terminal-pane-pane-created.ts | sed -n '130,225p' printf '%s\n' '--- pane-transport-options.ts ---' nl -ba src/renderer/src/components/terminal-pane/pty-connection/pane-transport-options.ts | sed -n '1,80p' printf '%s\n' '--- deferred-split-pane-handoff.ts ---' nl -ba src/renderer/src/components/terminal-pane/deferred-split-pane-handoff.ts | sed -n '1,240p' printf '%s\n' '--- draft installation and disposal references ---' rg -n -F --glob '*.ts' -e 'installAgentPreReadyTypedDraft' -e 'discardAgentPreReadyDraft' -e 'captureAgentPreReadyInput' -e 'dispose()' src/renderer/src/components/terminal-pane/pty-connection src/renderer/src/components/terminal-pane | head -200
Repository: stablyai/orca
Length of output: 41236
Script executed:
set -o pipefail printf '%s\n' '--- session-reconcile-dispose.ts ---' nl -ba src/renderer/src/components/terminal-pane/pty-connection/session-reconcile-dispose.ts | sed -n '135,165p' printf '%s\n' '--- deferred-split-pane-handoff.ts append/claim/release ---' nl -ba src/renderer/src/components/terminal-pane/deferred-split-pane-handoff.ts | sed -n '90,230p' printf '%s\n' '--- handoff creation/claim references ---' rg -n -C5 -F --glob '*.ts' -e 'beginDeferredSplitPaneHandoff' -e 'claimDeferredSplitPaneHandoff' -e 'handoffForInput' src/renderer/src/components/terminal-pane
Repository: stablyai/orca
Length of output: 43555
Script executed:
set -o pipefail printf '%s\n' '--- deferred-split-pane-handoff.ts lifecycle ---' nl -ba src/renderer/src/components/terminal-pane/deferred-split-pane-handoff.ts | sed -n '77,240p' printf '%s\n' '--- all deferred handoff lifecycle references ---' rg -n -C6 -F --glob '*.ts' -e 'beginDeferredSplitPaneHandoff' -e 'claimDeferredSplitPaneHandoff' -e 'appendDeferredSplitPaneInput' -e 'clearDeferredSplitPaneHandoff' -e 'releaseDeferredSplitPaneHandoff' src/renderer/src/components/terminal-pane
Repository: stablyai/orca
Length of output: 41735
Forward captured agent draft input to the deferred split handoff.
For a deferred agent split, captureAgentPreReadyInput consumes user input and stores it only in the session closure. A whole-tab remount releases the handoff, but disposal clears the closure-local draft. The next session can restore only entries recorded through onPreconnectInput.
Suggested fix
-
--- "a/src/renderer/src/components/terminal-pane/pty-connection/agent-pre-ready-typed-draft.ts" +++ "b/src/renderer/src/components/terminal-pane/pty-connection/agent-pre-ready-typed-draft.ts" @@ -86,9 +86,10 @@ if (phase !== 'capturing') { return false } if (wasUserInput) { draft = appendTypedDraftText(draft, data, PTY_PRECONNECT_INPUT_MAX_CODE_UNITS) + session.deps.onPreconnectInput?.({ data, kind: 'ordinary', inputKind: 'driving' }) } // Pre-bind focus reports have no terminal to reach. return true }
| if (!freshSpawn) { | ||
| // A reattached agent is already running; its composer takes the draft now. | ||
| void pasteDraft(ptyId, draftAgent) | ||
| return | ||
| } |
There was a problem hiding this comment.
🔎 Supported by static analysis
-
Script executed:
#!/bin/bash # Find every caller of bindActivePanePty and every writer of spawnedFreshPtyId. rg -nP -C4 '\bbindActivePanePty\s*\(' src/renderer/src/components/terminal-pane --type=ts -g '!**/*.test.ts' rg -nP -C3 'spawnedFreshPtyId' src/renderer/src/components/terminal-pane --type=ts -g '!**/*.test.ts' # Check how the cold-restore path binds and whether it uses onPtySpawn. rg -nP -C4 'buildColdRestoreAgentResumeStartup|coldRestore' src/renderer/src/components/terminal-pane/pty-connection --type=ts -g '!**/*.test.ts'
Repository: stablyai/orca
Length of output: 41326
Script executed:
set -eu printf '%s\n' '--- draft flow ---' sed -n '1,240p' src/renderer/src/components/terminal-pane/pty-connection/agent-pre-ready-typed-draft.ts printf '%s\n' '--- bind implementation and interface references ---' rg -n -F --glob '*.ts' -e 'bindActivePanePty:' -e 'bindActivePanePty =' -e 'bindActivePanePty(' -e 'onAgentPreReadyDraftPtyBound' src/renderer/src/components/terminal-pane/pty-connection printf '%s\n' '--- cold restore startup and bind-related flow ---' sed -n '220,330p' src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts sed -n '1,180p' src/renderer/src/components/terminal-pane/pty-connection/cold-restore-resume-startup.ts sed -n '1,240p' src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts printf '%s\n' '--- transport bind callbacks ---' rg -n -P -C6 'onPtySpawn|onPtyReady|bindActivePanePty|coldRestore' src/renderer/src/components/terminal-pane/pty-connection/pty-transport.ts src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-connect.ts
Repository: stablyai/orca
Length of output: 40011
Script executed:
set -eu printf '%s\n' '--- reattach result continuation ---' sed -n '220,520p' src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts printf '%s\n' '--- transport files and bind callbacks ---' rg --files src/renderer/src/components/terminal-pane | rg 'pty-transport|transport' rg -n -P -C8 'onPtySpawn|bindActivePanePty|callbacks.*spawn|spawn.*callback' src/renderer/src/components/terminal-pane --glob '*.ts' --glob '!*.test.ts' printf '%s\n' '--- startup delivery symbols ---' rg -n -P -C8 'applyColdRestoreAgentResumeStartup|schedulePendingStartupCommandDelivery|pendingStartupCommand|startupCommand' src/renderer/src/components/terminal-pane/pty-connection --glob '*.ts' --glob '!*.test.ts'
Repository: stablyai/orca
Length of output: 42331
Script executed:
set -eu printf '%s\n' '--- pane bind implementation ---' sed -n '1,210p' src/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.ts printf '%s\n' '--- renderer transport connect contract ---' sed -n '1,300p' src/renderer/src/components/terminal-pane/pty-transport.ts printf '%s\n' '--- connect option types and IPC implementation references ---' rg -n -P -C8 'interface.*Connect|type.*Connect|connect\(|command\??:|startupCommandDelivery|coldRestore' src/renderer/src/components/terminal-pane/pty-transport-types.ts src/main src/renderer/src/components/terminal-pane --glob '*.ts' --glob '!*.test.ts' | head -n 500
Repository: stablyai/orca
Length of output: 41527
Script executed:
set -eu printf '%s\n' '--- IPC connect implementation ---' sed -n '1,360p' src/renderer/src/components/terminal-pane/ipc-pty-connect.ts printf '%s\n' '--- connect option declarations ---' sed -n '1,260p' src/renderer/src/components/terminal-pane/pty-transport-types.ts printf '%s\n' '--- direct connect call sites ---' rg -n -P -C10 'connectIpcPty\(|coldRestore:|onPtySpawn\?\.' src/renderer/src/components/terminal-pane src/main/ipc --glob '*.ts' --glob '!*.test.ts'
Repository: stablyai/orca
Length of output: 42795
Script executed:
set -eu printf '%s\n' '--- fresh-spawn bind caller ---' sed -n '180,260p' src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts printf '%s\n' '--- deferred reattach-choice bind callers ---' sed -n '90,220p' src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-choice.ts printf '%s\n' '--- cold-restore reattach binding block ---' sed -n '210,300p' src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts
Repository: stablyai/orca
Length of output: 14644
Script executed:
set -eu printf '%s\n' '--- fresh spawn startup construction ---' sed -n '1,230p' src/renderer/src/components/terminal-pane/pty-connection/fresh-spawn-start.ts printf '%s\n' '--- spawn request construction ---' sed -n '1,300p' src/renderer/src/components/terminal-pane/ipc-pty-spawn-request.ts printf '%s\n' '--- host spawn API consumers ---' rg -n -P -C10 'spawnPty|coldRestore|commandDelivery|startupCommandDelivery|resumeProviderSession' src/main/ipc src/main --glob '*.ts' | head -n 500
Repository: stablyai/orca
Length of output: 42161
Script executed:
set -eu printf '%s\n' '--- command delivery and cold-restore host paths ---' rg -l -P 'commandDelivery|startupCommandDelivery|coldRestore' src/main/ipc src/main/pty src/main/runtime src/main --glob '*.ts' --glob '!*.test.ts' | sort -u | head -n 120 printf '%s\n' '--- focused definitions and handlers ---' rg -n -P -C12 'commandDelivery|startupCommandDelivery|coldRestore' src/main/ipc/pty src/main/ipc src/main/runtime --glob '*.ts' --glob '!*.test.ts' | head -n 800
Repository: stablyai/orca
Length of output: 42376
Wait for agent readiness after a cold restore.
A cold-restore result skips onPtySpawn, then the fallback bind calls bindActivePanePty. This sets freshSpawn to false, so pasteDraft runs without waitForAgentDraftInputReady.
Treat a cold-restore bind with resume startup as a fresh startup for draft delivery. The resume command is passed to the spawn request before the bind, so the issue is not proven to be draft text preceding the command itself. The draft can still be sent while the resumed agent is initializing.
f8a7e67 to
d520406
Compare
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:
6bb68d01-9942-4d99-a713-ccda5af6f7e4
Files selected for processing: 6-
src/renderer/src/components/terminal-pane/agent-pre-ready-typed-draft.test.tssrc/renderer/src/components/terminal-pane/pty-connection-preconnect-input.test.tssrc/renderer/src/components/terminal-pane/pty-connection/agent-pre-ready-typed-draft.tssrc/renderer/src/components/terminal-pane/pty-connection/pane-pty-visibility-bind.tssrc/renderer/src/components/terminal-pane/pty-connection/pane-transport-options.tssrc/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
-
| if (isDeferredSplitInputHold(session)) { | ||
| return true | ||
| // Why not mainStartsPane: a deferred split keeps holding under the layout-owner build, as before. | ||
| return !paneHasKnownStartupWork(session) |
There was a problem hiding this comment.
🔎 Supported by static analysis
-
Script executed:
sed -n '1,115p' src/renderer/src/components/terminal-pane/pty-connection/pane-transport-options.ts rg -n 'preconnectInput|paneHasStartupWork|onPreconnectInput' src/renderer/src/components/terminal-pane/pty-connection src/renderer/src/components/terminal-pane/pty-connection-preconnect-input.test.ts
Repository: stablyai/orca
Length of output: 8063
Script executed:
sed -n '1,140p' src/renderer/src/components/terminal-pane/pty-connection/agent-pre-ready-typed-draft.ts echo '--- preconnect consumers ---' rg -n -F --glob '*.ts' -e 'onPreconnectInput' -e 'preconnectInput' -e 'bufferInputUntilConnect' -e 'releasePreconnectInput' src/renderer/src src/shared src/main || test "$?" -eq 1
Repository: stablyai/orca
Length of output: 20643
Keep handed-off input for non-agent startup splits.
Restoring the hold for this case would send the seed to the shell before its startup command, so the seed needs a different delivery path. For a deferred split with a non-agent paneStartup and a non-empty preconnectInput, holdsInputUntilConnect returns false. buildPaneTransportOptions then omits preconnectInput. No other code reads session.deps.preconnectInput for this case, so the handed-off text is dropped without a notice. Before this change, deferred splits held this input and flushed it at bind.
Do not restore the hold as-is. The held seed would flush before the non-agent startup work, which is the ordering problem the comment at pane-transport-options.ts lines 26-30 describes. Deliver the seed through a path that runs after the startup work, or preserve it some other way that keeps the launch order.
ELI5
If you type into an agent pane while the agent is still starting, Orca now keeps what you typed. Once the agent is ready, the text appears in its input box as a draft, not sent. Before this change, those keys were thrown away.
What Changed
Before: in an agent pane (Claude, Codex and similar), keys typed before the terminal existed were dropped. In one captured run, the first agent spawn after a reload took 30 s. Everything typed in that window was lost.
After:
--resumeis typed into next.Things that stay the same:
Mechanism:
agent-pre-ready-typed-draft.ts.forwardPtyInputhands it user keystrokes before they reach the transport.waitForAgentDraftInputReady, with each agent's ready signal and timeout;sendAgentDraftPasteContentfor the bracketed paste;createPasteReadinessTimeoutNoticefor the drop notice.bindActivePanePty).Split-handoff race (follow-up from #33281): a deferred split with startup work used to hold keys in the transport. The transport would flush them at bind, which is ahead of the startup command. Now:
No current path creates a split with both an inherited working directory and startup work, so this race is closed rather than one that was firing.
Why
Reusing the launch-draft readiness and paste path means typed text uses the same ready signals, timeouts, paste chunking and notice that launch drafts already rely on. Delivering keys raw after readiness would let a stray Enter submit a half-typed prompt. Dropping everything silently is today's bug. An unsubmitted draft keeps what the user typed and leaves the decision to send with them.
Linked Issue
N/A (internal). Follow-up to #33281, which is merged.
Visual Proof
Screenshots from the manual run, described in Testing. Not attached here.
Testing
New
agent-pre-ready-typed-draft.test.tscovers:1and Enter go live, and the draft is never pasted;sendInputand a later bind pastes nothing;The three core capture tests fail when the capture is disabled. The three post-bind tests fail if keys typed after the bind are added to the draft.
Manual run (hidden dev build,
ORCA_BACKGROUND_LAUNCH=1, CDP, isolated profile). To make the spawn slow, I paused this test instance's own terminal host process for a few seconds:fix the flaky test+ Enter while the tab had no terminal. The text showed up in Codex's composer, not submitted.draft before bindshowed up in Claude's composer, not submitted.prebindbefore the bind andLIVEright after it.LIVEreached Claude's composer, and the held text was not pasted.pty-connection-preconnect-input.test.ts:pnpm tc,check:code-quality:changedand the fullterminal-panesuite pass. One load-sensitive file timed out in the full run and passes on its own.Also moved two grid readers from
pty-input-forward.tstoread-pane-size.ts, with no logic change, to keep the file under its line limit.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)