Skip to content

fix(codex): prefer real PowerShell executable on Windows - #2492

Open
zyaoii wants to merge 2 commits into
makecindy:mainfrom
zyaoii:fix/windows-codex-pwsh-path
Open

fix(codex): prefer real PowerShell executable on Windows#2492
zyaoii wants to merge 2 commits into
makecindy:mainfrom
zyaoii:fix/windows-codex-pwsh-path

Conversation

@zyaoii

@zyaoii zyaoii commented Aug 12, 2026

Copy link
Copy Markdown

这次改了什么

Fixes #2446

  • 在 Windows 上构建 Codex 子进程环境时,优先把包含真实 pwsh.exe 的目录放到 PATH 首位。
  • 跳过 Microsoft Store 的 WindowsApps alias,避免 Codex 选中 pwsh.cmd shim 或无效 alias 后让所有 shell 命令报 batch file arguments are invalid
  • 正确识别被双引号包裹的 PATH 目录:探测时移除一对外围引号,重排时保留原始 PATH 条目。
  • 非 Windows 平台行为保持不变。
  • 增加针对 .cmd shim、WindowsApps alias 和带引号真实 PowerShell 目录的回归测试。

怎么验证的

  • pnpm --filter @cindy/maker-core test -- src/agents/codex/env-builder.test.ts(6/6 通过)
  • pnpm --filter @cindy/maker-core exec eslint src/agents/codex/env-builder.ts src/agents/codex/env-builder.test.ts(通过)
  • pnpm --filter @cindy/maker-core run --if-present typecheck(该 package 无 typecheck script,按仓库门禁跳过)
  • pnpm test:unit -- --workspace-concurrency=1(D 盘隔离 worktree 全量通过;仅在命令 PATH 前置本机 Python 3.10,以避开系统 Python 2.7)
  • pnpm check:dco(2 个 PR commits 均通过)

风险与回滚

  • 影响范围仅为 Windows 上启动的 Codex 子进程环境;不会修改用户持久化环境变量。
  • macOS/Linux 不进入该逻辑。
  • 如需回滚,可直接 revert 本 PR 的提交。

UI

  • 不涉及 UI、文案或视觉改动。

Signed-off-by: zyaoii <347929035@qq.com>
@zyaoii
zyaoii marked this pull request as ready for review August 12, 2026 04:36
@zyaoii
zyaoii requested a review from a team as a code owner August 12, 2026 04:36
@greptile-apps

greptile-apps Bot commented Aug 12, 2026

Copy link
Copy Markdown

Greptile Summary

此 PR 调整 Codex 子进程在 Windows 上的 PATH,使真实的 pwsh.exe 优先于 .cmd shim 和 WindowsApps 执行别名。

  • 新增 Windows 专用的 PowerShell 可执行文件查找与 PATH 重排逻辑。
  • 保留其余 PATH 条目的相对顺序,并兼容带引号的目录。
  • 增加 .cmd shim、WindowsApps 别名及带引号 PATH 条目的回归测试。

Confidence Score: 5/5

当前未发现仍需阻止合并的故障,PR 看起来可以安全合并。

未发现仍然存在的阻塞性故障。

Important Files Changed

Filename Overview
packages/maker-core/src/agents/codex/env-builder.ts 在 Windows 上识别并前置首个非 WindowsApps 的真实 pwsh.exe,未发现符合跟进审查范围的新问题。
packages/maker-core/src/agents/codex/env-builder.test.ts 新增 Windows 回归测试,覆盖 shim、执行别名和带引号 PATH 条目。

Reviews (2): Last reviewed commit: "fix(codex): handle quoted PowerShell PAT..." | Re-trigger Greptile

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

Copy link
Copy Markdown

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: 58ab92510e

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/maker-core/src/agents/codex/env-builder.ts Outdated
@MagicLizi MagicLizi added the status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) label Aug 12, 2026

@MagicLizi MagicLizi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

格式门:PR 描述不完整

你的 PR 描述缺少以下必要段落,请补充后重新请求审查:

  • 这次改了什么:说明本次改动的内容和背景
  • 怎么验证的:说明你是怎么验证这个修复的(测试、手动验证步骤等)

补充完毕后直接 push(不需要新开 PR),自动化流程会在下一轮重新扫描。


@MagicLizi

Copy link
Copy Markdown
Contributor

@zymk8353 👋 这个 PR 还有 1 条 review conversation 没 resolve(packages/maker-core/src/agents/codex/env-builder.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

Signed-off-by: zyaoii <347929035@qq.com>

zyaoii commented Aug 12, 2026

Copy link
Copy Markdown
Author

Addressed the quoted-PATH review feedback in d94a04dc.

The PowerShell probe now removes one surrounding quote pair for normalization and pwsh.exe existence checks, while preserving the original quoted PATH entry when reordering. Added a Windows regression test for the quoted-entry case.

Verification:

  • focused env-builder suite: 6/6 passed
  • ESLint: passed
  • repository-wide pnpm test:unit -- --workspace-concurrency=1: passed in an isolated worktree
  • DCO: passed for both PR commits

The inline conversation has been resolved.

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

Copy link
Copy Markdown

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: d94a04dc14

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +64 to +65
const [executableDir] = entries.splice(executableIndex, 1);
entries.unshift(executableDir);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep host-managed PATH prefixes ahead of PowerShell

When runtimeConfig.pathPrepends is present, this unshift moves the discovered PowerShell directory ahead of those explicitly prepended directories. The inspected Desktop config uses pathPrepends for its mandatory bundled ripgrep, so installations where the PowerShell directory also contains an rg.exe—for example, a shared user-managed shim directory—will run that copy instead of Cindy's validated binary. Prioritize pwsh.exe only within the user PATH, or perform this reordering before prepending host-managed tools.

Useful? React with 👍 / 👎.

const normalized = path.win32.normalize(directory).replace(/[\\/]+$/, '').toLowerCase();
if (normalized.endsWith('\\microsoft\\windowsapps')) return false;

return existsSync(path.join(directory, 'pwsh.exe'));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid synchronous probes of arbitrary PATH shares

When a Windows PATH contains a disconnected or slow UNC/network directory before the first usable pwsh.exe, existsSync blocks while Windows resolves that share. This scan runs during buildCodexEnv, which the Desktop main process calls while creating every local Codex host, so the main thread and UI can freeze until the filesystem timeout expires. Probe arbitrary PATH entries asynchronously with a bound, or use a lookup mechanism that cannot synchronously stall the Electron main thread.

Useful? React with 👍 / 👎.

@MagicLizi MagicLizi added status:ci-running CI 还在跑(review-pr 自动维护,仅展示) and removed status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) labels Aug 12, 2026
@MagicLizi

Copy link
Copy Markdown
Contributor

@zyaoii 👋 这个 PR 还有 2 条 review conversation 没 resolve(packages/maker-core/src/agents/codex/env-builder.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:ci-running CI 还在跑(review-pr 自动维护,仅展示)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell command tool broken in v0.1.44 - all commands fail with "batch file arguments are invalid"

2 participants