Repository navigation
Open
Labels
Description
Summary
When adding a host via Desktop → Add SSH server, a failure to start the remote OpenCode service (here: the remote managed service port was already in use) is reported as error.connection — "Could not establish an SSH connection. Check your network and SSH settings." SSH itself connects fine, and the real remote error is captured but never surfaced.
Environment
- opencode version: Desktop 2.0.26 (auto-installed remote CLI 2.0.26); local
opencodeCLI 2.0.24 - OS: macOS 15 (Darwin 25.5.0, arm64); remote host Linux (Ubuntu 22.04, x86_64)
- Terminal: iTerm.app (
$TERM=xterm-256color) — issue is in the Desktop app, not the TUI - Shell:
/bin/zsh - Install/channel: OpenCode Desktop release 2.0.26 (
ai.opencode.desktop) - Active plugins: none found in local config
Reproduction
- On the remote Linux host, make the managed service bind all interfaces:
opencode service set hostname 0.0.0.0. - Make sure something holds the remote's default managed service port. Here an unrelated established outbound connection used port
49374as its source port (172.17.0.1:49374 → 172.17.0.3:6379, host Docker bridge → Redis container).49374is OpenCode's default managed port and lies inside the Linux ephemeral range (32768–60999). - In Desktop, open the command palette → Add SSH server (or server settings → + Add server → Add SSH server) and select the host from
~/.ssh/config. - Observe the generic error.
Expected Behavior
- The UI should distinguish "SSH connected, but the OpenCode server did not become ready" from "could not establish an SSH connection". An
error.servicestring already exists in the SSH i18n set and fits this case exactly. - Ideally the remote command's stderr (which already contains the actionable cause) should be shown, or the app should fall back to a free port automatically.
Actual Behavior
The dialog shows only error.connection:
Could not establish an SSH connection. Check your network and SSH settings.
SSH is in fact fine:
ssh -o BatchMode=yes <user>@<host>succeeds using key auth.- The app's own local forward works:
ssh ... -L 127.0.0.1:<local>:127.0.0.1:<remote-port> <host>establishes and the tunneled endpoint responds (HTTP 401 = reachable; auth is handled by the app).
The real cause is only visible in the remote log (~/.local/share/opencode/log/opencode.log):
level=ERROR message="cli process failed"
cause="... Managed service port 49374 on 0.0.0.0 is already in use by another process. Configure another port with `opencode service set port <port>` and start the service again. ..."
args="[\"service\",\"start\"]"
And the same when run manually:
$ <cli> service start
Error: Server process exited with code 1
Error: Managed service port 49374 on 0.0.0.0 is already in use by another process. Configure another port with `opencode service set port <port>` and start the service again.
exit=1
Additional Context
- The remote setup maps any non-zero exit of the remote
ssh ... <cli> service starttoerror.connection(the error payload carries the captured stderr), rather thanerror.serviceor a surfaced detail. There is no details/diagnostics affordance in the 2.0.26 bundle (copyDiagnostics/showDetailskeys are absent), so the captured stderr is effectively hidden from the user and the message points them at network/SSH instead. - Secondary robustness issue: the default managed service port
49374is inside the Linux ephemeral range (32768–60999), andserve --servicebinds a fixed port. A transient outbound connection can claim that port as a source port; binding0.0.0.0then fails withEADDRINUSE, while binding127.0.0.1succeeds (verified). Consider a default port outside the ephemeral range and/or falling back to a free port onEADDRINUSE. - Workaround that fixed it:
opencode service set port 27777 && opencode service restarton the remote host; the same Desktop flow then connects. - Frequency: reproduced consistently on the affected host while the port stayed occupied; a second host without the collision connected normally.
Activity
opencode-agent commentedon Oct 9, 2026
Thanks for the detailed report. I was able to reproduce this.
I couldn't run the Desktop GUI here, so I ran the Desktop SSH bootstrap code from source against a "remote" with CLI 2.0.26. A fake
sshthat always connects successfully stood in for the real one. I setopencode service set hostname 0.0.0.0and kept port 49374 on0.0.0.0busy. The bootstrap got through the checking step and into starting the service, then failed with codeconnection, which the dialog shows as "Could not establish an SSH connection…". The remote CLI's actual error ("Managed service port 49374 on 0.0.0.0 is already in use…") was captured but only kept as a hidden detail.The cause seems to be that any non-zero exit from the remote command is treated as an SSH connection failure, including a failed
service start. The SSH code is unchanged in the latestv2(eefe85d), and it still happens there. The script below reproduces it.The default port having no fallback when it's taken is tracked separately in #52234 and #50672. Until this is fixed, your workaround of setting another port with
opencode service set port <port>on the remote works.Reproduction script (repro.sh)
Run it:
bash repro.shargszero commentedon Oct 10, 2026
I'd like to work on this.
The diagnosis matches what I see in the source:
runSshturns every non-zero exit intoSshFailure("connection"), and the dialog renderserror.${code}, so a remoteservice startthat exits 1 is reported as a connection problem while the real remote stderr is captured but kept only in the hidden detail.I have a fix in progress that re-tags the failure of the start step alone as
SshFailure("service", <captured detail>), keeping genuine transport failures (OpenSSH's own exit 255, which fails an earlier step on the same connection) asconnection. It comes with a test that drives the realbootstrapagainst a stand-insshreading the remote script from stdin: the reported case yieldsconnectionbefore the change andserviceafter it.The default managed port colliding with the ephemeral range and falling back to a free port is out of scope here, since it is tracked separately in #52234 and #50672.
ai-nikolai commentedon Nov 12, 2026
@argszero - this is still broken.
When ssh connection (with password) stop (e.g. computer shutdown, etc.) then opencode cannot reconnect to the remote machine (throws a generic error message) and the port is still in use.
@cendh666 @Hona
ai-nikolai commentedon Nov 12, 2026
@Hona - created a PR with a fix:
#63542
ai-nikolai commentedon Nov 17, 2026
@Hona @Brendonovich - this issue is really persisting and quite annoying.
Basically, reconnecting to a remote server requires manually sshing into it and then killing the process manually and only then login works again.
The PR should fix this.