Skip to content

fix(remote-runtime): recover terminals after network loss - #9774

Merged
OrcaWin merged 10 commits into
mainfrom
OrcaWin/remote-runtime-network-recovery
Jul 21, 2026
Merged

OrcaWin merged 10 commits into
mainfrom
OrcaWin/remote-runtime-network-recovery

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Detect half-open remote-runtime sockets after sleep, timer suspension, roaming, or network partitions and fence stale callbacks by connection generation.
  • Reattach existing terminal panes to the same live PTY using authoritative snapshot/replay ordering; cached terminal pixels no longer count as a healthy attachment.
  • Retry recoverable PTY attachment for up to one minute, then stop automatically and show a neutral per-pane disconnected state with an explicit Reconnect action.
  • Keep recoverable connectivity failures out of the red terminal error toast while preserving fatal, authentication, and terminal-ended errors.
  • Make terminal.create retries capability-gated and idempotent so an unknown response outcome adopts the original server PTY instead of creating a duplicate.
  • Scope recovery by runtime environment and release timers, subscriptions, listeners, and pending state on health, cutoff, detach, or disposal.

Screenshots

Not attached. The disconnected state requires a controlled remote-runtime partition; renderer component tests cover the exact retrying and manual-reconnect UI states. A live patched Mac-to-Windows partition recording remains a follow-up validation gap.

Testing

  • pnpm lint — changed-file oxlint and React Doctor pass; the full command is blocked by unrelated pre-existing switch-exhaustiveness and localization-coverage findings.
  • pnpm typecheck
  • pnpm test — focused and broader registered reliability suites were run instead of the entire repository suite.
  • pnpm build — pnpm exec electron-vite build --mode e2e passed; the full multi-target build was not run.
  • Added or updated high-quality tests that would catch regressions.

Validation performed:

  • 11 deterministic fault-injection files / 127 tests, three consecutive cycles after the final lifecycle fix.
  • 2 focused transport/state files / 76 tests after the final commit formatting pass.
  • 10 broader provider/renderer files / 589 tests.
  • Node, CLI, and web typechecks.
  • Electron E2E build.
  • Reliability-gate manifest, localization catalog parity, max-lines ratchet, changed-file oxlint, React Doctor, and git diff --check.
  • Current Windows remote runtime reachability plus isolated PTY round-trip; unrelated live terminals were not mutated.

AI Review Report

Six adversarial review rounds across the initial and final review passes checked connection epochs, stale socket/RPC callbacks, subscription replay, PTY identity and reattachment ordering, create idempotency, timer/listener cleanup, per-environment isolation, fatal versus recoverable UX, compatibility with older runtimes, and macOS/Linux/Windows plus SSH/WSL/relay implications.

The initial rounds fixed disposed-pane recovery UI state and completed the reliability contract. The final review reproduced two major create-lifecycle bugs: cutoff surfaced a fatal error with no manual path, and a delayed create completion could replace a newer cross-runtime attachment. Both are now epoch-fenced and regression-tested. The next round found that a slow capability probe could leave a create RPC alive past cutoff; timeouts are now recomputed from the remaining budget and exact-cutoff callbacks cannot re-arm recovery. The final round was clean.

Cross-platform review confirmed there are no platform-specific shortcuts, path separators, or shell assumptions in the new lifecycle/UI code. Server and client heartbeat behavior is transport-generic, and older runtimes degrade safely because terminal-create replay is enabled only when the server advertises terminal.create-idempotency.v2.

Security Audit

  • Reconnection remains bound to the existing authenticated pairing and runtime identity; an address change alone cannot authorize a different runtime.
  • Stable terminal-create identity is derived from authenticated client identity, canonical worktree identity, and a client mutation UUID.
  • Unknown provider inventory and worktree/handle ownership conflicts fail closed rather than adopting or spawning ambiguously.
  • No secrets, raw terminal output, new dependencies, command interpolation, or filesystem path handling were added.
  • RPC fields are schema-bounded, in-flight create coordination is capped, and stale generations cannot close or overwrite a newer connection.

Notes

  • Automatic PTY recovery is intentionally bounded to 60 seconds. After that, the pane remains mounted with its cached content visibly marked disconnected until the user chooses Reconnect.
  • Manual reconnect preserves the authoritative PTY identity; it does not create a replacement terminal.
  • A full live patched Mac client to Windows runtime partition/recovery journey remains uncollected. Deterministic fault injection covers the sequencing and request/subscription invariants in this PR.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The pull request adds remote PTY recovery state tracking, epoch-fenced reconnect behavior, recovery-aware IO gating, and reconnect UI banners. Terminal creation gains deterministic handles, concurrent request deduplication, inventory reconciliation, worktree identity validation, and capability-gated retries. Shared runtime connections add recoverable error classification, generation-safe socket handling, reconnect scheduling, and probe-based liveness monitoring. Provider process listings now expose worktree identities, and reliability-gate evidence is expanded with recovery and idempotency coverage.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title matches the main change: remote-runtime terminal recovery after network loss.
Description check ✅ Passed All required sections are present, including summary, screenshots, testing, AI review, security audit, and notes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/runtime/rpc/methods/terminal.ts (1)

1362-1362: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the idempotency identity precedence.

pairedDeviceId ?? clientId ?? 'local' defines the mutation isolation boundary. Add a brief rationale so future cleanup does not change retry scoping.

Suggested clarification
+        // Keep retries scoped to the authenticated paired device when available.
         pairedDeviceId ?? clientId ?? 'local',

As per coding guidelines, “For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a7d703af-81ef-4cdd-bb69-1e65d4dc2df8

📥 Commits

Reviewing files that changed from the base of the PR and between 87af1c8 and e0d54b2.

📒 Files selected for processing (43)
  • config/reliability-gates.jsonc
  • src/main/daemon/daemon-pty-adapter.test.ts
  • src/main/daemon/daemon-pty-adapter.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/runtime/orca-runtime-terminal-create-idempotency.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/remote-runtime-terminal-create-idempotency.ts
  • src/main/runtime/remote-runtime-terminal-create-identity.ts
  • src/main/runtime/rpc/methods/terminal-create-idempotency.test.ts
  • src/main/runtime/rpc/methods/terminal.ts
  • src/main/runtime/rpc/remote-runtime-server-heartbeat.test.ts
  • src/main/runtime/rpc/remote-runtime-server-heartbeat.ts
  • src/main/runtime/rpc/ws-transport.ts
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
  • src/renderer/src/components/terminal-pane/TerminalRemoteRuntimeReconnectBanner.test.tsx
  • src/renderer/src/components/terminal-pane/TerminalRemoteRuntimeReconnectBanner.tsx
  • src/renderer/src/components/terminal-pane/pty-connection-types.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-recovery-state.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-recovery-state.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/components/terminal-pane/terminal-remote-runtime-recovery-ui-state.test.ts
  • src/renderer/src/components/terminal-pane/terminal-remote-runtime-recovery-ui-state.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/runtime/remote-runtime-terminal-multiplexer.ts
  • src/shared/protocol-version.ts
  • src/shared/remote-runtime-client-error-classification.test.ts
  • src/shared/remote-runtime-client-error-classification.ts
  • src/shared/remote-runtime-shared-control-connection.test.ts
  • src/shared/remote-runtime-shared-control-connection.ts
  • src/shared/remote-runtime-shared-control-reconnect.ts
  • src/shared/remote-runtime-shared-control-socket-generation.test.ts
  • src/shared/remote-runtime-shared-control-socket-generation.ts
  • src/shared/remote-runtime-socket-liveness.test.ts
  • src/shared/remote-runtime-socket-liveness.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts (2)

1083-1085: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Fence terminal creation against lifecycle changes.

A terminal.create RPC already in flight survives disconnect()/detach()/attach(). If it resolves later, Lines 1106-1119 restore handle, emit onPtySpawn, and subscribe a pane that was closed or replaced. The new retry flow extends this race to 60 seconds. Track a lifecycle epoch through create/retry, invalidate it on attach/disconnect/detach, and close a stale returned terminal instead of applying it.


426-510: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Keep exhausted recoverable creation failures retryable.

After the deadline, this throws the last recoverable connection error. connect() then routes it to onError, producing the fatal-error path, while recovery state remains offline and retryRecovery() cannot run without a handle. Transition this case to the disconnected/reconnectable state and reserve onError for non-recoverable failures.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 897c6368-3b61-4782-831c-70c542325499

📥 Commits

Reviewing files that changed from the base of the PR and between 8d4700c and e9392e4.

📒 Files selected for processing (4)
  • config/reliability-gates.jsonc
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-recovery-state.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • config/reliability-gates.jsonc

@OrcaWin
OrcaWin merged commit 54c1ec5 into main Jul 21, 2026
9 checks passed
@OrcaWin
OrcaWin deleted the OrcaWin/remote-runtime-network-recovery branch July 21, 2026 22:18
bbingz added a commit to bbingz/orca that referenced this pull request Jul 23, 2026
…ose tombstones

Narrow stablyai#8254 onto current main after stablyai#9774: return ok-union start results
across IPC, reconstruct cloneable {code,message} in preload (contextBridge),
and tombstone early onClose so late handles are release-only.
bbingz added a commit to bbingz/orca that referenced this pull request Jul 26, 2026
…line

Narrow stablyai#8255 onto current main after stablyai#9774: fire pending shared-control
reconnect timers and pane recovery backoffs on system resume and browser
online, without replacing the per-pane recovery state machine or reconnect
banner UX.
OrcaWin added a commit that referenced this pull request Jul 27, 2026
* fix(remote): accelerate shared-control and pane recovery on resume/online

Narrow #8255 onto current main after #9774: fire pending shared-control
reconnect timers and pane recovery backoffs on system resume and browser
online, without replacing the per-pane recovery state machine or reconnect
banner UX.

* test(remote): cover online and occluded-resume recovery triggers

* fix(remote): centralize recovery acceleration

---------

Co-authored-by: OrcaWin <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…8255)

* fix(remote): accelerate shared-control and pane recovery on resume/online

Narrow stablyai#8255 onto current main after stablyai#9774: fire pending shared-control
reconnect timers and pane recovery backoffs on system resume and browser
online, without replacing the per-pane recovery state machine or reconnect
banner UX.

* test(remote): cover online and occluded-resume recovery triggers

* fix(remote): centralize recovery acceleration

---------

Co-authored-by: OrcaWin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants