Skip to content

feat: add SSH auto-reconnect#2998

Open
ashvinnihalani wants to merge 1 commit into
pingdotgg:mainfrom
ashvinnihalani:codex/ssh-auto-reconnect
Open

feat: add SSH auto-reconnect#2998
ashvinnihalani wants to merge 1 commit into
pingdotgg:mainfrom
ashvinnihalani:codex/ssh-auto-reconnect

Conversation

@ashvinnihalani

@ashvinnihalani ashvinnihalani commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • Added a auto-reconnect feature that reconnects when SSH connections are disabled.
  • Also added some force re-inits after reconnecting otherwise the first message was stuck in working stat until manual refresh of the UI

Why

  • Flaky SSH connections are common, and automatically reconnecting is the write choice for transient disconnections. Otherwise users may not get up to date status of long running tasks as the connection remain disconnected

UI Changes

  • TODO: Add new settings pain

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk
Changes reconnect loops, WebSocket lifecycle, and thread subscription behavior for saved SSH environments; mis-timed reconnects could cause duplicate connections or stale UI until subscriptions refresh.

Overview
Adds SSH auto-reconnect for saved desktop SSH environments, controlled by a new client setting autoReconnectSshConnections (default off) with a toggle on the Connections settings page when the desktop bridge is available.

When the setting is on, an unexpected WebSocket close on an SSH saved environment schedules reconnectSavedEnvironment every 5 seconds until the link recovers or the user disconnects/removes the environment. Manual reconnects dedupe in-flight work, cancel pending auto-reconnect timers, and mark runtime state connected on success. reconnectSavedEnvironment also reattaches retained thread-detail subscriptions after reconnect.

refreshRetainedThreadDetailSubscription is exported and invoked from ChatView after a successful thread.turn.start so live thread updates stay wired without a manual UI refresh.

Saved-environment WebSocket transports can opt out of global connection status and RPC latency telemetry so remote SSH drops do not skew primary-connection metrics. onClose lifecycle handlers now receive an intentional flag to distinguish user-initiated closes from transport loss.

Reviewed by Cursor Bugbot for commit bebe477. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add SSH auto-reconnect for saved environments with a 5-second retry interval

  • Adds an autoReconnectSshConnections client setting (default false) and exposes it as an 'Auto-reconnect' toggle in the Connections settings page for desktop users.
  • On unexpected WebSocket close for SSH-backed saved environments, the runtime transitions to 'connecting' and schedules a reconnect attempt every 5 seconds, with epoch-based deduplication and cancellation on manual reconnect or disconnect.
  • Reconnect attempts reattach retained thread detail subscriptions on success and fall back to issuing a new bearer session if the initial reconnect fails.
  • Saved environment transports no longer update global WebSocket connection UI state or request latency tracking, controlled via new per-transport telemetry options in WsTransport.
  • Risk: SSH environments will silently retry in the background when autoReconnectSshConnections is enabled; users may not notice a connection failure until retries are exhausted.

Macroscope summarized bebe477.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c966f196-4b2e-4746-9928-2459d8c29a94

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jun 8, 2026
Comment thread apps/web/src/environments/runtime/service.ts Outdated
Comment thread apps/web/src/components/ChatView.tsx
@macroscopeapp

macroscopeapp Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces a new SSH auto-reconnect feature with significant new runtime behavior including timer-based retry logic, connection state management, and UI controls. New features of this scope warrant human review, and there is an unresolved comment identifying a potential race condition between disconnect and auto-reconnect.

You can customize Macroscope's approvability policy. Learn more.

@ashvinnihalani ashvinnihalani force-pushed the codex/ssh-auto-reconnect branch from dd1a0ad to ba63f99 Compare June 8, 2026 05:48
Comment thread apps/web/src/environments/runtime/service.ts
Comment thread apps/web/src/environments/runtime/service.ts
@ashvinnihalani ashvinnihalani force-pushed the codex/ssh-auto-reconnect branch from ba63f99 to 0030c10 Compare June 8, 2026 06:05
@ashvinnihalani ashvinnihalani force-pushed the codex/ssh-auto-reconnect branch from 0030c10 to bebe477 Compare June 8, 2026 06:09

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bebe477. Configure here.

}
await connection.reconnect();
reattachThreadDetailSubscriptionsForEnvironment(environmentId);
setRuntimeConnected(environmentId);

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.

Disconnect does not abort reconnect

Medium Severity

disconnectSavedEnvironment clears SSH auto-reconnect timers and removes the active connection, but it does not cancel an in-flight reconnectSavedEnvironment promise stored in pendingSavedEnvironmentReconnects. A scheduled auto-reconnect can still finish afterward, call connection.reconnect() or ensureSavedEnvironmentConnection, and mark the SSH environment connected again after the user disconnected.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit bebe477. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant