Skip to content

Kill full server process tree in agent host kill_running_server - #320631

Merged
Connor Peet (connor4312) merged 3 commits into
mainfrom
connor/fix-319516
Jun 9, 2026
Merged

Connor Peet (connor4312) merged 3 commits into
mainfrom
connor/fix-319516

Conversation

@connor4312

Copy link
Copy Markdown
Member

Fixes #319516

The CLI agent host supervisor launches the server via a shell shim (<server>/bin/code-server-<quality>) that spawns node ... server-main.js, which in turn spawns a bootstrap-fork agent host process. The previous child.kill() in kill_running_server only terminated the shim, leaving the node descendants reparented to PID 1.

This PR:

  • Routes kill_running_server through kill_tree (and reaps the child afterward).
  • Rewrites the non-Windows kill_tree to BFS the full descendant tree via pgrep -P rather than walking only direct children. Windows already covered the full tree via taskkill /t /pid.
  • Adds a depth-3 process-tree unit test on Unix that asserts every descendant is reaped.

Verified locally on macOS via code agent host + code agent kill — all four processes (supervisor, bash shim, server-main node, bootstrap-fork) are now reaped.

The CLI agent host supervisor launches the server via a shell shim
(`<server>/bin/code-server-<quality>`) that spawns `node ... server-main.js`,
which in turn spawns a `bootstrap-fork` agent host process. The previous
`child.kill()` in `kill_running_server` only terminated the shim, leaving
the node descendants reparented to PID 1.

Route the shutdown through `kill_tree` instead, and have the non-Windows
`kill_tree` walk the full descendant tree via `pgrep -P` rather than just
the direct children. Add a depth-3 process-tree unit test on Unix.

Fixes #319516

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 9, 2026 17:04
@connor4312
Connor Peet (connor4312) enabled auto-merge (squash) June 9, 2026 17:04
The previous test relied on `process_exists` to confirm pids were gone,
but on Linux the outer sh remains a zombie until its parent (the test
runtime) reaps it. Await `child.wait()` immediately after `kill_tree`
so the outer sh is reaped, and rely on init to reap the orphaned
descendants. Also bumps the deadline to 10s to absorb init latency.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a VS Code CLI agent host lifecycle issue where kill_running_server only terminated the launcher shim process, leaving the underlying node ... server-main.js (and its descendants like bootstrap-fork) orphaned and continuing to run (issue #319516). It updates the CLI’s process-termination logic so that shutdown/upgrade reliably terminates the entire server process tree and adds a Unix unit test to prevent regressions.

Changes:

  • Route kill_running_server through kill_tree and then explicitly reap the root child process.
  • Rework non-Windows kill_tree to walk the full descendant tree (BFS via pgrep -P) instead of only killing direct children.
  • Add a Unix unit test that spawns a depth-3 process tree and asserts all descendants are terminated.
Show a summary per file
File Description
cli/src/util/command.rs Implements BFS-based descendant discovery for kill_tree on Unix and adds a regression test validating full-tree termination.
cli/src/tunnels/agent_host.rs Switches kill_running_server to use kill_tree and reaps the child afterward to avoid leaving zombies.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread cli/src/tunnels/agent_host.rs Resolved
Comment thread cli/src/util/command.rs Resolved
Addresses Copilot review feedback:
- kill_running_server: bound child reap with a 5s timeout; escalate to
  SIGKILL via Child::kill if a process ignores SIGTERM, so a misbehaving
  server can't wedge the supervisor's shutdown or upgrade path.
- children_of: distinguish pgrep exit codes — 0/1 are expected (matches
  vs no matches), 2/3 are surfaced as CommandFailed.

Co-authored-by: Copilot <[email protected]>
@connor4312
Connor Peet (connor4312) merged commit f8a5597 into main Jun 9, 2026
39 of 40 checks passed
@connor4312
Connor Peet (connor4312) deleted the connor/fix-319516 branch June 9, 2026 18:28
@vs-code-engineering vs-code-engineering Bot added this to the 1.125.0 milestone Jun 9, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jul 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants