Repository navigation
Kill full server process tree in agent host kill_running_server - #320631
Merged
Merged
Conversation
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]>
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]>
Contributor
There was a problem hiding this comment.
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_serverthroughkill_treeand then explicitly reap the root child process. - Rework non-Windows
kill_treeto walk the full descendant tree (BFS viapgrep -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
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]>
Michael Lively (Yoyokrazy)
approved these changes
Jun 9, 2026
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.
Fixes #319516
The CLI agent host supervisor launches the server via a shell shim (
<server>/bin/code-server-<quality>) that spawnsnode ... server-main.js, which in turn spawns abootstrap-forkagent host process. The previouschild.kill()inkill_running_serveronly terminated the shim, leaving the node descendants reparented to PID 1.This PR:
kill_running_serverthroughkill_tree(and reaps the child afterward).kill_treeto BFS the full descendant tree viapgrep -Prather than walking only direct children. Windows already covered the full tree viataskkill /t /pid.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.