Repository navigation
Description
Summary
The CLI agent host supervisor's kill_running_server path leaks the underlying server node process when restarting after a _vscodeUpgrade RPC. The bash launcher script (<server>/bin/code-server-<quality>) is terminated, but the node ... server-main.js child it spawn'd remains alive as an orphan.
Repro
Discovered while testing #319455 against a remote macOS host using a pinned-old-server CLI:
- Bring up an agent host supervisor on commit A (e.g.
7090241a056cb49cfe90f58da9a8cc44df9262a9, protocol 0.2.0). - Connect a desktop on commit B (newer protocol 0.3.0). Handshake fails with
UnsupportedProtocolVersion. - Click "Update Server". The supervisor receives the
_vscodeUpgradeRPC, callskill_running_server, then restarts on commit B. - Observe processes on the remote: the bash wrapper for commit A is gone, but its node child (e.g.
~/.<serverDataFolderName>/cli/servers/Insiders-7090241a.../server/node ... server-main.js) is still alive withppid=1.
In my test run the orphan was pid 230 and survived indefinitely; only the new commit-B server's child was tracked by the supervisor after the restart.
Suspected cause
cli/src/tunnels/agent_host.rs::kill_running_server (or the platform-specific kill helper it delegates to) appears to signal the immediate child only. The server launcher is:
<server>/bin/code-server-<quality> (bash)
└── node ... out/vs/server/node/server-main.js (the server)
Bash does not forward SIGTERM to its children by default, and we don't wait on it before terminating the new generation, so the node child is reparented to PID 1 and continues running. It does eventually exit when its IPC pipe closes, but in our test it persisted for the duration of the run.
Suggested fix
A couple of options, in rough order of preference:
- Signal the whole process group / job from the CLI side — i.e. set up the server child in its own process group at spawn time (
setsid/CREATE_NEW_PROCESS_GROUP) and sendSIGTERMto the negative pgid on shutdown. Robust regardless of what the launch script does. - Make the launcher forward signals, e.g.
trapSIGTERM/SIGINTincode-server-<quality>and re-signal$!beforewait. Cheaper change but doesn't help non-shell launchers. - Replace the bash launcher with a direct exec so the CLI's child is the node server. Simplest of all if there's no other reason to keep the shell shim.
Scope
- CLI only (
cli/src/tunnels/agent_host.rsand the server-bin shim at<server>/bin/code-server-<quality>). - Independent of agentHost: keep SSH connection registered after incompatible handshake #319455; that PR fixes the desktop-side reconnect after upgrade, and is unaffected by whether the old server's node child gets reaped cleanly.
- Probably also fires on any non-upgrade shutdown path that goes through
kill_running_server(e.g. supervisor exit / quality switch), so the fix is generally useful.
(Written by Copilot)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Kill full server process tree in agent host kill_running_server (#320631
jruales commentedon Jun 16, 2026
(verified by Julia Kasper (@jukasper))