fix(python): terminate owned CLI process trees on stop#1829
Open
syf2211 wants to merge 1 commit into
Open
Conversation
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
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Ensure
CopilotClient.stop()andforce_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.cmd→cmd.exe) leaves orphanednode.exe/copilot.exedescendants alive after each session. POSIX spawns also benefit from process-group teardown when children outlive the parent.Changes
copilot._processhelpers:popen_process_group_kwargs()—start_new_session=Trueon POSIX spawnsterminate_owned_cli_process()—killpgon POSIX,taskkill /Ton Windows, with graceful→force escalationCopilotClient.stop()/force_stop()viaasyncio.to_thread()test_process.py; update shutdown tests to assert tree termination callsTests
python3 -m pytest test_process.py -q— 6 passedTestClientShutdownupdated (fulltest_client.pyrequires bundled CLI harness)Notes
taskkill /F /T; graceful path uses/Tfirst.Fixes #1804