Skip to content

Fix Windows compatibility: subprocess preexec_fn is POSIX-only#85

Open
Le-Anh-Duy wants to merge 2 commits into
microsoft:mainfrom
Le-Anh-Duy:fix/windows-preexec-fn
Open

Fix Windows compatibility: subprocess preexec_fn is POSIX-only#85
Le-Anh-Duy wants to merge 2 commits into
microsoft:mainfrom
Le-Anh-Duy:fix/windows-preexec-fn

Conversation

@Le-Anh-Duy

Copy link
Copy Markdown

subprocess.Popen(preexec_fn=..., start_new_session=True) raised "preexec_fn is not supported on Windows platforms" for every LLM call and test-runner invocation, causing /cmind.encode and friends to fail outright on Windows.

Branch on platform: POSIX keeps start_new_session + preexec_fn (killpg-based tree kill); Windows uses CREATE_NEW_PROCESS_GROUP and a new _kill_process_tree() helper that shells out to taskkill /T /F to reap the process tree instead.

Verified end-to-end: reinstalled the patched package as the local cmind-cli tool and ran a full /cmind.encode against an external repo on Windows; it now completes successfully (previously failed on every LLM call).

subprocess.Popen(preexec_fn=..., start_new_session=True) raised
"preexec_fn is not supported on Windows platforms" for every LLM call
and test-runner invocation, causing /cmind.encode and friends to fail
outright on Windows.

Branch on platform: POSIX keeps start_new_session + preexec_fn
(killpg-based tree kill); Windows uses CREATE_NEW_PROCESS_GROUP and a
new _kill_process_tree() helper that shells out to `taskkill /T /F`
to reap the process tree instead.

Verified end-to-end: reinstalled the patched package as the local
cmind-cli tool and ran a full /cmind.encode against an external repo
on Windows; it now completes successfully (previously failed on every
LLM call).
@Le-Anh-Duy

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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

Fixes Windows incompatibility caused by using POSIX-only subprocess.Popen(preexec_fn=...) by branching process-spawn and process-tree cleanup behavior by platform.

Changes:

  • Add a platform-aware process-tree termination helper and use it for timeout/exception cleanup.
  • Make Popen invocation platform-specific: POSIX uses start_new_session + preexec_fn, Windows uses CREATE_NEW_PROCESS_GROUP.
  • Expand .gitignore entries for CoderMind-managed local directories/files.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
CoderMind/scripts/common/llm_client.py Adds Windows-safe process spawning and cross-platform process-tree kill helper for LLM CLI invocations.
CoderMind/scripts/code_gen/test_runner.py Reuses the shared process spawning/kill logic for pytest/project test execution with Windows support.
.gitignore Adds ignore rules for CoderMind-managed local artifacts and config, with an exception for config.toml.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CoderMind/scripts/common/llm_client.py
Comment thread CoderMind/scripts/code_gen/test_runner.py
On Windows, _kill_process_tree ignores taskkill's return code. If taskkill fails (e.g. access denied / process already exited / PID reuse edge), this function returns without killing the process, but callers then do proc.wait(), which can hang indefinitely. Please fall back to proc.kill() when taskkill returns non-zero (or use check=True and catch CalledProcessError).

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@QingtaoLi1

Copy link
Copy Markdown
Contributor

@Le-Anh-Duy Thanks for your fix patch! CoderMind has not been officially tested on Windows platform. I tested your patch and it does fix the subprocess compatibility problem. However, the /cmind.encode command still fails with input errors on my Windows device. Does the /cmind.encode command run well at your side?

@Le-Anh-Duy

Le-Anh-Duy commented Jul 10, 2026 via email

Copy link
Copy Markdown
Author

@Le-Anh-Duy

Le-Anh-Duy commented Jul 10, 2026 via email

Copy link
Copy Markdown
Author

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

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines 11 to 13
import os as _os
import platform as _platform
import re
Comment on lines 23 to 25
from common.llm_client import LLMClient
from common.llm_client import _IS_WINDOWS, _kill_process_tree, _set_pdeathsig
import json as _json
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.

3 participants