Skip to content

fix(ssh): a host whose ssh_config forwards a port can still open its server tunnel (STA-10471) - #28396

Merged
OrcaWin merged 1 commit into
mainfrom
nwparker/ssh-forward-config-forwards
Oct 13, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
nwparker/ssh-forward-config-forwards

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​68 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​67
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​47 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​41

ELI5

Some SSH hosts set up their own port forwards in ~/.ssh/config (a LocalForward line). When such a host is reached through a jump host or proxy, Orca opens a second ssh process for its server tunnel. That second process read the same config line, tried to open the same port a second time, failed, and quit — taking Orca's own tunnel down with it. Now the second process ignores that failure and only gives up when its own port fails.

What Changed

Before: a host whose ~/.ssh/config entry has LocalForward (or RemoteForward) and ProxyCommand/ProxyJump can't connect after the upgrade. The user sees "Could not connect to the remote Orca runtime" and no projects.

After: the host connects. The config's own forward stays owned by Orca's main connection, as before.

Mechanism:

  • The ssh -N -L tunnel process ran with ExitOnForwardFailure=yes. That made ssh exit when any forward failed, including the duplicate config forward the main connection already holds. It now runs with ExitOnForwardFailure=no.
  • To keep the old guarantee for our own forward, Orca watches the process's stderr for OpenSSH's cannot listen to port: <our port> and stops the process when it appears, during startup or later. The startup error now names that line instead of the last stderr line.
  • The browser-route ssh -N -D process gets the same flag change. Its startup already waits until its own listener answers.

Why

Alternatives considered:

  • ClearAllForwardings=yes: also clears the -L given on the command line. Checked with ssh -G: the command-line localforward disappears.
  • A filtered -F config: would have to re-create Include, Match, and every proxy setting, and would drift from what OpenSSH resolves.
  • ssh -O forward through a ControlMaster: Windows OpenSSH has no multiplexing, and config-backed hosts often run without Orca's master.

Turning off exit-on-any-failure and checking our own port is the only option that works on every platform and for every config.

Linked Issue

STA-10471

Visual Proof

N/A — no UI change; the change is in which ssh process stays up.

Testing

  • Real host (Linux, OpenSSH 10.5 behind a ProxyJump, client OpenSSH 10.3 on macOS). The config entry has LocalForward 127.0.0.1:47101, and a main ssh -N connection holds it:
    • Old flags: the tunnel exits with cannot listen to port: 47101 / Could not request local forwarding.
    • This branch's startSystemSshPortForwardProcess: startup ok, our port 47110 listens, and the process is still alive after 5 s.
    • When our own port is busy, OpenSSH prints cannot listen to port: <ours>. That is the line the new watcher matches.
  • Unit tests:
    • Flag change for -L and -D.
    • Own-port failure rejects startup and stops ssh, including a line split across stderr chunks.
    • A config forward's failure does not.
    • Own-port failure after startup still stops ssh.
  • pnpm tc:node, oxlint, pnpm run check:code-quality:changed, pnpm lint

Review

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

  • Cross-platform: the OpenSSH message is in the portable channels.c, so the same text comes from Windows OpenSSH.
  • Through a user's own ControlMaster, the config forward is already registered on the master, so this path was not affected.
  • SSH-only change; no wire or persistence impact.

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)

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Dynamic and system SSH forwarding now use ExitOnForwardFailure=no. System SSH forwards monitor stderr for failures to bind their own local port and send SIGTERM when such a failure occurs. Error details can select the matching local-port failure line. Tests cover startup failures, unrelated SSH-config forwarding failures, and failures reported after startup.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to d2293

A narrow port race can make a browser route appear connected when its tunnel does not work. Validate the SOCKS listener before treating startup as successful.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description is complete and directly explains the problem, user-visible behavior, implementation, alternatives, testing, cross-platform impact, and checklist status. It identifies STA-10471, altho…
Title check Passed The title clearly identifies the SSH configuration forwarding issue and the fix. It is specific, concise, and related to the main change.
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.
  • Fix all pre-merge checks with AI
✨ 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.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0cd43f41-9846-4488-a845-20e12a56ef85
📥 Commits

Reviewing files that changed from the base of the PR and between c5d7628 and d22938b.

📒 Files selected for processing: 5
  • src/main/ssh/system-ssh-dynamic-forward-process.test.ts
  • src/main/ssh/system-ssh-dynamic-forward-process.ts
  • src/main/ssh/system-ssh-forward-process.test.ts
  • src/main/ssh/system-ssh-forward-process.ts
  • src/main/ssh/system-ssh-port-forward-provider.ts

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

Comment on lines +38 to +40
// Why `no`: an ssh_config forward the main connection already holds would end this one; the
// listener probe below is what proves our own -D bound.
const dynamicArgs = ['-N', '-o', 'ExitOnForwardFailure=no', '-D', `127.0.0.1:${localPort}`]

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,240p' src/main/ssh/system-ssh-dynamic-forward-process.ts
sed -n '1,220p' src/main/ssh/system-ssh-dynamic-forward-process.test.ts

