Skip to content

fix(tui_gateway): guard sys.path against local package shadowing#19885

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-8c54fd4a
May 4, 2026
Merged

fix(tui_gateway): guard sys.path against local package shadowing#19885
teknium1 merged 1 commit into
mainfrom
hermes/hermes-8c54fd4a

Conversation

@teknium1

@teknium1 teknium1 commented May 4, 2026

Copy link
Copy Markdown
Contributor

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

)

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>
@teknium1 teknium1 merged commit 60b143e into main May 4, 2026
8 of 10 checks passed
@teknium1 teknium1 deleted the hermes/hermes-8c54fd4a branch May 4, 2026 19:42
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels May 4, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI fails to launch when cwd contains a Python package named 'utils/'

3 participants