fix: resolve pip packages from site-packages instead of agent dir - #76
Conversation
When `pip install --target .` is run inside the hermes-agent checkout, third-party package directories (openai/, pydantic/, requests/, etc.) end up alongside real Hermes source files. With the agent dir at the front of sys.path (insert(0)), Python resolves imports from those local directories, breaking whenever the host platform differs from the container (e.g. macOS .so files inside a Linux image). Fix: append agent dir to sys.path instead of prepending. This lets site-packages resolve pip packages correctly while still allowing Hermes-specific modules (run_agent, hermes/, etc.) to resolve since they do not exist in site-packages. Also improves verify_hermes_imports() to surface the actual exception message in startup logs, making it much easier to diagnose why a module failed to import.
|
Thanks for this fix, @vCillusion — this is a real bug and the solution is correct. What the fix does:
The One thing to confirm: Otherwise this looks clean and ready to go. Changes are minimal, focused, and well-commented. |
nesquena
left a comment
There was a problem hiding this comment.
Review: PR #76 — fix sys.path ordering for pip-installed packages
Security Audit
Clean. Python-only changes, no external resources, no injection vectors. The except Exception broadening is scoped to error message capture only.
Code Review
The fix is correct — sys.path.insert(0) was causing agent-dir packages (openai/, pydantic/) to shadow system site-packages, breaking cross-platform containers. sys.path.append() resolves hermes-specific modules (run_agent, hermes/) just fine since they don't exist in site-packages.
Confirmed: verify_hermes_imports() has only one caller (server.py:64), which the PR updates to unpack the 3-tuple. No breakage.
The error message improvement is a welcome bonus — showing the actual exception (e.g. .so ABI mismatch) instead of just the module name will save real debugging time.
Tests
401 passed, 23 failed — no regressions. All 23 are pre-existing.
Verdict
Small, focused, well-commented fix for a real bug. Approved.
fix: resolve pip packages from site-packages instead of agent dir
fix: resolve pip packages from site-packages instead of agent dir
fix: resolve pip packages from site-packages instead of agent dir
When
pip install --target .is run inside the hermes-agent checkout, third-party package directories (openai/, pydantic/, requests/, etc.) end up alongside real Hermes source files. With the agent dir at the front of sys.path (insert(0)), Python resolves imports from those local directories, breaking whenever the host platform differs from the container (e.g. macOS .so files inside a Linux image).Fix: append agent dir to sys.path instead of prepending. This lets site-packages resolve pip packages correctly while still allowing Hermes-specific modules (run_agent, hermes/, etc.) to resolve since they do not exist in site-packages.
Also improves verify_hermes_imports() to surface the actual exception message in startup logs, making it much easier to diagnose why a module failed to import.