fix(tools): strip PYTHONPATH from subprocess env to prevent leak (#74817) - #74951
fix(tools): strip PYTHONPATH from subprocess env to prevent leak (#74817)#74951webtecnica wants to merge 1 commit into
Conversation
…sResearch#74817) PYTHONPATH was missing from _ACTIVE_VENV_MARKER_VARS, causing Hermes' own site-packages path to leak into every terminal/code_execution subprocess. Added PYTHONPATH alongside existing VIRTUAL_ENV and CONDA_PREFIX. Fixes NousResearch#74817
teknium1
left a comment
There was a problem hiding this comment.
Thanks for isolating the current local-environment gap: tools/environments/local.py:349 still omits PYTHONPATH, and the three local builders consume that tuple at lines 493, 622, and 1263.
Problems
- Adding
PYTHONPATHto this global tuple drops every user-provided entry, not only Hermes-injected venv paths. The Nix wrapper deliberately appendsextraPythonPackagestoPYTHONPATHfor entry-point plugin discovery (nix/hermes-agent.nix:116-121,206-208). - This does not cover
execute_code: its scrubber explicitly permitsPYTHONPATH(tools/code_execution_tool.py:148-150) and the spawn path preserves it at lines 1399-1403. - No regression test accompanies the new behavior; current marker tests cover only
VIRTUAL_ENVandCONDA_PREFIX(tests/tools/test_local_env_blocklist.py:268-314).
Suggested changes
- Filter only Hermes-injected incompatible site-packages entries, preserving unrelated
PYTHONPATHentries, and apply that policy to the execute_code child environment as well. - Add behavioral coverage for all affected environment builders, including preservation of a user path.
Automated hermes-sweeper review.
| # Hermes venv stays reachable via PATH (its bin dir is first), so stripping | ||
| # these markers is safe and only prevents the cross-project clobber (#23473). | ||
| _ACTIVE_VENV_MARKER_VARS = ("VIRTUAL_ENV", "CONDA_PREFIX") | ||
| _ACTIVE_VENV_MARKER_VARS = ("VIRTUAL_ENV", "CONDA_PREFIX", "PYTHONPATH") |
There was a problem hiding this comment.
This removes all PYTHONPATH entries, including user/package-manager paths. execute_code intentionally allows PYTHONPATH (tools/code_execution_tool.py:148-150), and the Nix wrapper appends it for extraPythonPackages plugin discovery (nix/hermes-agent.nix:116-121, 206-208). Please filter only Hermes-injected incompatible site-packages entries and cover the separate execute_code path.
SummaryTwo PRs address #74817: #74951 is an isolated one-line blanket Related pull requests
Duplicates#74871 and #74951 duplicate the same core blanket Suggested consolidationKeep #74951 open with a salvage path: replace blanket removal with filtering of only Hermes-injected incompatible paths, preserve unrelated user/Nix Complex graphflowchart LR
classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
classDef best stroke-width:3px,stroke:#b45309
classDef target stroke-width:3px,stroke:#4338ca
I74817(["issue #74817 (open)"])
subgraph Dup74871 ["PRs duplicating each other"]
P74871["PR #74871 (open)"]
P74951["PR #74951 (open)"]
end
P74951 -->|best fix| I74817
class I74817 open
class P74871 open
class P74951 open
class P74871 best
class P74951 best
class P74951 target
click I74817 "https://github.com/NousResearch/hermes-agent/issues/74817"
click P74871 "https://github.com/NousResearch/hermes-agent/pull/74871"
click P74951 "https://github.com/NousResearch/hermes-agent/pull/74951"
Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed (state tag in the node label). Cross-PR triage: Reviewed 2 pull requests and 1 issue in this complex. Each diff was read against this issue; Assessment working set: 44 kB of PR diffs, 7 kB of issue/PR text, 9 kB of discussion (9 comments), 6 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch. |
|
Thanks for the report and the fix @webtecnica. The underlying leak is now fixed on main via #88182, which took the selective-filtering approach (strip only Hermes-owned entries: cross-version site-packages, the Hermes venv's own site-packages, and the repo root) rather than a blanket |
Fixes #74817 — added PYTHONPATH to _ACTIVE_VENV_MARKER_VARS in tools/environments/local.py. Covers all 3 spawn paths.