Skip to content

fix: handle PowerShell Restricted execution policy in install script#1516

Closed
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:fix/install-ps1-execution-policy
Closed

fix: handle PowerShell Restricted execution policy in install script#1516
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:fix/install-ps1-execution-policy

Conversation

@Br1an67
Copy link
Copy Markdown

@Br1an67 Br1an67 commented Mar 19, 2026

Related Issue

Resolve #1513

Description

On fresh Windows machines, PowerShell defaults to Restricted execution policy. The install script uses $ErrorActionPreference = "Stop" and calls Invoke-Expression to run the uv installer, but when the execution policy blocks it, the error propagates and terminates the script — causing the PowerShell window to close instantly without any error message.

Changes:

  • Auto-set RemoteSigned execution policy for the current process only (safe, non-persistent — does not modify system or user policy)
  • Wrap all installation steps in try-catch blocks
  • Display colored, user-friendly error messages with clear remediation steps
  • Add Read-Host pause before exit so the window stays open on failure, allowing users to read the error

Before: PowerShell window closes instantly with no feedback.
After: Error message is displayed with suggested fix, window stays open.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open with Devin

devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0a7683dff1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +5 to +7
$currentPolicy = Get-ExecutionPolicy -Scope Process
if ($currentPolicy -eq "Restricted" -or $currentPolicy -eq "Undefined") {
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate the policy rewrite on the effective execution policy

At scripts/install.ps1:5-7, Get-ExecutionPolicy -Scope Process is typically Undefined unless the caller already set a process-level override. Because the Process scope takes precedence over CurrentUser and LocalMachine, this branch rewrites the current shell to RemoteSigned even on machines that intentionally use AllSigned or another non-default policy in those lower scopes. In the documented Invoke-RestMethod ... | Invoke-Expression flow that means the installer mutates the user's existing PowerShell session and can silently weaken a stricter local policy; checking the effective policy before changing it would avoid that regression.

Useful? React with 👍 / 👎.

Write-Host " Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process" -ForegroundColor Cyan
Write-Host ""
}
Read-Host "Press Enter to exit"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid interactive prompts in the error path

The new Read-Host makes the failure path unusable for any non-interactive invocation of install.ps1 (for example, from automation or a wrapper that starts PowerShell with -NonInteractive). In that mode Read-Host itself is a terminating error, so callers lose the original installation failure and never reach the intended exit 1. Since this script is published as a general bootstrapper, the catch block should either skip the prompt when no interactive host is available or avoid prompting entirely.

Useful? React with 👍 / 👎.

Wrap Install-Uv in try-catch so that when the default Restricted
execution policy blocks Invoke-Expression, users see a clear error
message with the remediation command instead of the PowerShell
window silently closing.

Also replace Write-Error with Write-Host for the uv-not-found check
and add a 'Press any key to exit' prompt so users can read the error
before the window closes.

Fixes MoonshotAI#1513
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5e63087bc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Write-Host ""
Write-Host "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
exit 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid exiting the caller's PowerShell session

Checked docs/en/guides/getting-started.md:34-36: the documented Windows install flow pipes this script into Invoke-Expression inside the user's current PowerShell window. In that context, PowerShell's exit closes the current script or PowerShell instance, so this new exit 1 path now tears down the caller's shell on any bootstrap failure instead of returning them to the prompt after printing the remediation. That means users can lose session state/history and can't immediately run the suggested Set-ExecutionPolicy command in the same window.

Useful? React with 👍 / 👎.

@RealKai42 RealKai42 closed this Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants