Repository navigation
fix(agent/agentssh): report ssh disconnect when the connection closes - #32353
Merged
Merged
Conversation
This was referenced Nov 17, 2026
Merged
EhabY
marked this pull request as ready for review
November 19, 2026 12:43
ethanndickson
approved these changes
Nov 20, 2026
ethanndickson
left a comment
Member
There was a problem hiding this comment.
👍 after the mutex is replaced with a sync.once
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Non-PTY SSH sessions (
ssh -T, used by VS Code Remote-SSH and other editors) keep their process running after the client leaves, matching OpenSSH (#18519). The disconnect was only reported when that process exited, so connection log rows stayed "Ongoing" while the editor's server or a foreground loop kept running.The session handler now also reports the disconnect (reason
client_closed) when the SSH connection closes, whichever comes first. The report still happens at most once and before the handler returns. Process lifetime is unchanged.Not covered here: a client that disappears without closing TCP (sleep,
kill -9) is only detected by the server keep-alive, which today only probes while a session is open and then closes just that session. coder/ssh#8 fixes both and will follow with a fork bump.Verification
TestSSHShutdownReason/ClientDisconnectWhileProcessRuns(exec sleep 120, client closes) fails onmainand passes with this change.A throwaway repro (non-PTY
bashsession, client closes, disconnect reported within 3s):while true; do sleep 1; donesleep 1000 &(holds stdout)sleep 1000 </dev/null &>/dev/null &Decision log
sync.Onceguards the report: a concurrentDoblocks until the first call finishes, so the handler never returns mid-report.session.Context()is per connection, so a session closed on a still-open multiplexed connection still reports on process exit, as before.CODER_AGENT_SSH_MAX_TIMEOUT(default 72h, so one probe per 24h). Shortening it is a separate change.Written with Coder Agents and reviewed by @EhabY.