fix(tui_gateway): guard sys.path against local package shadowing#19885
Merged
Conversation
) When the TUI backend (tui_gateway/entry.py) is spawned by Node.js with the user's CWD containing a local utils/ directory, that directory shadows the installed utils module, causing ImportError in run_agent and hermes_cli. Strip '' and '.' from sys.path and prepend HERMES_PYTHON_SRC_ROOT (already set by hermes_cli before spawning the subprocess) so installed packages always win over CWD artifacts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
8 tasks
m4dni5
added a commit
to m4dni5/hermes-agent
that referenced
this pull request
Jun 10, 2026
Extends NousResearch#15989 / NousResearch#19885 — the existing guard in tui_gateway/entry.py strips '' and '.' from sys.path, but virtualenv .pth hooks in editable installs may resolve '' to the absolute CWD path before user code runs. A tools.py or utils.py in the working directory still shadows the Hermes package because the absolute path passes through the '' filter. Fix: strip os.getcwd() alongside '' and '.' in both hermes_cli/main.py (new guard) and tui_gateway/entry.py (upgraded guard). Re-insert the project root / src_root after stripping so CWD == repo root doesn't collaterally remove the project root from sys.path. Tests: updated test_entry_sys_path.py, new test_cwd_shadowing.py.
m4dni5
added a commit
to m4dni5/hermes-agent
that referenced
this pull request
Jun 10, 2026
Extends NousResearch#15989 / NousResearch#19885 — the existing guard in tui_gateway/entry.py strips '' and '.' from sys.path, but virtualenv .pth hooks in editable installs may resolve '' to the absolute CWD path before user code runs. A tools.py or utils.py in the working directory still shadows the Hermes package because the absolute path passes through the '' filter. Fix: strip os.getcwd() alongside '' and '.' in both hermes_cli/main.py (new guard) and tui_gateway/entry.py (upgraded guard). Re-insert the project root / src_root after stripping so CWD == repo root doesn't collaterally remove the project root from sys.path. Tests: updated test_entry_sys_path.py, new test_cwd_shadowing.py.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Salvage of #16141 onto current main.
Summary
When hermes is run from a directory containing a local utils/ subdirectory, the TUI fails to launch because tui_gateway/entry.py imports utils.* and Python's sys.path insertion of '' / '.' causes the local dir to shadow the installed module. Strip '' and '.' from sys.path in entry.py before any non-stdlib import resolves. Fixes #15989.
Validation
scripts/run_tests.sh tests/tui_gateway/test_entry_sys_path.py -> passed
Original PR: #16141