fix(tools): preserve canonical Windows location env var names in _build_safe_env - #49684
TheSmokeDev wants to merge 1 commit into
Conversation
|
Quick bump on this one. Still green against |
aeac1bc to
36cd3e8
Compare
|
Rebased onto current upstream/main (fbf748b) and re-ran the focused verification on native Windows via uv / CPython 3.13.3: \\ ext 6 passed in 7.44suv run --python 3.13 --extra dev --extra acp python -m pytest tests/tools/test_mcp_tool.py -q 200 passed in 22.49suv run --python 3.13 --extra dev ruff check tools/mcp_tool.py All checks passed\\ Still a single-file runtime fix in \ ools/mcp_tool.py\ (+22/-1), no scope change. |
|
Hey, I’m trying to help with native Windows compatibility. I refreshed this PR onto current main; it’s still a single-file P2 bug fix for MCP env vars, and the full \ ests/tools/test_mcp_tool.py\ file passes on native Windows. Happy to adjust shape if there’s a preferred reviewer path. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused Windows compatibility fix. Current main still copies the source key verbatim in tools/mcp_tool.py:436-442, while the existing regression contract expects canonical names at tests/tools/test_mcp_tool.py:1711-1713.
Problems
- The new lookup at
tools/mcp_tool.py:403runs on every platform. A POSIX environment withPROGRAMFILESwould now be emitted asProgramFiles, despite the PR stating non-Windows behavior is unchanged.
Suggested changes
- Gate the canonical-name mapping on
os.name == "nt"; retain the original key elsewhere. - Add a platform-independent test using uppercase source keys, rather than relying only on Windows
os.environnormalization.
This is an automated hermes-sweeper review.
| env[key] = value | ||
| # Restore the canonical mixed-case spelling for Windows location | ||
| # vars that os.environ upper-cased; other keys pass through as-is. | ||
| canonical_key = _WINDOWS_CANONICAL_ENV_KEYS.get(key.upper(), key) |
There was a problem hiding this comment.
Please gate this mapping on os.name == "nt". As written, a POSIX environment that intentionally contains PROGRAMFILES is rewritten to ProgramFiles, so non-Windows behavior is not preserved as the PR description states.
36cd3e8 to
4eb09d9
Compare
|
Rebased onto current |
4eb09d9 to
fdbe3ca
Compare
|
Addressed the sweeper review and rebased onto current
Fork CI still requires maintainer dispatch. The explicit review blocker is now closed; ready for workflow approval and review, or salvage/cherry-pick with authorship preserved. |
fdbe3ca to
2a99934
Compare
|
The 2026-07-14 review's two requested changes are in, plus a rebase and a test receipt worth highlighting. Changes:
The receipt: in a clean venv (pytest + mcp), current |
2a99934 to
08041d8
Compare
|
@teknium1 friendly bump — the fixes from your sweep were addressed (replies above) and CI is green. Want me to rebase onto current main before your next pass? |
08041d8 to
febad49
Compare
…ld_safe_env On Windows, CPython upper-cases every os.environ key, so _build_safe_env emitted PROGRAMFILES/PROGRAMDATA/PROGRAMW6432 instead of the documented mixed-case ProgramFiles/ProgramData/ProgramW6432 that launcher-style MCP tools expect. Map the upper-cased key back to its canonical spelling when building the subprocess env. All-uppercase vars (APPDATA, USERPROFILE) and non-Windows platforms are unaffected. Fixes NousResearch#49486
febad49 to
8b40bda
Compare
What
Preserve canonical mixed-case Windows location variable names (
ProgramFiles,ProgramData,ProgramW6432, and theCommonProgram*family) in the filtered environment passed to stdio MCP subprocesses.Why
The earlier #49486 fix allowlisted these variables, but current
mainstill emits each source key verbatim. CPython normalizesos.environkeys to uppercase on Windows, so launcher-style MCP servers receivePROGRAMFILESinstead of the documentedProgramFilesspelling they query.This follow-up maps only those known location keys back to canonical spelling, and only when
os.name == "nt". Secret filtering and explicit user-env precedence are unchanged. POSIX environments retain the exact source spelling.Review feedback addressed
PROGRAMFILESremainsPROGRAMFILESrather than being rewritten.Current-main A/B proof
Fresh verification after rebasing onto
mainat9f384783e:main, existing Windows-location test: fails withKeyError: 'ProgramFiles'.fdbe3ca81),TestBuildSafeEnv: 9 passed.tests/tools/test_mcp_tool.py: 217 passed.ruff check tools/mcp_tool.py tests/tools/test_mcp_tool.py: clean.git diff --check: clean.Scope
Two files: the runtime mapping and focused behavioral regression tests. No dependency, lockfile, or unrelated MCP changes.
Follow-up to #49486.