Skip to content

Conversation

@cpjet64
Copy link
Contributor

@cpjet64 cpjet64 commented Oct 23, 2025

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.


Before / After

Before

  • PATH was prepended with an apply_patch helper dir (Rust + Node wrapper), reordering tools and breaking virtualenvs/shims on macOS/Linux.
  • On Windows, MCP servers missed core env vars and often failed to start without explicit per-server env blocks.

After

  • Helper dir is appended to PATH (preserves user/tool precedence).
  • Windows MCP child env now includes common core variables and mirrors PATHPath, so typical CLIs/plugins work without per-server env blocks.

Scope of change

codex-rs/arg0/src/lib.rs

  • Append temp/helper dir to PATH instead of prepending.

codex-cli/bin/codex.js

  • Mirror the same append behavior for the Node wrapper.

codex-rs/rmcp-client/src/utils.rs

  • Expand Windows DEFAULT_ENV_VARS (e.g., COMSPEC, SYSTEMROOT, PROGRAMFILES*, APPDATA, etc.).
  • Mirror PATHPath for Windows child processes.
  • Small unit test; conditional mut + clippy cleanup.

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 fmt
  • cargo clippy -p codex-arg0 -D warningsclean
  • cargo clippy -p codex-rmcp-client -D warningsclean
  • cargo test -p codex-rmcp-client13 passed

Manual

  • Local verification on Windows PowerShell 5/7 and WSL (no unused_mut warnings on non-Windows targets).

Checklist

  • Append (not prepend) helper dir to PATH in Rust and Node wrappers
  • Windows MCP child inherits core env vars; PATH mirrored to Path
  • cargo fmt / clippy clean across touched crates
  • Unit tests updated/passing where applicable
  • Cross-platform behavior preserved (macOS/Linux PATH precedence intact)
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.
Copy link
Contributor

@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.

ℹ️ 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.
Copy link
Collaborator

@dylan-hurd-oai dylan-hurd-oai left a 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

@cpjet64
Copy link
Contributor Author

cpjet64 commented Oct 28, 2025

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",
Copy link
Collaborator

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

Copy link
Contributor Author

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!

Copy link
Collaborator

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.

Copy link
Contributor Author

@cpjet64 cpjet64 Oct 29, 2025

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!

cpjet64 and others added 2 commits October 28, 2025 21:04
…:\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.
@cpjet64
Copy link
Contributor Author

cpjet64 commented Oct 29, 2025

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.

@cpjet64
Copy link
Contributor Author

cpjet64 commented Oct 29, 2025

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.

@cpjet64
Copy link
Contributor Author

cpjet64 commented Oct 29, 2025

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 😨 !

@dylan-hurd-oai dylan-hurd-oai merged commit e9135fa into openai:main Oct 29, 2025
25 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants