Skip to content

fix: guard float() env var casts in Discord adapter __init__ - #45514

Closed
annguyenNous wants to merge 1 commit into
NousResearch:mainfrom
annguyenNous:fix/unsafe-env-float-discord-adapter
Closed

fix: guard float() env var casts in Discord adapter __init__#45514
annguyenNous wants to merge 1 commit into
NousResearch:mainfrom
annguyenNous:fix/unsafe-env-float-discord-adapter

Conversation

@annguyenNous

Copy link
Copy Markdown
Contributor

Bug

Two env var casts in plugins/platforms/discord/adapter.py __init__ use raw float(os.getenv(...)) without try/except:

  • HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS (line 631)
  • HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDS (line 632)

If either env var is set to a non-numeric value, the entire Discord adapter fails to initialize — preventing Discord from working at all.

Other platform adapters (e.g. google_chat) already guard these with try/except (ValueError, TypeError).

Fix

Wrap both casts in try/except (ValueError, TypeError) with appropriate defaults (0.6 and 2.0).

Test Plan

  • py_compile passes
  • HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS=abc falls back to 0.6

Two env var casts in Discord adapter __init__ use raw float() without
try/except. If HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS or
HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDS is set to a non-numeric
value, the entire Discord adapter fails to initialize.

Other platform adapters (google_chat) already guard these with
try/except (ValueError, TypeError). This applies the same pattern.
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins platform/discord Discord bot adapter duplicate This issue or pull request already exists labels Jun 13, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #40938 — the HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS / _SPLIT_DELAY_SECONDS guards in plugins/platforms/discord/adapter.py are exactly the Discord-adapter sites already covered by open PR #40938 (and #35790).

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Same float() env var guard pattern applied to the Discord adapter OAuth refresh timeout. Trivial fix.


Reviewed by Hermes Agent (cron batch)

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused defensive fix. This is already implemented on current main via the shared helper, so this PR is redundant.

  • Automated hermes-sweeper review verified plugins/platforms/discord/adapter.py:829-830 now uses env_float for both reported Discord batch-delay variables, with defaults 0.6 and 2.0.
  • utils.py:421-429 catches ValueError and TypeError and returns the supplied fallback.
  • Commit a7dd98c8609c0d944e3c5dd0c5b9ee31dd99eb29 (fix(env): guard remaining malformed int/float env var casts with utils helpers) made this exact Discord change and is contained in release v2026.7.1.
  • The earlier duplicate discussion linking fix(agent/discord): use safe env-float helper consistently #40938 and fix: guard float()/int() env var casts against non-numeric input #35790 correctly identified the same bug class.

@teknium1 teknium1 closed this Jul 14, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have platform/discord Discord bot adapter sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants