Skip to content

perf(ssh): opt-in proxy connection reuse for system SSH on Windows - #33030

Merged
nwparker merged 8 commits into
mainfrom
nwparker/windows-ssh-proxy-reuse
Oct 24, 2026
Merged

nwparker merged 8 commits into
mainfrom
nwparker/windows-ssh-proxy-reuse

Conversation

@nwparker

@nwparker nwparker commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

On Windows, Orca connects to SSH hosts behind a proxy (AWS SSM, GCP IAP, a bastion jump host) by starting a new ssh for every remote command. Each one pays the proxy's slow setup again. On macOS and Linux, OpenSSH shares one connection, but Windows OpenSSH can't. This PR adds an opt-in setting: Orca keeps one tunnel open through the proxy and sends later commands through it, so the slow proxy setup happens once instead of about 55 times per connect.

What Changed

Before: a Windows connect to a proxied host ran every setup command through the proxy. We measured 55 proxy handshakes during connect and 59 after 30 s idle; macOS needs 2. With a proxy that takes 3 s to connect, a connect took 203 s. The reporter saw about 10 minutes on a real 9 s proxy.

After, with the new setting on: Orca holds one ssh -N -L 127.0.0.1:<port>:localhost:<sshd port> through the real proxy. Later commands dial 127.0.0.1, with HostName, Port, ProxyCommand=none, ProxyJump=none and HostKeyAlias overrides, so the user's User, identities and known_hosts trust still apply. With the same 3 s proxy, connect dropped to 33 s and proxy handshakes from 59 to 4.

The mechanism:

  • Setting: a new optional per-target field, systemSshProxyConnectionReuse. It defaults to off and only applies on Windows. It's offered in the SSH host's Advanced settings only for hosts this desktop dials itself; a paired server's add-host dialog never shows or sends it.
  • Safety net: before using the route, Orca checks it and falls back to the direct route on any doubt.
    • It runs ssh -G with and without the route options and refuses on any difference outside the rewritten keys. This catches, for example, a Match host block that would switch User.
    • It refuses values containing % tokens or ${VAR}, which ssh -G can leave unexpanded.
    • It takes the sshd port and HostKeyAlias from the direct ssh -G.
    • It refuses if any security-key identity file exists, or ssh-add -L lists an sk- key, for the target and for every ProxyJump hop.
    • A BatchMode=yes login probe must succeed over the route.
  • Background logins: the held forward is non-interactive, sends keepalives (ServerAliveInterval=15), and is stopped through process-host's tree kill.
  • Recovery: commands fall back to the proxy as soon as the forward exits.
  • What doesn't change: user port forwards and orcad tunnels never use the route, so their command lines stay stable for crash recovery. Upload sessions re-read the route before each file.
  • Out of scope: macOS, Linux, WSL and folder workspaces are unaffected. No wire or protocol change; the only new field is optional.

Why

This builds on @bing-xbx's design and implementation from #31731. Their work is kept as the first commit, under their authorship. The issue is the Windows gap left by OpenSSH ControlMaster reuse.

Alternatives considered:

  • Remove the win32 gate on ControlMaster: Windows OpenSSH fails with getsockname failed: Not a socket.
  • Reduce the number of commands per connect: this is the real root cause, about 55 separate commands. It's a much larger change and is tracked as a follow-up.
  • Turn the route on automatically: five review rounds kept finding new ways ssh_config can depend on the real host name (Match host, %h, ${VAR}, jump-host identities). So it's opt-in, with the automatic checks kept as a safety net.

Credit to @bing-xbx for the report, design, Windows measurements and original implementation.

Linked Issue

Fixes #31558
Fixes #32582

Visual Proof

The new "Reuse one proxy connection" switch in an SSH host's Advanced settings, shown on Windows only. Captured from a hidden e2e window with a Windows user agent.

Light Dark
setting-light.png setting-dark.png

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Measured: a full hidden-app connect against a Docker sshd through a ProxyCommand that counts its own launches, with multiplexing off to match Windows.

  • Main: 55 handshakes during connect (59 after 30 s idle). macOS with multiplexing: 2.
  • With a 3 s simulated proxy: main took 203 s and 59 handshakes; the branch took 33 s and 4.
  • These numbers predate the opt-in switch and were taken with the route forced on.

Windows (OpenSSH_for_Windows 9.5p2): the exact ssh commands the branch builds work. The forward, probe and routed commands run. Existing known_hosts trust carries over through HostKeyAlias, and a wrong alias is rejected under strict checking. Tree kill also stops the ProxyJump child and frees the port. A Match host User drift reproduces with Windows ssh -G, which the admission check catches. Not done on Windows: a speed measurement on a slow proxy, and a full Orca app run.

Automated: unit tests cover:

  • the route lifecycle (reconnect races, cancellation, forward exit, disconnect);
  • argument building;
  • the opt-in gate;
  • non-interactive forwards and keepalives;
  • forwards never being routed;
  • upload sessions re-reading the route;
  • admission against real ssh -G with temporary configs (Match host User drift, %h and ${VAR} refusal, jump-host security key, manual-host Host block remap);
  • persistence keeping only an explicit opt-in.

Checks run:

  • The full static job passes locally.
  • All 95 test files that import a changed module pass.
  • A Docker managed-orcad subset passed: 4 specs, 11 tests.

Review

Independent reviews (Codex and Opus) ran over several rounds, and their findings are fixed. The final Opus review is clean. The final Codex round raised two issues that are listed under known limits below. Both apply only when the opt-in is on.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Known limits, all only when the opt-in is on:

  • Jump-host prompts: a ProxyJump hop that needs a password, OTP or passphrase can still prompt through a user-configured SSH_ASKPASS. OpenSSH's jump subprocess doesn't inherit BatchMode.
  • Host certificates on non-22 ports: the [host]:port HostKeyAlias fails principal validation, so the probe fails and the route stays off. This is safe.
  • ProxyCommand hops that run ssh -W: they aren't inspected.
  • Agent-only identities: a security key held only in an agent that ssh-add can't reach under a non-default IdentityAgent fails closed. A default agent that can't be reached counts as no agent.
  • Loopback port: the 127.0.0.1 port is reachable by other local users. It only reaches the target's own sshd login. Hosts with StrictHostKeyChecking no lose MITM protection on that hop.
  • Remote audit: sshd sees routed logins from 127.0.0.1, and bastion audit logs show one session instead of one per command.
  • No restart: if the forward exits, the route isn't restarted until the next reconnect.

Follow-up: about 55 separate ssh commands per connect on Windows without multiplexing. That's the root cause, and it's worth reducing directly.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

