Skip to content

fix(executor): handle Windows shell runtimes robustly#709

Merged
mksglu merged 1 commit into
mksglu:nextfrom
NgoQuocViet2001:fix/windows-powershell-execution-policy
May 25, 2026
Merged

fix(executor): handle Windows shell runtimes robustly#709
mksglu merged 1 commit into
mksglu:nextfrom
NgoQuocViet2001:fix/windows-powershell-execution-policy

Conversation

@NgoQuocViet2001

Copy link
Copy Markdown
Contributor

What / Why / How

While dogfooding context-mode from Codex on Windows, ctx_execute(language: "shell") and ctx_batch_execute can fail before user code runs:

File ...\script.ps1 cannot be loaded because running scripts is disabled on this system.
UnauthorizedAccess

Codex sets SHELL to Windows PowerShell in this environment. context-mode correctly writes a temporary script.ps1, but then runs it as powershell -File <script>. On normal Windows PowerShell installs where the effective execution policy is Restricted, that temp script is blocked.

This patch keeps the fix narrow to Windows shell handling:

  • run Windows PowerShell / pwsh temp scripts with -NoProfile -ExecutionPolicy Bypass -File
  • use .cmd temp scripts plus cmd.exe /d /s /c when the selected shell is cmd
  • ignore Windows WSL bash shims from SHELL overrides, so Windows-hosted execution falls back to Git Bash instead of C:\Windows\System32\bash.exe
  • keep Git Bash, cmd, PowerShell 5, pwsh 7, and Unix shell command shapes covered by tests

ExecutionPolicy Bypass here is process-scoped for this spawned PowerShell process only; it does not change machine/user policy.

Validation

  • pnpm exec vitest run tests/runtime.test.ts -t "SHELL env var|Windows bash gets bash -c source pattern|Windows powershell gets process-scoped execution policy bypass|Windows pwsh gets process-scoped execution policy bypass|Windows cmd gets cmd /c pattern|Unix bash gets direct file path" --reporter=dot
  • pnpm exec vitest run tests/executor.test.ts -t "PowerShell shell runtime executes generated script|buildCommand returns shell command array|buildScriptFilename: POSIX shell on Windows has NO extension|buildScriptFilename: cmd on Windows uses .cmd extension|buildScriptFilename: PowerShell on Windows uses .ps1 extension|buildScriptFilename: shell on Unix keeps .sh extension" --reporter=dot
  • Manual PolyglotExecutor smoke on this Windows machine: Windows PowerShell 5, pwsh 7, Git Bash, cmd all executed successfully.
  • Manual MCP smoke against rebuilt server.bundle.mjs: ctx_execute and ctx_batch_execute succeeded for Windows PowerShell 5, pwsh 7, Git Bash, cmd, and WSL-bash-shim fallback.
  • pnpm run typecheck
  • pnpm run build

@mksglu mksglu merged commit 59f4d10 into mksglu:next May 25, 2026
5 checks passed
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.

2 participants