fix: add missing openai and httpx to requirements.txt#1383
fix: add missing openai and httpx to requirements.txt#1383wali-reheman wants to merge 1 commit intonesquena:masterfrom
Conversation
Hermes WebUI's streaming module calls into hermes-agent's AIAgent, which uses 'from openai import APIError' in exception handlers. When hermes-agent raises an anthropic.APIError (e.g. context window overflow), the handler attempts to import openai.APIError to check for SSE-specific retryable errors. If the WebUI's venv lacks the openai package, this import raises ModuleNotFoundError as an unhandled exception in a daemon thread. The orphaned thread exits while holding the global _ENV_LOCK, causing all subsequent HTTP requests to hang indefinitely on that lock. Adding openai>=1.0 to requirements.txt ensures the venv has the package, so the import succeeds and the exception handler completes normally, releasing _ENV_LOCK. htpx is added as a peer dependency of openai and is also imported directly by the WebUI streaming code.
|
Thanks for the careful root-cause analysis in the PR body — the daemon-thread holding That said, I'm holding this PR (and labeling The The WebUI's The WebUI server itself doesn't import Where the fix belongs The real bug is in hermes-agent: the exception handler does an unguarded import that throws # Option A — guard the import
try:
from openai import APIError as _APIError
except ImportError:
_APIError = None
if _APIError is not None and isinstance(e, _APIError) and not getattr(e, "status_code", None):
...# Option B — release the lock unconditionally
try:
# ... existing handler body, including the openai import ...
except Exception:
logger.exception("error handler crashed")
finally:
# ensure _ENV_LOCK is released even if the handler raisesOption A is the minimal correct fix — it eliminates the What I'd like in a follow-up PR Either:
Closing thought: the bug analysis is great and I want to land the underlying fix. Just from the right side. Tag me on the agent-side PR (or open an issue here referencing the agent file/line) and I'll help push it through. |
Cross-reference: fix landed in hermes-agentThe root-cause fix (Option A -- try/except guard on the openai import) has been landed in hermes-agent: NousResearch/hermes-agent#18247 Two sites in This eliminates the This supersedes the requirements.txt workaround in this PR. Recommend closing #1383 as superseded -- the fix belongs in hermes-agent, not in the WebUI's minimal requirements contract. |
Summary
When the WebUI's Python venv lacks the
openaipackage, running a chat that hits an API error causes the server to hang indefinitely.Root Cause
api/streaming.pydelegates chat execution tohermes-agent'sAIAgent. WhenAIAgentraises ananthropic.BadRequestError(e.g. "context window exceeds limit"), its internal exception handler tries to importopenai.APIError:If
openaiis not installed in the WebUI's venv, thisimportraisesModuleNotFoundErroras an unhandled exception inside a daemon thread. The orphaned thread exits while holding the global_ENV_LOCK(athreading.Lockinapi/streaming.py). All subsequent HTTP requests block forever waiting for that lock.Fix
Add
openai>=1.0andhttpx>=0.25torequirements.txt. Both packages are already imported by the WebUI streaming code or its dependency chain; they just weren't declared.Testing
openaipip install openai httpx), restart serverRelated
hermes-agentissue:from openai import APIErrorin exception handler is not guarded by a try/except, so anyModuleNotFoundErrorpropagates unhandled