github / github/copilot-cli

Every shell command emits a spurious error under PowerShell ConstrainedLanguage mode (AppLocker/WDAC): $host.SetShouldExit() is not permitted

オープン
#4,683 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

area:platform-windows area:tools
主要言語
Shell
スター
11.2k
フォーク
1.9k
平均マージ
14時間 16分
マージ済み PR(30日)
6

説明

Describe the bug

On Windows machines where PowerShell runs in ConstrainedLanguage mode (enforced by AppLocker or WDAC, common in managed enterprise environments), every single shell command run by the agent prints a spurious error block.

Copilot CLI appends an exit-status epilogue to each command it runs:

} finally { $__copilotSuccess = $?; if (-not $__copilotSuccess -and $LASTEXITCODE -is [int] -and $LASTEXITCODE -ne 0) { $host.SetShouldExit($LASTEXITCODE) } elseif (-not $__copilotSuccess) { $host.SetShouldExit(1) } else { $host.SetShouldExit(0) } }

$host.SetShouldExit() is a .NET method call on a non-core type, which ConstrainedLanguage forbids. The wrapper itself therefore fails and emits:

Cannot invoke the method. Method invocation is supported only on core types in this language mode.
At line:2 char:225
+ ... Success) { $host.SetShouldExit(1) } else { $host.SetShouldExit(0) } }
+                                                ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage
Why this matters
  • Affects every command: Get-Item, python, curl — all of them.
  • Pollutes the model context. The block is ~150 tokens.
  • Risks incorrect failure detection. The text goes to stderr.
Suggested fix

Replace the $host.SetShouldExit(...) calls with the exit keyword, which is fully permitted in ConstrainedLanguage:

} finally { $__copilotSuccess = $?; if (-not $__copilotSuccess -and $LASTEXITCODE -is [int] -and $LASTEXITCODE -ne 0) { exit $LASTEXITCODE } elseif (-not $__copilotSuccess) { exit 1 } else { exit 0 } }

Alternatively, guard the call with a language-mode check and fall back to exit.

Affected version

1.0.81-0 (also reproduced on 1.0.82)

Steps to reproduce the behavior
  1. On a Windows machine where AppLocker/WDAC forces PowerShell into ConstrainedLanguage mode.
    Verify with $ExecutionContext.SessionState.LanguageMode, which returns ConstrainedLanguage.
  2. Run any trivial shell command via the agent, e.g. Get-Item $env:TEMP or python --version.
  3. Observe the MethodInvocationNotSupportedInConstrainedLanguage error block shown above.
Expected behavior

The exit-status wrapper should use constructs permitted in ConstrainedLanguage (e.g. the exit keyword), so no spurious output is appended to successful commands.

Additional context
  • OS: Windows 11, domain-joined, managed by corporate GPO
  • CPU architecture: x86_64
  • Shell: Windows PowerShell 5.1 (powershell.exe) — also reproduced on PowerShell 7.6.5 (pwsh.exe), so this is not version-specific
  • Language mode: ConstrainedLanguage, enforced by AppLocker (Exe rule collection, EnforcementMode=1, pushed via domain GPO)
  • Host: Copilot CLI running as the VS Code agent host (@github/copilot-win32-x64)
Verification performed
  • Confirmed the offending template string is present in prebuilds/win32-x64/runtime.node.
  • Confirmed it is still present in 1.0.82, so updating does not resolve it.
  • Confirmed the wrapped commands themselves succeed and the process exit code is still correct (0 on success). The failure is limited to the epilogue, making this primarily output noise plus a stderr false-positive risk.
  • A user-side trap cannot suppress it, because the error is raised from the wrapper's own finally block.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず prebuilds/win32-x64/runtime.node にある問題の template string を調べ、$ExecutionContext.SessionState.LanguageMode と Get-Item $env:TEMP のようなコマンドを使って ConstrainedLanguage 下で wrapper を再現します。exit-status epilogue が許可された構文を使用していること、また成功するコマンドと失敗するコマンドのどちらも MethodInvocationNotSupportedInConstrainedLanguage エラーを出力しなくなっていることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
powershell
領域
cli
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
明確に書かれている
初心者へのやさしさ
68/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。