You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(ssh): disconnect no longer waits on a stopped server left as a zombie - #46053
Disconnecting an SSH environment on a host whose PID 1 never reaps exited processes fails with a stop error and a 2 second wait, even though the server did stop.
Steps (Linux, no sign-in):
Start a container whose PID 1 does not reap: docker run -d -p 2222:22 <debian image with openssh-server and a key for user dev> sh -c '/usr/sbin/sshd && exec sleep infinity'.
In T3 Code desktop on Linux, add an SSH environment for dev@localhost port 2222 and let it connect (the remote server starts).
Remove the environment (or turn it off).
Expected: the removal finishes at once. Actual: it waits about 2 extra seconds, then the desktop log has "Could not disconnect the managed SSH environment." with "Remote T3 server with PID N did not stop within 2 seconds. Its ownership files were kept." In the container, ps -o pid,stat,args -p N shows a Z<defunct> entry and ~/.t3/ssh-launch/<key>/pid still names it: the server exited, but nothing reaped it.
Cause
REMOTE_STOP_SCRIPT in packages/ssh/src/tunnel.ts:1097 stops the managed server, then waits for the exit with a bare kill -0 "$REMOTE_PID" (tunnel.ts:1115) and fails if kill -0 still passes after 2 seconds (tunnel.ts:1119). kill -0 accepts a zombie's PID, so on a host whose PID 1 never reaps orphans the loop always runs out and the script exits 1. The sibling REMOTE_MANAGED_SERVER_RUNNING_SCRIPT (tunnel.ts:598) already documents this in its comment at tunnel.ts:595, "kill -0 also passes for a zombie", and its managed_server_running helper checks the ps args so a zombie does not count. The stop script interpolates that helper and runs it before the kill (tunnel.ts:1112), but not after; the launch script's shutdown branches re-check with managed_server_running, not kill -0 (#19432, #26963).
Change
The stop script's wait loop and final check now use managed_server_running, the same rule the script already applies before the kill. Without ps it still falls back to kill -0, as before. Three lines change and one comment line is added, in one file.
Scope
Small fix of an obvious bug, steps reproduce it, so it needs no issue.
Verification
New case in packages/ssh/src/tunnel.test.ts, remote stop script > disconnecting stops a managed server whose exit is never reaped (skipped on Windows): a shell starts a node process with serve-like arguments in the background and then exec sleep 30, so nobody reaps it; the test records it as the managed server, runs the real stop script through disconnectEnvironment with sh -s under a temp HOME, and expects success and the pid file gone.
Test commit alone, fails on main faad516 (macOS /bin/sh):
FAIL src/tunnel.test.ts > remote stop script > disconnecting stops a managed server whose exit is never reaped
SshCommandError: Remote T3 server with PID 55849 did not stop within 2 seconds. Its ownership files were kept.
Tests 1 failed | 60 skipped (61)
Again with sh pointing at /bin/dash on the PATH: 1 failed | 60 skipped (61), the same error.
With the fix, 1 passed | 60 skipped (61) under both shells. Whole file with the fix: 3 failed | 51 passed | 7 skipped (61); the three failures ("names missing gzip after verifying with sha256sum", "names missing gzip after verifying with shasum", "concurrent launches on one remote home record the server that owns it") fail identically on pristine main on this Mac, 3 failed | 50 passed | 7 skipped (60): the gzip pair because macOS tar unpacks gzip by itself, the third a timing flake. They are unrelated to this change.
vp run check:changed: format, lint, knip 1/2 and 2/2, and typecheck (5 packages) pass; the test step (2 files) fails only on the two gzip host failures, stable across a re-run.
Not verified: I did not start a real Docker container with sshd && exec sleep infinity, connect T3 Code to it over OpenSSH and remove the environment; the test reproduces the unreaped exit locally by spawning the server under a sleep parent and running the real stop script through disconnectEnvironment.
Model: Claude Opus 5.5. Harness: Claude Code in T3 Code.
Macroscope's review found this PR approvable — SSH disconnect now recognizes an exited managed server instead of waiting on its zombie process. Existing server-ownership checks and shutdown safeguards remain unchanged.
You can add or adjust custom eligibility rules. Learn more.
Reviewing files that changed from the base of the PR and between 277f78a and a173e92.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The stop script now uses managed_server_running to check shutdown progress and determine whether to report a timeout. A POSIX-only test checks that disconnect removes the recorded PID file when the server’s exit is not reaped.
Changes: Managed server shutdown
Layer / File(s)
Summary
Shutdown detection and regression test packages/ssh/src/tunnel.ts, packages/ssh/src/tunnel.test.ts
The stop script uses managed_server_running during its shutdown wait and timeout check. The test checks PID-record removal after disconnect when the server’s exit is not reaped.
This fixes SSH environment disconnect hanging or timing out when a stopped remote server stays a zombie. The change is small and localized, and a regression test covers it. No merge-blocking risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the actual change: disconnect no longer waits on a stopped server left as a zombie. It matches the stop script change that uses managed_server_running instead of kill -0, and the regre…
Description check
The description follows the template well. It has Problem, Change, Scope, and Verification sections. The Problem section gives reproduction steps and expected versus actual behavior. The Change sectio…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the actual change: disconnect no longer waits on a stopped server left as a zombie. It matches the stop script change that uses managed_server_running instead of kill -0, and the regression test. It uses the conventional commit format and is specific. The title is 73 characters, within normal length.
Full details: Description check
Explanation
The description follows the template well. It has Problem, Change, Scope, and Verification sections. The Problem section gives reproduction steps and expected versus actual behavior. The Change section explains the fix and why it is limited to one file. The Scope section explains why no issue is linked. The Verification section gives focused test commands, observed results under two shells, the unrelated pre-existing failures, and what was not verified. It also names the model and harness, as the template requests. The author did not link an issue but gave a reason for omitting it, which the template allows for small obvious bug fixes.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Reviewing files that changed from the base of the PR and between faad516 and 277f78a.
Files selected for processing: 2
packages/ssh/src/tunnel.test.ts
packages/ssh/src/tunnel.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.
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
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.
Problem
Disconnecting an SSH environment on a host whose PID 1 never reaps exited processes fails with a stop error and a 2 second wait, even though the server did stop.
Steps (Linux, no sign-in):
docker run -d -p 2222:22 <debian image with openssh-server and a key for user dev> sh -c '/usr/sbin/sshd && exec sleep infinity'.dev@localhostport 2222 and let it connect (the remote server starts).ps -o pid,stat,args -p Nshows aZ<defunct>entry and~/.t3/ssh-launch/<key>/pidstill names it: the server exited, but nothing reaped it.Cause
REMOTE_STOP_SCRIPTin packages/ssh/src/tunnel.ts:1097 stops the managed server, then waits for the exit with a barekill -0 "$REMOTE_PID"(tunnel.ts:1115) and fails ifkill -0still passes after 2 seconds (tunnel.ts:1119).kill -0accepts a zombie's PID, so on a host whose PID 1 never reaps orphans the loop always runs out and the script exits 1. The siblingREMOTE_MANAGED_SERVER_RUNNING_SCRIPT(tunnel.ts:598) already documents this in its comment at tunnel.ts:595, "kill -0 also passes for a zombie", and itsmanaged_server_runninghelper checks thepsargs so a zombie does not count. The stop script interpolates that helper and runs it before the kill (tunnel.ts:1112), but not after; the launch script's shutdown branches re-check withmanaged_server_running, notkill -0(#19432, #26963).Change
The stop script's wait loop and final check now use
managed_server_running, the same rule the script already applies before the kill. Withoutpsit still falls back tokill -0, as before. Three lines change and one comment line is added, in one file.Scope
Small fix of an obvious bug, steps reproduce it, so it needs no issue.
Verification
New case in
packages/ssh/src/tunnel.test.ts,remote stop script > disconnecting stops a managed server whose exit is never reaped(skipped on Windows): a shell starts a node process with serve-like arguments in the background and thenexec sleep 30, so nobody reaps it; the test records it as the managed server, runs the real stop script throughdisconnectEnvironmentwithsh -sunder a temp HOME, and expects success and the pid file gone.Test commit alone, fails on main faad516 (macOS
/bin/sh):Again with
shpointing at/bin/dashon the PATH:1 failed | 60 skipped (61), the same error.With the fix,
1 passed | 60 skipped (61)under both shells. Whole file with the fix:3 failed | 51 passed | 7 skipped (61); the three failures ("names missing gzip after verifying with sha256sum", "names missing gzip after verifying with shasum", "concurrent launches on one remote home record the server that owns it") fail identically on pristine main on this Mac,3 failed | 50 passed | 7 skipped (60): the gzip pair because macOS tar unpacks gzip by itself, the third a timing flake. They are unrelated to this change.vp run check:changed: format, lint, knip 1/2 and 2/2, and typecheck (5 packages) pass; the test step (2 files) fails only on the two gzip host failures, stable across a re-run.Not verified: I did not start a real Docker container with
sshd && exec sleep infinity, connect T3 Code to it over OpenSSH and remove the environment; the test reproduces the unreaped exit locally by spawning the server under asleepparent and running the real stop script throughdisconnectEnvironment.Model: Claude Opus 5.5. Harness: Claude Code in T3 Code.