Skip to content

fix(windows): ensure silent execution and bypass execution policy for subprocesses#340

Open
feision wants to merge 1 commit into
lsdefine:mainfrom
feision:fix/windows-silent-execution
Open

fix(windows): ensure silent execution and bypass execution policy for subprocesses#340
feision wants to merge 1 commit into
lsdefine:mainfrom
feision:fix/windows-silent-execution

Conversation

@feision
Copy link
Copy Markdown

@feision feision commented May 11, 2026

Problem
On Windows, the agent frequently triggers intrusive CMD/PowerShell console windows when executing scripts (especially via node, npm, or other toolchains). This creates a "flickering" effect that disrupts the user's focus. Additionally, default PowerShell execution policies can sometimes block or stall script execution.

Solution
This PR implements two low-level fixes to ensure a 100% silent and stable background execution environment on Windows:

PowerShell Policy Bypass (ga.py): Added -ExecutionPolicy Bypass to the PowerShell command builder. This prevents execution stalls caused by restricted system policies.

Global Subprocess Suppression (assets/code_run_header.py): Enhanced the subprocess monkey-patch to inject CREATE_NO_WINDOW (0x08000000) into the subprocess.run method. While the existing patch covered Popen, many modern Node.js wrappers use the run interface, which previously bypassed the silent flag.

Impact
Zero Popups: Completely eliminates CMD window flashing during npm install or other long-running tasks.
Stability: Prevents "zombie" or stalled processes due to PowerShell permission prompts.
Transparency: No changes to Linux/macOS behavior.


问题背景
在 Windows 环境下使用时,GA 运行脚本(尤其是通过 node、npm 或其他工具链)会频繁弹出 CMD/PowerShell 黑色窗口。这种“闪烁”效果非常干扰用户焦点,甚至会导致当前窗口失去焦点。此外,Windows 默认的 PowerShell 执行策略有时会拦截脚本运行,导致执行卡顿或失败。

解决方案
本 PR 针对底层执行逻辑进行了两项关键修复,确保 Windows 下 100% 后台静默且稳定运行:

绕过 PowerShell 执行策略 (ga.py): 在 PowerShell 命令构造中添加了 -ExecutionPolicy Bypass 参数。这解决了因系统权限策略导致的脚本拦截和执行停滞问题。

强制全局静默标志 (assets/code_run_header.py): 增强了 subprocess 的猴子补丁(Monkey Patch),将 CREATE_NO_WINDOW (0x08000000) 标志注入到 subprocess.run 方法中。 原因:原有的补丁仅覆盖了 Popen,但许多现代 Node.js 包装器使用的是 run 接口,这会导致之前的静默标志失效。本次更新确保了所有 Python 派生的子进程均无窗口运行。

改动影响
零弹窗:彻底消除了 npm install 或长耗时任务期间的 CMD 窗口闪烁。
稳定性提升:防止了因 PowerShell 权限提示导致的“僵尸进程”或任务挂起。
无副作用:仅针对 Windows 环境 (os.name == 'nt') 生效,不影响 Linux/macOS 用户。

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.

1 participant