Skip to content

Agent host CLI: kill_running_server leaks server node child process after upgrade #319516

Closed

Description

@roblourens

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:

  1. Bring up an agent host supervisor on commit A (e.g. 7090241a056cb49cfe90f58da9a8cc44df9262a9, protocol 0.2.0).
  2. Connect a desktop on commit B (newer protocol 0.3.0). Handshake fails with UnsupportedProtocolVersion.
  3. Click "Update Server". The supervisor receives the _vscodeUpgrade RPC, calls kill_running_server, then restarts on commit B.
  4. 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 with ppid=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:

  1. 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 send SIGTERM to the negative pgid on shutdown. Robust regardless of what the launch script does.
  2. Make the launcher forward signals, e.g. trap SIGTERM / SIGINT in code-server-<quality> and re-signal $! before wait. Cheaper change but doesn't help non-shell launchers.
  3. 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.rs and 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)

Activity

  1. added
    agent-host
    on Jun 2, 2026
  2. added
    bug
    on Jun 9, 2026
  3. added a commit that references this issue on Jun 9, 2026
    f8a5597
  4. added
    unreleased
    on Jun 9, 2026
  5. added this to the 1.125.0 milestone on Jun 9, 2026
  6. added
    insiders-released
    and removed
    unreleased
    on Jun 10, 2026
  7. jruales commented on Jun 16, 2026

    @jruales
    Contributor
  8. locked and limited conversation to collaborators on Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agent-hostbuginsiders-releasedverified

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions