Skip to content

fix(python): terminate owned CLI process trees on stop#1829

Open
syf2211 wants to merge 1 commit into
github:mainfrom
syf2211:fix/1804-process-tree-teardown
Open

fix(python): terminate owned CLI process trees on stop#1829
syf2211 wants to merge 1 commit into
github:mainfrom
syf2211:fix/1804-process-tree-teardown

Conversation

@syf2211

@syf2211 syf2211 commented Jun 29, 2026

Copy link
Copy Markdown

Summary

Ensure CopilotClient.stop() and force_stop() terminate the full SDK-owned CLI process tree instead of only the top-level launcher process.

Motivation

Fixes #1804. On Windows, terminating the launcher (copilot.cmdcmd.exe) leaves orphaned node.exe / copilot.exe descendants alive after each session. POSIX spawns also benefit from process-group teardown when children outlive the parent.

Changes

  • Add copilot._process helpers:
    • popen_process_group_kwargs()start_new_session=True on POSIX spawns
    • terminate_owned_cli_process()killpg on POSIX, taskkill /T on Windows, with graceful→force escalation
  • Use helpers from CopilotClient.stop() / force_stop() via asyncio.to_thread()
  • Add unit tests in test_process.py; update shutdown tests to assert tree termination calls

Tests

  • python3 -m pytest test_process.py -q — 6 passed
  • TestClientShutdown updated (full test_client.py requires bundled CLI harness)

Notes

  • External-server TCP connections are unchanged (socket terminate only).
  • Windows force path uses taskkill /F /T; graceful path uses /T first.

Fixes #1804

Spawn SDK-owned CLI servers in an isolated process group on POSIX and
use process-tree termination in stop()/force_stop() so child processes
are not orphaned when the top-level launcher exits.

On Windows, use taskkill /T to reap descendant node/copilot processes.

Fixes github#1804
@syf2211 syf2211 requested a review from a team as a code owner June 29, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CopilotClient.stop() leaks the CLI server's child process tree on Windows (orphaned node/copilot.exe per session)

1 participant