-
Notifications
You must be signed in to change notification settings - Fork 6.1k
fix(windows-path): preserve PATH order; include core env vars #5579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Context: * Address open issues related to PATH/PATHEXT and Windows env propagation. * Prepending to PATH changed users' tool precedence (e.g., virtualenv). MCP servers on Windows missed critical env vars (COMSPEC, SYSTEMROOT, etc.). Change: * Append apply_patch temp dir to PATH instead of prepending (arg0, Node wrapper). * Expand Windows DEFAULT_ENV_VARS for MCP client to include COMSPEC, SYSTEMROOT, PROGRAMFILES, APPDATA, etc. Risk: * Low: only affects PATH ordering (preserved) and adds allowed env passthrough. No privilege broadening. Tests: * Existing rmcp-client unit tests pass. Verification: * Ran cargo fmt. * Built and ran tests: `cargo test -p codex-rmcp-client` (all passed). `cargo check -p codex-arg0` OK.
Context: * Some Windows programs (incl. MCP servers/plugins) read canonical `Path` key. * Users had to manually set PWSH/POWERSHELL; include when present. Change: * In rmcp-client env builder, ensure `Path` mirrors `PATH` on Windows. * Add PROGRAMW6432, POWERSHELL, PWSH to the default pass-through list. Risk: * Low; only adds env keys when available. No privilege expansion. Tests: * Added Windows unit test verifying PATH/Path aliasing. Verification: * cargo fmt; cargo clippy -p codex-rmcp-client; cargo test -p codex-rmcp-client (all ok).
- Conditionally declare `mut` only on Windows in env builder. - Remove unnecessary `clone()` flagged by clippy. Validated with: cargo clippy -p codex-rmcp-client -D warnings.
There was a problem hiding this 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.
ℹ️ 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".
- On Windows, if only `Path` is provided (extra env/whitelist), ensure `PATH` is set to the same value (and vice versa). Avoids HashMap ordering races. Validated: clippy clean, rmcp-client tests pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commenting to say that this change feels reasonable to me, but am going to test this before approving
I have good availability today so if there are adjustments you want let me know and I can work on them ASAP. I want to get Windows up to where it needs to be. This goes for all of my PRs. |
| "TMP", | ||
| // Common shells/pwsh hints | ||
| "POWERSHELL", | ||
| "PWSH", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpjet64 if we separate these changes, i'm happy to stamp the DEFAULT_ENV_VARS change and merge it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dylan-hurd-oai Happy to do so but was hoping it would pass since my next PR for this issue is virtual shells like Python venv and such and the non-PATH fix is the foundation.
I will make this PR into a dedicated path fix in the meantime.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not opposed to switching to appending here, but the impacts of the path change are just more subtle, and might impact the success rate of apply_patch calls. Adding env vars to unblock better MCP support on windows feels much lower risk, so let's get that improvement in and we can focus on this PATH change here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dylan-hurd-oai Understood and I agree the env var change is definitely more low risk because I didn't consider the apply-patch impact in that manner. I'll split them now and get you a new commit in a few minutes! Later I'll dig more into apply_patch to make sure before I push a new PR for it. Thanks for that!
…:\n* Reviewer requested separating concerns; keep env passthrough low-risk changes in this PR.\n\nChange:\n* Revert PATH precedence changes in arg0 and Node wrapper (restore prepend).\n* Remove PATH<->Path aliasing logic and test from rmcp-client; retain expanded DEFAULT_ENV_VARS.\n\nRisk:\n* None beyond reverting to upstream behavior for PATH order and aliasing; env list expansion preserved.\n\nTests:\n* Ran just fmt; just fix -p codex-arg0, codex-rmcp-client.\n* cargo test -p codex-rmcp-client -> all tests pass.\n\nVerification:\n* Diff for PR now limited to DEFAULT_ENV_VARS in rmcp-client.
|
Update: Split the changes as requested.
This should make #5579 low‑risk and ready for review/merge. If you’d like the PATH<->Path mirroring pursued as a separate follow‑up as well, I can open a dedicated PR for that too. |
@dylan-hurd-oai my local bugged out do not merge that. Not everything was committed. Fixing now. |
OK. BLUF. It was a browser cache issue and everything did actually commit properly GH just wasnt showing me the correct diff. We are good to go pending CI. Terrifying and embarrassing moment for me 😨 ! |
Preserve PATH precedence & fix Windows MCP env propagation
Problem & intent
Preserve user PATH precedence and reduce Windows setup friction for MCP servers by avoiding PATH reordering and ensuring Windows child processes receive essential env vars.
prepend_path_entry_for_apply_patchmangles $PATH and interferes with python virtualenv behavior #5225 MCP client forplaywrightfailed to start: program not found #2945 Windows can not launch MCP servers using PNPM #3245 The solution for encountering the Error "Error creating local task: Error: Timeout" when using "startup_timeout_ms" under windows #3385 Unable to execute shell commands #2892 Playwright mcp fails on windows : program not found #3310 Vs Code Extension MCP timed out and program not found #3457 Documentation for Docker Desktop MCP Gateway #4370Before / After
Before
apply_patchhelper dir (Rust + Node wrapper), reordering tools and breaking virtualenvs/shims on macOS/Linux.After
PATH→Path, so typical CLIs/plugins work without per-server env blocks.Scope of change
codex-rs/arg0/src/lib.rsPATHinstead of prepending.codex-cli/bin/codex.jscodex-rs/rmcp-client/src/utils.rsDEFAULT_ENV_VARS(e.g.,COMSPEC,SYSTEMROOT,PROGRAMFILES*,APPDATA, etc.).PATH→Pathfor Windows child processes.mut+clippycleanup.Security effects
No broadened privileges. Only environment propagation for well-known Windows keys on stdio MCP child processes. No sandbox policy changes and no network additions.
Testing evidence
Static
cargo fmtcargo clippy -p codex-arg0 -D warnings→ cleancargo clippy -p codex-rmcp-client -D warnings→ cleancargo test -p codex-rmcp-client→ 13 passedManual
unused_mutwarnings on non-Windows targets).Checklist
PATHmirrored toPathcargo fmt/clippyclean across touched crates