hermes - ✅(Solved) Fix [Bug] Intermittent cron failure: ModuleNotFoundError: No module named 'openai' (Python interpreter mismatch) [1 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#11610Fetched 2026-04-18 05:59:53
View on GitHub
Comments
3
Participants
3
Timeline
5
Reactions
0
Timeline (top)
commented ×3cross-referenced ×1referenced ×1

Error Message

Some cron jobs fail before task logic starts with the error: If preflight fails, stop with a clear fail-fast error message instead of partial execution. Representative error:

Root Cause

Root Cause Analysis The scheduler imports the agent entrypoint, and the agent path imports openai at module import time. If cron is launched with a non-venv interpreter, import fails immediately. So the failure is not specific to a single cron prompt; it is a runtime interpreter consistency problem.

Fix Action

Fixed

PR fix notes

PR #11869: fix(cron): preflight import check with clear error on interpreter mismatch (#11610)

Description (problem / solution / changelog)

Summary

  • run_job() called from run_agent import AIAgent without any guard
  • run_agent imports openai (and other third-party libs) at module level
  • When cron runs under a Python interpreter without the Hermes venv (e.g. system Python wired via crontab), the job fails immediately with a cryptic ModuleNotFoundError: No module named 'openai'
  • Wrap the import in try/except ImportError, log sys.executable, return a structured failure with an actionable message pointing the operator to the venv

Test plan

  • Normal gateway-embedded cron: import succeeds, no behavioural change
  • Simulate misconfigured Python: python3 -c "import sys; sys.modules['openai'] = None" — import fails → run_job returns (False, "", "", "Cannot load Hermes agent module: ...")
  • Error message includes sys.executable so the operator can see which Python was used

Tested on v0.10.0 (sha256:9f37fa3ff8d8d83ab9e1b529b1373c598c377b61ecdb90e26c3d310bf04f5904).

Closes #11610

🤖 Generated with Claude Code

Changed files

  • cli.py (modified, +30/-11)
  • cron/scheduler.py (modified, +19/-2)
RAW_BUFFERClick to expand / collapse

Bug Description Some cron jobs fail before task logic starts with the error: ModuleNotFoundError: No module named 'openai'. This is intermittent and depends on which Python interpreter is used at runtime.

Expected Behavior Cron execution should be deterministic and always use the same Python environment as Hermes runtime, so imports are stable.

Actual Behavior In some execution paths, cron starts with a Python interpreter that does not have the openai package, causing an early import failure before the job workflow can run.

Steps to Reproduce

  1. Trigger a cron job that goes through scheduler -> agent initialization.
  2. Use an execution path that resolves to a different Python interpreter than the Hermes venv.
  3. Observe early failure with: ModuleNotFoundError: No module named 'openai'.
  4. Run the same job through a venv-pinned execution path and observe success.

Root Cause Analysis The scheduler imports the agent entrypoint, and the agent path imports openai at module import time. If cron is launched with a non-venv interpreter, import fails immediately. So the failure is not specific to a single cron prompt; it is a runtime interpreter consistency problem.

Proposed Fix Standardize cron execution to a single, venv-pinned Python runtime. Add a lightweight preflight import check (import openai) before cron execution. If preflight fails, stop with a clear fail-fast error message instead of partial execution. Document this as a known pitfall: system Python vs venv Python mismatch in cron/systemd contexts.

Affected Component Cron/Scheduler, Agent initialization, Runtime configuration.

Environment OS: Linux Python: 3.13 Hermes: current stable Deployment style: local runtime with scheduled cron jobs

Additional Logs Representative error: ModuleNotFoundError: No module named 'openai'

Security / Privacy Note All sensitive identifiers were removed. No tokens, personal paths, hostnames, or private account details are included.

extent analysis

TL;DR

Standardize cron execution to a single, venv-pinned Python runtime to resolve the ModuleNotFoundError issue.

Guidance

  • Verify that the openai package is installed in the virtual environment (venv) used by the Hermes runtime.
  • Update the cron job configuration to ensure it uses the same venv-pinned Python interpreter as the Hermes runtime.
  • Consider adding a preflight import check for the openai module before cron execution to catch any potential issues early.
  • Review the agent initialization code to ensure it imports the openai module only when necessary, to minimize the impact of import failures.

Example

No code snippet is provided as the issue is more related to configuration and environment setup.

Notes

The proposed fix relies on standardizing the Python runtime for cron execution, which may require updates to the system configuration or the cron job scripts. Additionally, the preflight import check should be designed to provide clear error messages to facilitate debugging.

Recommendation

Apply the workaround by standardizing the cron execution to a single, venv-pinned Python runtime, as this approach addresses the root cause of the issue and provides a clear path to resolving the ModuleNotFoundError.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix [Bug] Intermittent cron failure: ModuleNotFoundError: No module named 'openai' (Python interpreter mismatch) [1 pull requests, 3 comments, 3 participants]