Repository navigation
fix: Remote Orca Server reconnect liveness — recover mirrors, input routing, and creates after tunnel drops - #7827
Conversation
…play tagging A half-open tunnel (devtunnel/NAT drop) never delivers a ws close, so the client's edge-triggered reconnect never fired while the server reaped its end via its 15s ping/terminate sweep: frozen mirrors, void RPCs, zombie sockets (#7718, #7489). - New remote-runtime-socket-liveness monitor: ping on a cadence (10s) and declare the socket dead when no inbound traffic arrives within 25s; wired into the shared-control socket (open module) and the dedicated stream sockets (terminal.multiplex / browser.screencast) so the existing close -> reconnect/resubscribe paths run. - Shared-control request timeouts now tear the socket down (mirrors RemoteRuntimeRequestConnection) instead of leaving it 'ready'. - Reconnect replays tag the first re-emitted response per subscription (_replayedAfterReconnect, added client-side after wire parsing) so snapshot freshness gates can accept the replayed snapshot. Backward compatible: liveness rides RFC 6455 ping/pong, which every supported server (and the ws package) answers automatically; the replay tag never touches the wire. Co-authored-by: Orca <[email protected]>
…nnect After a shared-control reconnect the server re-emits each stream's current snapshot with an UNCHANGED publicationEpoch/snapshotVersion (the host did not restart), so the monotonic freshness gate shouldApplyWebSessionTabsSnapshot dropped it and mirrored tabs stayed frozen until an app restart (#7718). Responses tagged as reconnect replays now clear the per-env/worktree freshness entry before the gate runs, making the replayed snapshot authoritative while re-priming ordering protection for subsequent frames. Normal-operation out-of-order rejection is unchanged — only tagged replays bypass. Co-authored-by: Orca <[email protected]>
…handles on reconnect Handles are re-minted when a pane's PTY/generation changes, but terminal.send prechecks and terminal.multiplex subscribe resolved via the unguarded resolveLeafForHandle — a stale handle silently bound to whatever PTY now occupies the same pane, misrouting keystrokes and mirrored output after a reconnect (#7718). - New OrcaRuntimeService.resolveLiveLeafForHandle: throws terminal_handle_stale when a handle minted for a concrete PTY no longer matches the pane's PTY/generation; handles still awaiting their first PTY (ptyId null) may adopt it, preserving the mobile pre-spawn subscribe flow. - terminal.send and the multiplex subscribe frame now use the guarded resolver; multiplex answers a stale subscribe with an explicit terminal_handle_stale stream error + end instead of binding the wrong PTY. - Renderer remote PTY transport: on transport close, host-session mirrors re-derive their handle from the current session.tabs.list snapshot instead of resubscribing the stale closure value; input-path errors route through the stale-handle recovery (retire + wait for next snapshot) instead of a dead-end red banner. Co-authored-by: Orca <[email protected]>
…ce-wait failures session.tabs.createTerminal waited up to 10s for the surface publish and, on timeout, closed the freshly created tab unless a fully pane-key-registered live PTY backed it. Two ways that killed real terminals (#7718 symptom 2, #7489 "terminals refuse to open"): - a dead client connection let the wait run down and trigger rollback even though the renderer had spawned a real shell; - a live shell whose pane key had not registered (or is not a terminal-leaf UUID) failed the rescue and fell through to rollback. Now the ws abort signal threads through session.tabs.createTerminal into the reply/surface waits (cancelling them with client_disconnected, never rolling back), and the rollback guard is broadened: any connected PTY bound to the renderer tab keeps the tab alive even when the surface rescue cannot publish it. True spawn failures still roll back. Also carries the regression tests for the stale-handle resolver from the previous commit (same test file). Co-authored-by: Orca <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (24)
📝 WalkthroughWalkthroughThis PR adds stale terminal handle detection (resolveLiveLeafForHandle, terminal_handle_stale) to orca-runtime and terminal RPC methods, plus AbortSignal-based cancellation for mobile terminal creation to avoid incorrect rollback/timeout behavior. The renderer PTY transport now centralizes "terminal gone" error handling and re-derives handles after transport close instead of relying on stale state. Session tabs sync gains replay acceptance to bypass freshness gating after reconnects. A new shared socket-liveness monitor (ping/pong tracking, dead-connection detection) is integrated into the remote runtime client and shared-control connection, alongside reconnect-replay response tagging and refactored stable-reset timer handling. Extensive test coverage accompanies each change. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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 |
Live verification (deterministic half-open repro) — PASSVerified on one machine with two real paired desktop instances routed through a freezable TCP proxy (existing sockets black-hole bytes but stay open — including swallowing the server-side heartbeat terminate so the client leg stays genuinely half-open, exactly like a dead devtunnel; new connections pass so reconnect can succeed). Baseline on
This branch (eac6cd3) — same script:
Residual notes: worst-case detection is the 25s liveness window (comparable to the server's own reaper); screencast stream shares the same liveness code but only terminal.multiplex was live-driven; repro was loopback (WAN jitter has less margin, but detection keys off any inbound activity). |
…outing, and creates after tunnel drops (stablyai#7827) Co-authored-by: Orca <[email protected]>
Fixes #7718
Likely fixes #7489 — same root cause, Windows flavor unverified live.
Symptoms (Remote Orca Server, after a devtunnel/network drop-and-return)
Root cause
The client has no client→server liveness probe, and shared-control reconnect is edge-triggered on a ws
closethat a half-open tunnel never delivers. The server reaps its end via a 15s ping/terminate sweep (ws-transport.ts), so the two sides diverge: the client keeps a zombie socket inreadystate, every push/RPC goes into the void and times out per-request (a shared-control request timeout previously rejected just that request and left the zombie socket alive — unlike the cached request connection, which tears down on timeout).Three secondary bugs kept things broken even once a reconnect did fire:
publicationEpoch/snapshotVersion(host didn't restart). The monotonic freshness gateshouldApplyWebSessionTabsSnapshotrejected it → mirrors stayed frozen forever.terminal.sendprechecks + the multiplex subscribe frame resolved via the unguardedresolveLeafForHandle, which doesn't validate PTY/generation. Handles are re-minted when a pane's PTY changes, so an old handle could route input to / mirror output from a different terminal.session.tabs.createTerminalwaited 10s for the surface publish and on failure closed the freshly created tab unless a fully pane-key-registered live PTY backed it. A dead client connection (the response had nowhere to go) or a live shell without a registered pane key both fell through tonotifier.closeTerminal— the "tab dies after ~10s".Commits
fix(remote-runtime): client-side socket liveness + reconnect replay tagging— newremote-runtime-socket-livenessmonitor (ping every 10s, dead after 25s of silence — just under two server heartbeat periods) wired into the shared-control socket and the dedicated stream sockets (terminal.multiplex,browser.screencast); a dead socket is terminated so the existinghandleSocketClosed → scheduleReconnect/onTransportClose → resubscribepaths run. Shared-control request timeouts now tear the socket down, mirroringRemoteRuntimeRequestConnection. Reconnect replays tag the first re-emitted response per subscription (client-side, post-parse) so freshness gates can accept it.fix(web-session-tabs): accept replayed snapshots— tagged replay responses clear the per-env/worktree freshness entry before the gate runs, making the replayed snapshot authoritative and re-priming ordering protection. Normal-operation out-of-order rejection is untouched (fixes A).fix(terminal): guard stale handles + re-derive mirror handles— new guardedresolveLiveLeafForHandle(throwsterminal_handle_staleon PTY/generation mismatch; still lets a pre-spawnptyId: nullhandle adopt its first PTY, preserving the mobile flow) used byterminal.sendand the multiplex subscribe frame; the renderer transport re-derives host-mirror handles from a freshsession.tabs.liston transport close instead of resubscribing the stale closure value, and routes input-path errors through the existing stale-handle recovery (retire + re-attach on next snapshot) instead of a dead-end red banner (fixes B).fix(terminal): don't roll back live mobile-created terminals— the ws abort signal threads throughsession.tabs.createTerminalinto the reply/surface waits (a dead connection cancels the wait withclient_disconnectedinstead of triggering rollback), and the rollback guard is broadened: any connected PTY bound to the renderer tab keeps the tab alive even when the surface rescue can't publish it. True spawn failures still roll back (fixes C).Backward compatibility
wspackage — no protocol change, no new frame types. The replay tag is added client-side after wire parsing and never touches the wire. The guarded-resolver and create changes are server-side only.terminal.send/ multiplex subscribe now answer stale handles withterminal_handle_staleinstead of silently resolving the wrong PTY; old desktop clients already classify that message as "terminal gone" and recover (isRemoteTerminalGoneMessage). Valid handles behave identically, including the mobile pre-spawnwaitForLeafPtyIdpath. The abort-signal threading only changes behavior for connections that are already dead.Test evidence (all deterministic; suites green)
autoPong: falsethat completes the handshake then goes silent — noclose, no pongs, no frames. Asserts the client heartbeat terminates the socket, reconnects, replays the subscription, and that the replayed response carries the tag while the initial-connect response does not (remote-runtime-shared-control-connection.test.ts). Same scenario for a dedicated stream socket assertingonError+ singleonCloseso the multiplexer's resubscribe path runs (remote-runtime-client.test.ts).web-session-tabs-sync.test.ts).terminal_handle_stale(and that a pre-spawn null-PTY handle still adopts); RPC-level tests proveterminal.sendfails withterminal_handle_staleand multiplex answers a stale subscribe with an error frame + end without ever binding a PTY.client_disconnectedand never callscloseTerminal; a surface-publish stall with a live shell (no registered pane key) times out WITHOUT killing the terminal. Existing rollback tests (true spawn failure, ghost tab) still pass unchanged.orca-runtimesuite and the 718-test terminal/session set),pnpm typecheck, oxlint clean on all changed files, max-lines ratchet OK (split the shared-control connection's liveness/stability wiring into the open/stability modules instead of suppressing).Not verified / remaining risks
terminal.sendconnection.terminal.updateViewportand a few other low-stakes paths still use the unguarded resolver; a stale handle there resizes the adopted pane until the next snapshot re-derives the handle. Left out to keep this change scoped to the input/output hot paths.Made with Orca 🐋