Repository: stablyai/orca

Length of output: 10009


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- callers and related symbols ---'
rg -n -F --glob '!node_modules' --glob '!dist' -e 'startSystemSshDynamicForwardProcess' -e 'localPort' -e 'dynamicForward' -e 'SOCKS' -e 'socks' src/main src/shared tests 2>/dev/null || true

printf '%s\n' '--- relevant file list ---'
rg --files src/main/ssh src/main | rg '(dynamic|forward|browser|proxy|tunnel|ssh).*\.(ts|tsx)$' | head -120

printf '%s\n' '--- base-to-head diff for the target area ---'
git diff --unified=80 c5d7628686c19d23d50296595061af0962fa3c3d d22938b54fd0f3644765b8759301b5f69ce735f2 -- src/main/ssh/system-ssh-dynamic-forward-process.ts src/main/ssh/system-ssh-dynamic-forward-process.test.ts

printf '%s\n' '--- direct caller source context ---'
rg -l -F --glob '*.ts' --glob '*.tsx' 'startSystemSshDynamicForwardProcess' src | while read -r f; do
  echo "FILE: $f"
  sed -n '1,280p' "$f"
done

Repository: stablyai/orca

Length of output: 41872


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- SOCKS client and exact route block ---'
nl -ba src/main/browser/system-ssh-socks-client-socket.ts
nl -ba src/main/browser/ssh-browser-network-execution-route.ts | sed -n '185,245p'

printf '%s\n' '--- SSH argument builder and forward process contract ---'
nl -ba src/main/ssh/ssh-system-fallback.ts | sed -n '1,260p'
nl -ba src/main/ssh/system-ssh-forward-process.ts | sed -n '1,240p'

printf '%s\n' '--- all focused tests and references ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'ExitOnForwardFailure' -e 'system SSH dynamic forward' -e 'SystemSshSocksClientSocket' -e 'startDynamicForward' -e 'startSystemSshDynamicForwardProcess' src tests || true

Repository: stablyai/orca

Length of output: 22700


🌐 Web query:

OpenSSH ssh_config ExitOnForwardFailure=no dynamic forwarding behavior when local SOCKS bind fails official manual

💡 Result:

With `ExitOnForwardFailure=no`—the default—`ssh` **does not terminate the connection** if it can’t set up a requested dynamic forward, such as when the local SOCKS listening port cannot be bound. The manual says this option controls whether failure to set up dynamic, local, remote, or tunnel forwards terminates `ssh`; `no` disables that behavior. ([github.com](https://github.com/openssh/openssh-portable/blob/master/ssh_config.5?utm_source=openai))

That means the SSH connection may remain up **without the SOCKS listener being available**. This setting does not govern later failures to connect to a destination through an established forward. ([github.com](https://github.com/openssh/openssh-portable/blob/master/ssh_config.5?utm_source=openai))

Citations:

- 1: https://github.com/openssh/openssh-portable/blob/master/ssh_config.5?utm_source=openai
- 2: https://github.com/openssh/openssh-portable/blob/master/ssh_config.5?utm_source=openai

Validate the SOCKS protocol during startup.

When another process claims the allocated port before SSH binds it, ExitOnForwardFailure=no allows SSH to remain running without its -D listener. waitForDynamicForward treats any successful TCP connection as success, so the browser route can return a tunnel backed by the unrelated listener. The first SystemSshSocksClientSocket then fails its SOCKS handshake instead of using SSH.

Suggested fix
       const closeProbe = (): void => {
         if (probeSocket === socket) {
           probeSocket = undefined
         }
         socket.removeAllListeners()
         socket.destroy()
       }
-      socket.once('connect', () => {
-        closeProbe()
-        finish(resolve)
-      })
-      socket.once('error', () => {
+      const retry = (): void => {
         closeProbe()
         if (!settled) {
           probeTimer = setTimeout(probe, PROBE_INTERVAL_MS)
         }
-      })
+      }
+      let response = Buffer.alloc(0)
+      socket.once('connect', () => socket.write(new Uint8Array([5, 1, 0])))
+      socket.on('data', (bytes: Buffer) => {
+        response = Buffer.concat([response, bytes])
+        if (response.byteLength < 2) {
+          return
+        }
+        if (response[0] !== 5 || response[1] !== 0) {
+          retry()
+          return
+        }
+        closeProbe()
+        finish(resolve)
+      })
+      socket.once('timeout', retry)
+      socket.once('error', retry)
+      socket.setTimeout(PROBE_INTERVAL_MS)
     }

@OrcaWin
OrcaWin merged commit 64dd8f5 into main Oct 13, 2026
53 checks passed
registered2nd pushed a commit to registered2nd/orca that referenced this pull request Oct 14, 2026
…server tunnel (STA-10471) (stablyai#28396)

Co-authored-by: m4air <[email protected]>
(cherry picked from commit 64dd8f5)
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.

1 participant