copilot-sdk
copilot-sdk copied to clipboard
fix(python): terminate owned CLI process trees on stop
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.cmd → cmd.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._processhelpers:popen_process_group_kwargs()—start_new_session=Trueon POSIX spawnsterminate_owned_cli_process()—killpgon POSIX,taskkill /Ton Windows, with graceful→force escalation
- Use helpers from
CopilotClient.stop()/force_stop()viaasyncio.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 passedTestClientShutdownupdated (fulltest_client.pyrequires bundled CLI harness)
Notes
- External-server TCP connections are unchanged (socket terminate only).
- Windows force path uses
taskkill /F /T; graceful path uses/Tfirst.
Fixes #1804