Repository navigation
fix(terminal): one send owns the terminal's input until its last byte - #26676
Draft
brennanb2025 wants to merge 2 commits into
Draft
brennanb2025 wants to merge 2 commits into
brennanb2025 wants to merge 2 commits into
Conversation
Two sends to one shell could interleave as A-text, B-text, A-Enter, B-Enter and run as one merged command. Every writer of a PTY's input on this host (terminal send, desktop keystrokes, paired/mobile input, agent prompt paste/submit, startup commands, mailbox pointers) now goes through one per-PTY, per-incarnation input queue; a send holds it from its first chunk through its Enter, under a bounded hold so a stalled send can never keep the user's typing waiting. Ctrl-C preempts the remaining bytes of a send in progress.
Review round 1: a wall-clock limit on a whole send could fire on healthy work and drop the Enter after the text, recreating merged commands. Replace it with a per-await leak backstop above the providers' own acknowledgment limits, make Ctrl-C stop a send's waits immediately without reordering the user's earlier keys, keep a prompt accepted after its first Enter, let the transaction own its writes, route writers that don't opt in through the same queue, and key the queue by terminal id.
This was referenced Oct 27, 2026
8 of 10 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When two things type into the same terminal at the same moment, Orca could shuffle their keystrokes together. Two
orca terminal send --text "<command>" --entercalls to one shell could come out as one merged line,commandAcommandB, followed by two Enters. The shell then ran a command nobody asked for. Now each send has the terminal to itself from its first character through its Enter, and the next writer waits its turn. Your own typing still always gets through: a send can only hold the terminal for a bounded time, and Ctrl-C always cuts in.What Changed
Before: a single
terminal sendis several separate writes: the text (split into chunks for large pastes), a pause so the terminal can take in the text, then Enter. Nothing kept the terminal reserved across those steps. A second send, a keystroke from the desktop, input from a paired phone or desktop, or an agent prompt could land between one send's text and its Enter. The visible result was two commands merged into one line, or a keystroke inserted into the middle of a command.After:
partial_write/ unverifiable, refused).Mechanism: a new per-terminal input queue in the main process (
src/main/runtime/pty-input-transactions.ts, built onkeyed-operation-queue.ts). It is keyed by the PTY id plus the PTY's incarnation, whichsrc/main/ipc/pty/provider/input-binding.tsbinds from the provider that owns the PTY. A respawned PTY that reuses an id therefore never waits behind, or receives, input meant for the old process. Every writer of terminal input on this host goes through this one queue:terminal send(CLI, mobile, paired multiplex input), viaRuntimeTerminalWriterpty:write/pty:writeAcceptedThe queue keeps the existing "previous entry settles, failure still releases, remove the tail only by identity" pattern. The agent-prompt per-generation queue now reuses the same queue implementation instead of its own copy. When the terminal is idle, a keystroke is written synchronously exactly as before, with no added latency. Every write boundary rechecks the binding: the same PTY incarnation is still current, the transaction has not been preempted, and it is still within its time limit. Terminal query replies (the bytes a terminal answers its own status queries with) keep a narrow bypass so terminal negotiation can't deadlock behind a waiting prompt.
Agent prompts keep their existing per-generation turn reservation. Only the bytes (paste, ingest wait, submit, resubmit) hold the input queue. Checking that the agent actually started a turn now runs after the queue is released, so waiting on an agent never blocks your typing.
Why
The bug is that a send's ownership of the terminal did not span its own writes. Making individual writes ordered can't fix that, because text and Enter are separate writes by design: ConPTY chunking, paste ingest delays, and the permission and generation checks between writes. The fix is one operation queue per terminal on the host that writes the PTY: each input message is written as one unit after the previous operation settles, a failed predecessor still releases the queue, and only the matching tail is removed. Here the unit is a transaction covering all of one send's writes.
Alternatives considered:
terminal send: rejected. Desktop typing, paired input and agent prompts would still land inside a send.Design choices:
Linked Issue
N/A (maintainer root-cause series: control-channel admission, part 1). Related stopgap: #26549.
Visual Proof
N/A. This is a main-process input-ordering change with no UI. Proof is the deterministic ordering tests below. A live run that sends to a shell from two CLIs at once will be added from QA.
Testing
New:
pty-input-transactions.test.ts,pty-input-bounded-hold.test.ts,runtime-terminal-input-transactions.test.ts,runtime-terminal-input-ownership.test.ts,input-binding.test.ts. They cover:sendTerminalandpty:writepaths.Two existing tests updated to the new contract: an abort after the text now still writes Enter, and a refused Enter after accepted text is reported as
partial_write.Targeted vitest (18 files, 194 tests) passed on this head.
tscfor the node project and the repo's static CI checks passed locally.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Review summary will be posted as a comment.
Agent skill upstream boundary
Notes
Author: @BrennanKB5
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)