Repository navigation
fix(mobile): pipeline live terminal input instead of awaiting each RPC (STA-3199) - #15708
brennanb2025 wants to merge 3 commits into
Conversation
Live keystrokes were stop-and-wait on terminal.send, so bursts still paid RTT between the first write and the coalesced tail. Reuse the existing subscribe Input frames so writes return after the socket send, matching desktop multiplex input, and fall back to terminal.send when the host has not advertised a binary stream id. Fixes #12071
STA-3199 moved the live-mirror send out of the session route, so the route's TERMINAL_INPUT_SEND_OPTIONS count drops 4 -> 3. Rather than just lowering the number, assert the new module carries the option too, and that the pipelined stream path - which never reaches terminal.send - gets its now-or-never guarantee from the connection gate instead.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change adds terminal input stream framing with opcode Merge Risk: 🔵 Low · up to Live terminal input now uses the binary stream when available, but a stale connection may reject keystrokes without automatically recovering, temporarily interrupting typing until the connection is refreshed. This bounded risk warrants owner awareness or follow-up, while the change remains mergeable. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5d503bef-7399-407a-9152-a5c8322b987a
📒 Files selected for processing (19)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/src/terminal/send-live-terminal-input.test.tsmobile/src/terminal/send-live-terminal-input.tsmobile/src/terminal/terminal-live-accessory-raw-send.test.tsmobile/src/terminal/terminal-live-accessory-raw-send.tsmobile/src/transport/e2ee.tsmobile/src/transport/mobile-relay-rpc-session.test.tsmobile/src/transport/mobile-relay-rpc-session.tsmobile/src/transport/mobile-relay-rpc-streams.test.tsmobile/src/transport/mobile-relay-rpc-streams.tsmobile/src/transport/rpc-client-encrypted-binary-send.test.tsmobile/src/transport/rpc-client-encrypted-binary-send.tsmobile/src/transport/rpc-client-terminal-input-send.test.tsmobile/src/transport/rpc-client-terminal-input-send.tsmobile/src/transport/rpc-client-terminal-input.test.tsmobile/src/transport/rpc-client.tsmobile/src/transport/stable-logical-rpc-client.test.tsmobile/src/transport/stable-logical-rpc-client.tsmobile/src/transport/terminal-stream-protocol.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
| if (!socket || socket.readyState !== WebSocket.OPEN || !sharedKey) { | ||
| return false |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Recover when the binary socket is stale.
Lines 49-50 return false without invoking onWriteError when the socket is no longer open. If React Native drops onclose, live input returns failed but does not start reconnect recovery. The live-input caller suppresses its terminal.send fallback for failed, so later input is dropped until another recovery path runs.
Route a non-open socket through the current-socket error callback. Add a regression test that changes readyState without calling onclose.
Proposed fix
- if (!socket || socket.readyState !== WebSocket.OPEN || !sharedKey) {
+ if (!socket || !sharedKey) {
return false
}
+ if (socket.readyState !== WebSocket.OPEN) {
+ onWriteError(socket)
+ return false
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (!socket || socket.readyState !== WebSocket.OPEN || !sharedKey) { | |
| return false | |
| if (!socket || !sharedKey) { | |
| return false | |
| } | |
| if (socket.readyState !== WebSocket.OPEN) { | |
| onWriteError(socket) | |
| return false | |
| } |
…path React Doctor flags both on changed lines: TerminalInputStreamRegistry is used only as a type, and Array<T> is forbidden in favour of T[].
|
Close this older input-stream patch while #12071 keeps tracking slow phone typing. The fix needs to use the current connection and stream ownership. |
ELI5
Phone typing into a remote terminal used to wait for the desktop to reply to every keystroke before sending the next one. On a slow link that made letters appear in chunks and keep arriving after you stopped. Live keys now ride the same one-way terminal stream desktop already uses, so typing is no longer gated on a round trip per letter.
What Changed
TerminalStreamOpcode.Inputframes (opcode 7) on the mobileterminal.subscribebinary stream and return after the socket write.RpcClient.sendTerminalInput. Ordered writes and pending-byte coalescing stay; the queue no longer waits on RPC responses.streamId(JSON-only subscribe / lease-only / not yet subscribed), live input still usesterminal.send.terminal.send(avoids duplicate or stale replay after disconnect).Why
Mobile live input was stop-and-wait:
queueTerminalLiveMirrorSendawaitedrpc.sendRequest('terminal.send'), andsendRequestonly resolves when the correlated response arrives. Even with coalescing, a burst was first-key RTT plus remainder RTT, which is the “one visible step every ~0.5s, then drain after you stop” report. Desktop already sends Input frames fire-and-forget on the multiplex stream; the host already accepts those frames onterminal.subscribe. This matches that path instead of inventing a debounce or dropping keys.Linked Issue
Fixes #12071
https://linear.app/stably/issue/STA-3199
Visual Proof
N/A — no UI layout or styling change. The change is send-path latency: live keystrokes no longer wait for an RPC response before the next write.
Testing
terminal.sendwas held (expected '' to be 'abc').'h'+'ello world'concatenates in order with nothing dropped; old-host fallback still coalesces'bc'onto the secondterminal.send.sendTerminalInputbranch (kept the tests): first test went red again (expected '' to be 'abc'), then restored.pnpm vitest run --config vitest.config.tson live-input, rpc-client, relay, logical-client, accessory, pending-flush, and commit tests — 107 passed in the full related set; focused re-run after test-file split still green.pnpm typecheckinmobile/Before / after (deterministic)
Hold the first RPC response, then queue
a,b,c:terminal.sendcallsa), remainder blockedathenbc(joinabc)At 300–500 ms RTT that is the difference between “step every RTT, keep draining after stop” and “all live bytes leave immediately; only echo waits on RTT”.
Remote wire compatibility
Reuse of existing opcode 7 (
Input), not a new opcode, not a host-publish change. Clients send Input only after a numericstreamIdfrom the subscribe handshake, which only binary-stream hosts emit. Older JSON-only hosts never see Input frames and keepterminal.send. Old clients against new hosts are unchanged.Notes
Cross-platform: no keyboard/path changes. SSH/folder: input still goes to the execution host via existing
terminal.send/ stream Input handlers. Compose-box submit and native-chat answer paths still useterminal.send(one-shot, not live typing).Checklist
N/Awith reason