fix: guard int/float env var casts against invalid values - #48298
fix: guard int/float env var casts against invalid values#48298vanthinh6886 wants to merge 1 commit into
Conversation
Multiple gateway files cast os.getenv() results directly with int() or float() without try/except. If a user sets an invalid value (e.g. HERMES_MAX_ITERATIONS=abc), the gateway crashes with ValueError on startup or message handling. Changes: - utils.py: Add env_float() companion to existing env_int() - gateway/run.py: Use env_int() for HERMES_MAX_ITERATIONS (2 sites) - gateway/platforms/feishu.py: Use env_int()/env_float() for 5 Feishu config env vars - gateway/platforms/api_server.py: Wrap HERMES_MAX_ITERATIONS in try/except (api_server does not import utils) The telegram.py and chat_completion_helpers.py modules already have their own _env_int/_env_float helpers — those are left as-is to avoid touching unrelated files in this PR.
|
Related: #39113 (guards float()/int() env casts across 27 files / 52 locations) and #41646 (gateway+plugins, 20 locations) both already cover the gateway env-cast guards in this PR (gateway/run.py, gateway/platforms/feishu.py, gateway/platforms/api_server.py) using the same |
|
Note: This is NOT a duplicate of the prior closed PRs (#39113, #41646). The earlier PRs were closed because they were stale (far behind upstream main). This version has been cherry-picked onto the latest origin/main with a clean diff containing only the fix changes. No conflicts. CI green. Ready for review. |
|
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: |
Summary
Multiple gateway files cast
os.getenv()results directly withint()orfloat()without try/except. If a user sets an invalid value (e.g.HERMES_MAX_ITERATIONS=abc), the gateway crashes withValueErroron startup or message handling.Fix
utils.py: Addenv_float()companion to existingenv_int()— both catchValueError/TypeErrorand return the default.gateway/run.py: Useenv_int()forHERMES_MAX_ITERATIONSat 2 call sites.gateway/platforms/feishu.py: Useenv_int()/env_float()for 5 Feishu config env vars.gateway/platforms/api_server.py: WrapHERMES_MAX_ITERATIONSin try/except (api_server does not import utils).Changes
Existing
_env_int/_env_floathelpers intelegram.pyandchat_completion_helpers.pyare left as-is to keep this PR focused.