Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(coderd): reject redundant SSH autostarts of running workspaces - #29246

Draft
ezhang-figma wants to merge 1 commit into
coder:mainfrom
ezhang-figma:codex/ssh-autostart-guard
Draft

fix(coderd): reject redundant SSH autostarts of running workspaces#29246
ezhang-figma wants to merge 1 commit into
coder:mainfrom
ezhang-figma:codex/ssh-autostart-guard

Conversation

@ezhang-figma

Copy link
Copy Markdown

Written with AI

An SSH client can read a workspace as stopped, then submit its autostart request after another client has already finished starting that workspace. The server rejects starts while a provisioning job is active, but accepts this delayed request once the previous start has succeeded. That creates an unnecessary new build and invalidates agent connections belonging to the previous build. Managed devcontainers can consequently lose connectivity or authorization even though the underlying workspace machine is still running.

Reject SSH autostart requests with HTTP 409 when the latest build is already a successful start. The existing SSH client's conflict handler refreshes the workspace and connects without requesting another start, preserving the running build and its agents. Normal autostarts of stopped workspaces and explicit starts or rebuilds remain available. This server-side change protects clients that already send the SSH connection build reason; it does not require a client upgrade or a per-workspace repair script, and it does not repair agents invalidated by earlier builds.

The regression test reproduces the delayed request deterministically and verifies that the latest build stays unchanged, while stopped-workspace autostarts and explicit starts still succeed. The running-workspace case fails before the fix on v2.37.0. The new regression, workspace builder tests, and existing SSH conflict-recovery tests pass with the fix on both v2.37.0 and upstream base 5e058aa.

Verification evidence (commands executed by Codex)

An isolated PostgreSQL instance was used for the API and CLI tests. A local Go overlay redirected the test database port to avoid touching an existing development database; neither the overlay nor the harness is part of this change.

Before the fix, running the new regression test on v2.37.0 produced this failure (excerpt):

--- FAIL: TestWorkspaceBuildSSHAutostart
    --- FAIL: TestWorkspaceBuildSSHAutostart/Running
        Error: An error is expected but got nil.
        expected: *codersdk.Error
FAIL github.com/coder/coder/v2/coderd 6.941s

With the fix on v2.37.0:

$ go test -overlay=../postgres-test-overlay.json ./coderd ./coderd/wsbuilder -run '^(TestWorkspaceBuildSSHAutostart|TestBuilder_.*)$' -count=1
ok  github.com/coder/coder/v2/coderd     1.234s
ok  github.com/coder/coder/v2/coderd/wsbuilder 0.053s

With the fix on upstream base 5e058aa, the regression and builder tests passed:

ok  github.com/coder/coder/v2/coderd     6.631s
ok  github.com/coder/coder/v2/coderd/wsbuilder 0.068s

The existing SSH autostart and conflict-recovery tests also passed on that base:

$ go test -overlay=../postgres-test-main-overlay.json ./cli -run '^TestSSH/(StartStoppedWorkspace|StartStoppedWorkspaceConflict)$' -count=1
ok  github.com/coder/coder/v2/cli 9.966s

The regression verifies HTTP 409 and an unchanged latest-build ID for a redundant SSH autostart, and successful builds for a stopped-workspace autostart and an explicit dashboard start. gofmt and git diff --check passed. Full repository lint and tests have not been run locally; CI results are separate from the targeted checks above.

@github-actions github-actions Bot added the community Pull Requests and issues created by the community. label Sep 11, 2026
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@ezhang-figma

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@ezhang-figma

Copy link
Copy Markdown
Author

recheck

cdrci2 added a commit to coder/cla that referenced this pull request Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Pull Requests and issues created by the community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant