fix(env): guard float()/int() casts on env vars in gateway and plugins (20 locations) - #41646
Conversation
Non-numeric values in env vars like HERMES_API_TIMEOUT, HERMES_STREAM_READ_TIMEOUT, HERMES_STREAM_STALE_TIMEOUT, HERMES_MAX_ITERATIONS, EMAIL_IMAP_PORT, etc. raised ValueError at init and crashed startup. Parse them safely, falling back to defaults. - agent/chat_completion_helpers.py: replace 3 bare float(os.getenv()) with the existing _env_float() helper (Pitfall 30) - gateway/run.py: replace 2 bare int(os.getenv()) with utils.env_int() - gateway/platforms/email.py: guard 3 int() casts with try/except - gateway/platforms/telegram.py: use existing _env_float_clamped() - gateway/platforms/wecom.py: guard 2 float() casts with try/except - gateway/platforms/feishu.py: add local _safe_int/_safe_float helpers, replace 6 bare casts - gateway/platforms/api_server.py: guard 1 int() cast with try/except - plugins/platforms/discord/adapter.py: guard 2 float() casts Follow-up to NousResearch#40598 which covered core/hermes_cli/tools modules.
Code Review — Positive VerificationReviewed the full diff (215 lines across 6 files: Correctness:
Scope:
Risk assessment: Pure defensive change — no behavioral difference for correctly-set env vars. Prevents |
|
Closing as superseded by #49558, which landed the canonical fix for this whole bug class. #49558 adds We went with the Thanks for spotting and driving the fix on this — it's all in main now via: |
Bug
Non-numeric values in env vars like
HERMES_API_TIMEOUT,HERMES_STREAM_READ_TIMEOUT,HERMES_STREAM_STALE_TIMEOUT,HERMES_MAX_ITERATIONS,EMAIL_IMAP_PORT,EMAIL_SMTP_PORT,EMAIL_POLL_INTERVAL,HERMES_TELEGRAM_MEDIA_BATCH_DELAY_SECONDS,HERMES_WECOM_TEXT_BATCH_DELAY_SECONDS,HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS, and Feishu batch settings raisedValueErrorat init and crashed startup.A user setting
HERMES_API_TIMEOUT=abcin their.envwould crash the entire agent.Fix
Guard all
float()/int()casts on env vars with try/except or existing safe helpers:agent/chat_completion_helpers.pyfloat()_env_float()helper (Pitfall 30 — file had the helper but didn't use it)gateway/run.pyint()utils.env_int()gateway/platforms/email.pyint()gateway/platforms/telegram.pyfloat()_env_float_clamped()gateway/platforms/wecom.pyfloat()gateway/platforms/feishu.pyint()+ 3float()_safe_int/_safe_floathelpersgateway/platforms/api_server.pyint()plugins/platforms/discord/adapter.pyfloat()Total: 20 locations across 8 files.
Follow-up
Extends #40598 which covered core/hermes_cli/tools modules. This PR covers
gateway/andplugins/directories that were missed.