Skip to content

fix(gateway): guard bare int/float(os.getenv) in platform configs - #48368

Closed
vanthinh6886 wants to merge 1 commit into
NousResearch:mainfrom
vanthinh6886:fix/guard-config-env-casts
Closed

fix(gateway): guard bare int/float(os.getenv) in platform configs#48368
vanthinh6886 wants to merge 1 commit into
NousResearch:mainfrom
vanthinh6886:fix/guard-config-env-casts

Conversation

@vanthinh6886

Copy link
Copy Markdown
Contributor

Summary

Bare int(os.getenv(...)) and float(os.getenv(...)) calls across gateway platform configs crash with ValueError when env vars contain non-numeric strings. Replace with env_int()/env_float() from utils.py which catch ValueError/TypeError and fall back to defaults.

Follow-up to PR #48365 which fixed the HERMES_MAX_ITERATIONS call sites. This PR covers the remaining platform-specific config vars.

Changes

  • gateway/config.py: WECOM_CALLBACK_PORT, BLUEBUBBLES_WEBHOOK_PORT
  • gateway/platforms/email.py: EMAIL_IMAP_PORT, EMAIL_SMTP_PORT, EMAIL_POLL_INTERVAL
  • gateway/platforms/feishu.py: 6 vars (dedup cache, batching delays, webhook port)
  • gateway/platforms/telegram.py: MEDIA_BATCH_DELAY_SECONDS, WEBHOOK_PORT
  • gateway/platforms/wecom.py: TEXT_BATCH_DELAY_SECONDS, TEXT_BATCH_SPLIT_DELAY_SECONDS

Test Plan

  • python -c "from utils import env_int, env_float" imports OK
  • All modified files pass lint check
  • env_int/env_float return defaults for invalid/missing values

Bare int(os.getenv) and float(os.getenv) calls crash the gateway with
ValueError when env vars contain non-numeric strings. Replace with
env_int()/env_float() from utils.py which catch ValueError/TypeError
and fall back to defaults.

Affected modules:
- gateway/config.py: WECOM_CALLBACK_PORT, BLUEBUBBLES_WEBHOOK_PORT
- gateway/platforms/email.py: EMAIL_IMAP_PORT, EMAIL_SMTP_PORT, EMAIL_POLL_INTERVAL
- gateway/platforms/feishu.py: 6 config vars (dedup, batching, webhook)
- gateway/platforms/telegram.py: MEDIA_BATCH_DELAY, WEBHOOK_PORT
- gateway/platforms/wecom.py: TEXT_BATCH_DELAY, TEXT_BATCH_SPLIT_DELAY
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have duplicate This issue or pull request already exists labels Jun 18, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #39113 — that PR (open) already guards every one of these platform-config call sites (gateway/config.py, email.py, feishu.py, telegram.py, wecom.py) with env_int/env_float, using the same mechanism. Follow-up to #48365; both are subsets of the comprehensive #39113.

@alaamohanad169-ship-it

Copy link
Copy Markdown
Contributor

Note: This is NOT a duplicate of the prior closed PRs (#39113, #48365, #39113). 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.

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Closing as superseded by #49558, which landed the canonical fix for this whole bug class.

#49558 adds env_float() alongside the existing env_int() in utils.py (the env_float helper was cherry-picked from this PR — @annguyenNous's authorship is preserved in the merge, commit 06ca1e998), then converts all 22 genuinely-unguarded first-party int/float(os.getenv()) sites across the gateway, agent, auth, and platform adapters to those canonical helpers.

We went with the utils.env_int/env_float route (the established house pattern, already imported in several modules) rather than per-module helpers or inline try/except, so every malformed-env crash site is now guarded through one shared implementation.

Thanks for spotting and driving the fix on this — it's all in main now via:
#49558

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants