github / github/copilot-cli

[Windows] Shell commands have no console handle since v1.0.57 - breaks Clear-Host and MSAL interactive auth

Đang mở
#3,683 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
area:platform-windows area:tools
Ngôn ngữ chính
Shell
Star
11.2k
Fork
1.9k
Merge trung bình
14 giờ 16 phút
Pull request đã merge (30 ngày)
6

Mô tả

## Describe the bug

Since upgrading from v1.0.47 to v1.0.60, the `powershell` tool launches `pwsh.exe` without a console handle attached to the process. This breaks any script that calls `Clear-Host`/`cls` or requires MSAL interactive browser authentication.

Evidence from inside a powershell tool call:
```powershell
# GetConsoleWindow() returns 0 (no console window)
Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public class C { [DllImport("kernel32.dll")] public static extern IntPtr GetConsoleWindow(); }'
[C]::GetConsoleWindow() # 0

[System.Console]::WindowWidth # Throws "The handle is invalid"
Clear-Host # Throws SetValueInvocationException: "The handle is invalid"

# Process has no window
[System.Diagnostics.Process]::GetCurrentProcess().MainWindowHandle # 0
```

## Affected version

```
GitHub Copilot CLI 1.0.60-0.
```

Last working version: 1.0.47 (May 13, 2026).

## Steps to reproduce the behavior

1. Launch Copilot CLI v1.0.60 on Windows
2. Ask it to run a command containing `cls` or `Clear-Host` (e.g., "run `cls; Write-Host hello`")
3. Observe exit code 1 with error:
```
SetValueInvocationException:
Line |
3 | $RawUI.CursorPosition = @{X=0;Y=0}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception setting "CursorPosition": "The handle is invalid."
```

Alternatively:
1. Ask it to run any script that uses MSAL interactive auth (e.g., Azure EV2 deployment cmdlets)
2. Auth fails with:
```
Failed to get authentication information : Value cannot be null. (Parameter 'format').
```
No browser window opens for authentication.

## Expected behavior

Shell commands executed via the `powershell` tool should have a console handle attached, as they did in v1.0.47. `Clear-Host` should succeed or be a silent no-op, and MSAL should be able to open a browser for interactive authentication.

## Additional context

- Operating system: Windows 11 (10.0.26100)
- CPU architecture: x86_64
- Terminal emulator: Windows Terminal
- Shell: PowerShell 7.6.2
- The pwsh process is launched as: `pwsh.exe -NoProfile -NoLogo -NonInteractive -Command "..."`
- The Copilot shell wrapper's `finally` block checks `$?` and calls `$host.SetShouldExit(1)` on any error, making the `cls` error fatal
- Workaround: use `Start-Process pwsh -ArgumentList @("-ExecutionPolicy", "Bypass", "-Command", $cmd)` to get a real console window, but this prevents the agent from capturing stdout directly
- Possibly related: #2525

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start by locating the powershell tool's pwsh.exe launch path and its shell wrapper, especially the finally block that calls $host.SetShouldExit(1). Reproduce on Windows with the documented pwsh arguments using Clear-Host and an MSAL interactive-auth script, then compare behavior with v1.0.47. Done means commands retain the expected console behavior without making stdout uncapturable, and the reported failures are covered by tests or verified reproduction steps.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
powershell
Lĩnh vực
cli, operating-systems
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.