fix(windows): ensure silent execution and bypass execution policy for subprocesses#340
Open
feision wants to merge 1 commit into
Open
fix(windows): ensure silent execution and bypass execution policy for subprocesses#340feision wants to merge 1 commit into
feision wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 用户。