Skip to content

fix: crash on Windows MSYS2 UCRT env when executing command#2826

Open
mindfulcoder wants to merge 4 commits intoQwenLM:mainfrom
mindfulcoder:fix/issue-2306-fix-crash-msys2-ucrt-env-on-windows11
Open

fix: crash on Windows MSYS2 UCRT env when executing command#2826
mindfulcoder wants to merge 4 commits intoQwenLM:mainfrom
mindfulcoder:fix/issue-2306-fix-crash-msys2-ucrt-env-on-windows11

Conversation

@mindfulcoder
Copy link
Copy Markdown

Fix process crash when running Qwen Code in MSYS2 UCRT environment on Windows. The issue was caused by findGitBashPath() incorrectly selecting MSYS2's bash instead of Git Bash, which is incompatible with Windows ConPTY.

Changes:

  • Add isRunningInMSYS2() and isRunningInGitBash() detection functions
  • Use system default shell (cmd.exe) in MSYS2 environments
  • Disable node-pty in MSYS2 to avoid ConPTY crashes
  • Add unit tests for environment detection

Fixes #2306

TLDR

Problem: Qwen Code crashes when executing system commands on Windows MSYS2 UCRT environments (UCRT64, CLANG64, MSYS).

Root Cause: The findGitBashPath() function introduced in commit c2fe554e3 incorrectly selects MSYS2's bundled bash instead of Git Bash. MSYS2 bash is designed for the MSYS2 POSIX emulation layer and is incompatible with Windows ConPTY (used by node-pty), causing immediate crashes.

Solution:

  1. Added environment detection functions (isRunningInMSYS2(), isRunningInGitBash()) to distinguish between MSYS2 and Git Bash environments using the MSYSTEM environment variable
  2. In MSYS2 environments, use system default shell (cmd.exe via ComSpec) instead of bash - reverting to v0.11.1's working behavior
  3. In Git Bash environments (MINGW64, MINGW32), continue using findGitBashPath() to locate Git Bash correctly
  4. Disable node-pty in MSYS2 environments and fall back to child_process to avoid ConPTY incompatibility

Files Changed:

  • packages/core/src/utils/shell-utils.ts - Added detection functions and refactored getShellConfiguration()
  • packages/core/src/services/shellExecutionService.ts - Disable node-pty in MSYS2
  • packages/core/src/utils/shell-utils.test.ts - Added unit tests for new detection functions

Screenshots / Video Demo

N/A

Dive Deeper

Environment Variable Analysis

Environment Variable MSYS2 UCRT Git Bash
MSYSTEM UCRT64 MINGW64
MINGW_PREFIX /ucrt64 /mingw64
MSYSTEM_PREFIX /ucrt64 /mingw64

Detection Logic

Environment Type Detection Condition Shell Used
MSYS2 MSYSTEM === 'MSYS' or starts with UCRT/CLANG cmd.exe (via ComSpec)
Git Bash MSYSTEM.startsWith('MINGW') or TERM contains cygwin Git Bash (via findGitBashPath())
Other Windows Default cmd.exe or PowerShell

Why This Fix Works

  • v0.11.1 behavior restored for MSYS2: Before commit c2fe554e3, MSYS2 environments worked correctly because they used the system default shell
  • Git Bash still optimized: Git Bash environments continue to benefit from the findGitBashPath() fix for users who have Git Bash installed
  • No regression: Linux, macOS, and standard Windows (cmd/PowerShell) users are unaffected

Reviewer Test Plan

  1. MSYS2 UCRT64 environment (primary fix validation):

    • Install MSYS2 with UCRT64 toolchain
    • Launch UCRT64 terminal
    • Run qwen and execute any shell command (e.g., ls, pwd, echo test)
    • Verify: No crash, command executes successfully via cmd.exe
  2. Git Bash environment (regression test):

    • Launch Git Bash terminal
    • Run qwen and execute shell commands
    • Verify: Commands execute using Git Bash correctly
  3. Standard Windows environments (regression test):

    • cmd.exe: Run qwen and verify commands work
    • PowerShell: Run qwen and verify commands work
  4. Run unit tests:

    npm run test -- packages/core/src/utils/shell-utils.test.ts
    • Verify: All 14 new test cases pass (6 for isRunningInMSYS2, 8 for isRunningInGitBash)
  5. Type checking:

    npm run typecheck

Testing Matrix

🍏 🪟 🐧
npm run -
npx -
Docker - - -
Podman - - -
Seatbelt - - -

Notes:

  • macOS (🍏) and Linux (🐧): No changes to Unix shell handling, existing behavior preserved
  • Windows (🪟): Primary platform for this fix - tested in MSYS2 UCRT64, Git Bash, cmd.exe, and PowerShell

Linked issues / bugs

Fixes #2306

Copy link
Copy Markdown
Collaborator

@wenshao wenshao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(previous review superseded)

Copy link
Copy Markdown
Collaborator

@wenshao wenshao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(previous review superseded)

Copy link
Copy Markdown
Collaborator

@wenshao wenshao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(previous review superseded)

mindfulcoder and others added 2 commits April 7, 2026 15:37
Fix process crash when running Qwen Code in MSYS2 UCRT environment on Windows.
The issue was caused by findGitBashPath() incorrectly selecting MSYS2's bash
instead of Git Bash, which is incompatible with Windows ConPTY.

Changes:
- Add isRunningInMSYS2() and isRunningInGitBash() detection functions
- Use system default shell (cmd.exe) in MSYS2 environments
- Disable node-pty in MSYS2 to avoid ConPTY crashes
- Add unit tests for environment detection

Fixes QwenLM#2306

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
…n bash env check;2. restore the logic for checking git bash env to keep compatibility.
@mindfulcoder mindfulcoder force-pushed the fix/issue-2306-fix-crash-msys2-ucrt-env-on-windows11 branch from b7b2522 to 10da38b Compare April 7, 2026 07:48
- Convert isRunningInMSYS2 mock to hoisted variable to allow runtime control
- Add test case verifying child_process fallback when running in MSYS2 environment
- Ensure PTY is skipped and child_process is used directly in MSYS2 even when shouldUseNodePty is true

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Copy link
Copy Markdown
Collaborator

@wenshao wenshao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes — see inline comment on isRunningInMSYS2().

Reviewed by glm-5.1 via Qwen Code /review

wenshao added a commit that referenced this pull request Apr 7, 2026
Two issues found from real review (PR #2826):

1. Multiple /review runs on same PR create duplicate comments. Now
   Step 9 checks for existing "via Qwen Code /review" comments
   before posting and warns the user about potential duplicates.

2. Comments posted without line numbers appear as orphaned PR
   comments. Now enforced: every inline comment MUST reference a
   specific line in the diff. Findings that can't be mapped to
   diff lines go in the summary instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
export const isWindows = () => os.platform() === 'win32';

/**
* 检测当前是否运行在 MSYS2 环境中
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not use Chinese annotation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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.

Qwen Code crash when asking permission to execute cmd

3 participants