bing-xbx and others added 8 commits October 23, 2026 19:33
Windows OpenSSH cannot multiplex (ControlMaster fails with "getsockname
failed: Not a socket"), so every system-SSH exec for a ProxyCommand or
ProxyJump target re-ran the proxy handshake. Hold one `ssh -N -L` through
the real proxy per session and dial later execs over 127.0.0.1 with
HostName/Port/ProxyCommand=none/ProxyJump=none/HostKeyAlias overrides.

The route starts after connect, is proven with a login before use, falls
back to per-command proxying on any failure, honors
systemSshConnectionReuse: false, and is torn down with its proxy child.

Rebased from #31731 (commits b1cdd46, 3835c2d, 6268f2f) onto current main,
including the pending-route cancellation fix from b301b6a.

Co-authored-by: Neil <[email protected]>
…kill

Reuse signalProcessTree instead of a hand-rolled taskkill-then-kill
fallback: it already joins an in-flight tree kill, refuses a reaped PID,
and falls back to killing the root, so the route keeps no parallel copy
of that logic.
- Manual targets: take the forward's sshd port and the HostKeyAlias from
  the stored endpoint; `ssh -G` ran on the label and named another host.
- Hold the forward with ServerAlive probes so a silently dead proxy ends
  it and commands fall back instead of stalling on 127.0.0.1.
- Never route forwards: their argv must stay stable for orphan recovery,
  and the route's own forward must take the real proxy.
- Upload sessions read the route per file, so an exited route's port is
  not dialled after it closes.
- Skip the route for security-key identities, whose forward and probe
  logins would each ask for an unprompted touch.
…aims

The unclaimed-alias endpoint rewrite only applies to config-backed targets,
so manual targets with a configHost no block names stay eligible.
The forward is an optional background login; with BatchMode=no a password or
passphrase login raised an extra prompt right after connect, which the
non-interactive probe then discarded anyway.
…he route

Overriding HostName to 127.0.0.1 changes which ssh_config blocks match, so a
`Match host <real host>` block could silently switch the remote User (or
identities, certificates, known-hosts files) for every routed command. Run
`ssh -G` with and without the route options and refuse the route on any
difference outside HostName/Port/HostKeyAlias/ProxyCommand/ProxyJump.

Also ask the agent with `ssh-add -L` and refuse the route when it may hold a
security key, so the background forward and probe never request a touch.
Both checks run through process-host and fail closed.
…etting

The loopback route rewrites HostName, which ssh_config can key settings on,
so it no longer turns on by itself: a new optional systemSshProxyConnectionReuse
field (default off, Windows only) enables it from the SSH host's Advanced
settings. Old clients and servers ignore or omit the field.

Admission stays as the safety net and now:
- takes the forward's sshd port and HostKeyAlias from the direct `ssh -G`,
  so a manual host's own Host block cannot send the route to another sshd;
- refuses any non-routing value with a `%` token, which `ssh -G` can leave
  unexpanded while a routed login expands `%h` to 127.0.0.1;
- checks the security-key and agent identities of every ProxyJump hop;
- asserts the routed config really dials 127.0.0.1 with no proxy left.
… ${VAR} paths

- The switch now appears only for this desktop's own SSH hosts. A paired
  server's add-host dialog never shows or sends it, so an older server's
  strict schema is never handed the new field, and a client's platform no
  longer decides a server's setting.
- Admission also refuses `${VAR}` references, which `ssh -G` prints
  unexpanded while a login expands them.
- Advanced no longer auto-opens just for the opt-in.
@coderabbitai

coderabbitai Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e07e021b-7c15-413e-b683-07ec6cd0560d
Commits

Reviewing files that changed from the base of the PR and between 77efa5a and 75d7ac0.

Files selected for processing: 27
  • config/process-host-direct-import-baseline.txt
  • src/main/persistence-ssh-targets-and-pane-keys.test.ts
  • src/main/persistence/leasing-ssh-ptys/ssh-normalization.ts
  • src/main/runtime/rpc/methods/ssh.ts
  • src/main/ssh/connection/ssh-connection-file-transfers.ts
  • src/main/ssh/connection/ssh-connection-loopback-cancel.test.ts
  • src/main/ssh/connection/ssh-connection-loopback-route.test.ts
  • src/main/ssh/connection/ssh-connection.ts
  • src/main/ssh/runtime-ssh-target-fingerprint.ts
  • src/main/ssh/system-transport/system-ssh-args.ts
  • src/main/ssh/system-transport/system-ssh-forward-process.test.ts
  • src/main/ssh/system-transport/system-ssh-forward-process.ts
  • src/main/ssh/system-transport/system-ssh-loopback-route-admission.test.ts
  • src/main/ssh/system-transport/system-ssh-loopback-route-admission.ts
  • src/main/ssh/system-transport/system-ssh-loopback-route.test.ts
  • src/main/ssh/system-transport/system-ssh-loopback-route.ts
  • src/renderer/src/components/settings/SshHostAdvancedFields.tsx
  • src/renderer/src/components/settings/SshTargetForm.tsx
  • src/renderer/src/components/settings/ssh-target-draft.ts
  • src/renderer/src/components/settings/ssh-target-save-payload.ts
  • src/renderer/src/components/sidebar/AddRemoteHostFields.tsx
  • src/renderer/src/components/sidebar/AddRemoteHostSshFormPanel.tsx
  • src/renderer/src/components/sidebar/add-remote-host-ssh-actions.ts
  • src/renderer/src/i18n/locales/en.json
  • src/shared/rpc-contract/ssh-params.ts
  • src/shared/ssh-target-management.ts
  • src/shared/ssh-types.ts
Files with no reviewable changes: 1
  • config/process-host-direct-import-baseline.txt

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

Adds an opt-in setting for reusing a proxy connection with system SSH on Windows. Eligible connections use a local loopback forward, subject to SSH configuration and security-key admission checks. The connection manages route startup, cancellation, disposal, and route arguments for later commands and uploads. The change also carries the setting through the form, RPC, normalization, and persistence layers.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 75d7a

The opt-in setting clears when disabled, and eligible Windows ProxyCommand connections can use the route while retaining the direct-route fallback. No identified issue needs resolution before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 52 functions across 25 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: opt-in proxy connection reuse for system SSH on Windows.
Description check Passed The description follows the required template. It explains the user impact, implementation, rationale, linked issues, visual proof, testing, known limits, and checklist status.
Linked Issues check Passed The PR meets the coding requirements in [#31558] and [#32582]. system-ssh-loopback-route.ts gates reuse to Windows, explicit opt-in, proxied targets, and the existing systemSshConnectionReuse opt-…
Out of Scope Changes check Passed The changes stay within [#31558] and [#32582]. The process-host migration supports required Windows process-tree teardown. The argument, lifecycle, admission, persistence, RPC, UI, localization, uploa…
Full details: Linked Issues check

Explanation

The PR meets the coding requirements in [#31558] and [#32582]. system-ssh-loopback-route.ts gates reuse to Windows, explicit opt-in, proxied targets, and the existing systemSshConnectionReuse opt-out. It admits the route, starts a non-interactive keepalive forward, probes login, and disposes the forward on failure or cancellation. ssh-connection.ts manages route startup, reconnect races, forward exit, and disconnect. SSH argument changes route later commands through loopback while preserving the direct host-key alias. The UI, RPC schema, normalization, persistence, and tests implement the per-target setting and its scope.

Full details: Out of Scope Changes check

Explanation

The changes stay within [#31558] and [#32582]. The process-host migration supports required Windows process-tree teardown. The argument, lifecycle, admission, persistence, RPC, UI, localization, upload, and regression-test changes support proxy route reuse or its stated safety and scope. The PR does not add unrelated platform behavior; the setting remains limited to Windows desktop-dialled SSH hosts.

Full details: Docstring Coverage

Explanation

Docstring coverage is 40.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 52 functions across 25 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@nwparker
nwparker merged commit cd2eeeb into main Oct 24, 2026
65 checks passed
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.

[Bug] perf(ssh): reuse one proxy connection for system SSH on Windows [Feature]: Connection reuse for ProxyCommand/ProxyJump SSH targets on Windows

2 participants