Pipeline iOS terminal input over ordered mobile RPC
Typing from iOS over the mobile RPC fallback path (used whenever the per-surface iroh lane is not ready: lane opening after attach, suspension after backgrounding, failure recovery) was stop-and-wait since https://github.com/manaflow-ai/cmux/pull/8682: the single input drain awaited a full request/response round trip per 16 KiB batch, so throughput was one batch per RTT and keystroke echo crawled on cellular.
Naive pipelining would reintroduce the reorder bug 8682 fixed, because the Mac handles each RPC frame in its own unstructured Task. Instead of client sequence numbers plus a reorder buffer, this uses the transport as the sequence: the RPC control lane is one ordered byte stream and the Mac decodes frames in arrival order inside the connection actor, so arrival order equals client enqueue order.
Mac side: MobileHostConnection now routes terminal.input/terminal.paste (and their mobile.* aliases) through a per-connection FIFO drained by a single worker, while other methods keep concurrent handling. Queued ordered frames still count toward the MobileHostRPCWorkQuota admission and idle-timeout bookkeeping. The host advertises terminal.input.ordered.v1 in mobile.host.status capabilities.
iOS side: MobileCoreRPCSession gains a two-phase send (beginSend registers the pending settlement and enqueues the frame on the ordered write queue, awaitResponse settles later), exposed as MobileCoreRPCClient.sendRequestPipelined (no authorizationFailed retry, since a retried request would land behind later pipelined work; the caller only uses it on iroh transport-admission routes where no bearer token rides along). The input drain pipelines batches through MobileTerminalInputRPCPipeline: at most 4 unsettled requests, responses settled in FIFO order by one reaper with the same generation-guarded error handling as the legacy path. Before sending on the iroh surface lane while pipelined RPC inputs are unsettled, the drain awaits settlement (the Mac responds after applying input on the serialized path, so settlement means applied) to prevent lane bytes overtaking un-applied RPC bytes; while the lane is not ready it keeps pipelining instead of stalling.
Compatibility: old Mac (no capability) keeps today's one-in-flight stop-and-wait; old iOS against a new Mac is unaffected by serialized handling. No wire-format changes.
Tests: Mac-side serialization (held input #1 blocks input #2 but not a concurrent workspace.list; quota with queued ordered frames; capability advertised), session two-phase settlement (order, settle-before-await, timeout, teardown, cancellation), and composite pipelining via the RoutingHostRouter harness (window of 4 with order preserved, exactly 1 in flight without the capability, lane-activation barrier, operational-error and stale-generation failure paths).
Verification: CmuxMobileRPC 140 passed; CmuxMobileShellModel 179 passed; CmuxMobileShell 786 passed with only the 3 pre-existing main failures (terminalViewportDetachKeepsGenerationTombstoneForStaleAcks, terminalReplayInFlightClearsWhenOutputStreamUnmountsBeforeResponse, staleReplayResponseAfterRemountDoesNotDeliverIntoCurrentStream); pbxproj test wiring lint passed.
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
Pipelines iOS terminal input over the ordered mobile RPC stream to remove stop-and-wait on fallback paths. Keystrokes echo faster on cellular with strict per-surface ordering; stalled response writes don’t block later input, ambiguous failures keep that surface off the lane until reset, and one surface’s delay can’t hold another.
-
New Features
- Mac:
MobileHostConnectionroutes PTY-writing RPCs (terminal.input/terminal.paste/terminal.paste_image/terminal.scroll/terminal.mouse) through per-surface FIFO workers; it authorizes+applies inline and hands response writes to concurrent tasks. Queued ordered frames count towardMobileHostRPCWorkQuota. Host advertisesterminal.input.ordered.v1. - iOS: Added
MobileCoreRPCClient.sendRequestPipelinedwithbeginSend/awaitResponse(up to 4 in flight, FIFO, same cancelled-write demand gate assend(), no auth-retry).MobileTerminalInputRPCPipelineis per surface (entries and reapers), enforces per-surface ordering, and gates lane activation until unsettled pipelined inputs for that surface settle; ambiguous failures (timeout/transport, no host response) keep only that surface on ordered RPC until lifecycle clear. Teardown keeps unclaimed outcomes claimable so laterresponse()reportsconnectionClosed.
- Mac:
-
Bug Fixes
- Clearing the pipeline abandons pending
MobileCoreRPCPipelinedRequests; exactly one capacity waiter resumes per settlement to preserve enqueue order. Per-surface reapers prevent one surface’s stalled response from blocking others. - Ordered worker decouples input application from response writes so a stalled peer can’t freeze later input; stalled sends accumulate under quota and can close the connection instead. Session teardown converts pending pipelined slots to the real teardown failure and retains settled outcomes until claimed.
- Clearing the pipeline abandons pending
Summary by CodeRabbit
- New Features
- Added async-pipelined JSON-RPC requests with a handle for awaiting or abandoning results.
- Implemented ordered terminal input pipelining for compatible connections, preserving input order and limiting in-flight work.
- Advertised the
terminal.input.ordered.v1capability to enable client-side gating.
- Bug Fixes
- Improved pipelined response settlement, timeouts, cancellation, and teardown error propagation.
- Hardened ordered terminal input lifecycle handling and failure routing across connection boundaries.
- Tests
- Added/extended pipelined and ordered terminal input test suites and supporting test transports/mocks.