fix(terminal): strip PYTHONHOME/PYTHONPATH from subprocess env - #24928
fix(terminal): strip PYTHONHOME/PYTHONPATH from subprocess env#24928carterwayneskhizeine wants to merge 1 commit into
Conversation
Prevent Hermes Agent's own PYTHONHOME (pointing to uv's Python) from leaking into terminal subprocesses. This fixes 'No module named conda' errors on Windows where conda's Scripts/conda-script.py loads the wrong interpreter. Cf. install.sh which already unsets these vars at launch time.
teknium1
left a comment
There was a problem hiding this comment.
Thanks for identifying the inherited Python-runtime environment hazard. The foreground fix needs a small salvage for the current terminal architecture.
Problems
- The proposed change only covers foreground
LocalEnvironment._run_bash, which builds_make_run_env()attools/environments/local.py:1004. Background and PTY terminal spawns instead call_sanitize_subprocess_env()attools/process_registry.py:718andtools/process_registry.py:760; that helper currently copies allowed variables attools/environments/local.py:355-361and removes onlyVIRTUAL_ENV/CONDA_PREFIXat:383-384. - The diff contains no regression test.
tests/tools/test_local_env_blocklist.py:289-304already provides the matching pattern of asserting stripping from both environment constructors.
Suggested changes
- Apply the Python-runtime-variable scrub to both terminal environment builders and add tests for foreground plus background/PTY construction.
Automated hermes-sweeper review.
| # Sanitize PYTHONHOME/PYTHONPATH — they can cause the subprocess to load | ||
| # the wrong Python interpreter (e.g. uv's Python instead of conda's), which | ||
| # breaks tools like conda that rely on finding their own stdlib packages. | ||
| run_env.pop("PYTHONHOME", None) |
There was a problem hiding this comment.
Please apply the same scrub to _sanitize_subprocess_env: background and PTY terminal calls use it at tools/process_registry.py:718 and :760, while this change protects only the foreground _make_run_env path.
|
Partial update: the |
|
Both halves of this PR are now fixed on main: the PYTHONPATH strip landed in #88182, and the PYTHONHOME strip — which you were the first to report and propose, back in May — landed today in #88285 (as part of the ownership-model consolidation from #82581). The merged approach strips both selectively rather than the blanket pop proposed here, so user-set entries survive, but your conda repro was the original driver for the PYTHONHOME half. Thank you @carterwayneskhizeine — closing as completed on main. |
Summary
On Windows, Hermes Agent bootstraps its own Python via
uvand setsPYTHONHOMEin the process environment. When the terminal tool spawns subprocesses, thisPYTHONHOMEis inherited, causingconda(and potentially other Python-based tools) to loaduv's Python instead of the system/conda Python — resulting inNo module named conda.Fix
Strip
PYTHONHOMEandPYTHONPATHfrom the subprocess environment in_make_run_env(). This mirrors theunset PYTHONHOME/unset PYTHONPATHlogic already present ininstall.shat launch time.Testing
After patching,
conda --versionreturnsconda 25.5.1correctly in the Hermes Agent terminal session on Windows.Checklist
scripts/install.shPython-path sanitization is already in place