Skip to content

fix(agent/discord): use safe env-float helper consistently - #40938

Closed
annguyenNous wants to merge 1 commit into
NousResearch:mainfrom
annguyenNous:fix/use-env-float-helper-consistently
Closed

fix(agent/discord): use safe env-float helper consistently#40938
annguyenNous wants to merge 1 commit into
NousResearch:mainfrom
annguyenNous:fix/use-env-float-helper-consistently

Conversation

@annguyenNous

Copy link
Copy Markdown
Contributor

Bug

chat_completion_helpers.py already defines _env_float() (line 118) that guards against non-numeric env var values with a try/except (ValueError, TypeError) fallback. But 3 call sites in the same file still use bare float(os.getenv(...)):

  • HERMES_API_TIMEOUT (line 1683)
  • HERMES_STREAM_READ_TIMEOUT (line 1690)
  • HERMES_STREAM_STALE_TIMEOUT (line 2296)

Additionally, plugins/platforms/discord/adapter.py uses bare float(os.getenv()) for:

  • HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS (line 591)
  • HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDS (line 592)

A non-numeric value in any of these env vars crashes the agent or gateway with ValueError.

Fix

  • chat_completion_helpers.py: Replace 3 bare float(os.getenv(...)) calls with the existing _env_float() helper
  • discord/adapter.py: Add local _safe_float_env() helper and use it for the 2 calls

This is Pitfall 30 from the codebase patterns: "File has a safe helper but doesn't use it internally."

chat_completion_helpers.py already defines _env_float() (line 118) that
guards against non-numeric env var values, but 3 call sites still use
bare float(os.getenv(...)):
- HERMES_API_TIMEOUT (line 1683)
- HERMES_STREAM_READ_TIMEOUT (line 1690)
- HERMES_STREAM_STALE_TIMEOUT (line 2296)

Also: plugins/platforms/discord/adapter.py uses bare float(os.getenv())
for HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS and
HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDS without any guard.

A non-numeric value in any of these crashes the agent or gateway.
Fix by using _env_float() (chat_completion_helpers) or a local
_safe_float_env() helper (discord adapter).
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint platform/discord Discord bot adapter labels Jun 7, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for identifying the unguarded environment parsing cases.

Automated hermes-sweeper review found that the requested behavior is already on current main:

  • agent/chat_completion_helpers.py:2171, :2178, and :2998 use the shared safe utils.env_float helper.
  • plugins/platforms/discord/adapter.py:829-830 use that same helper for both Discord text-batching delay variables.
  • Commit a7dd98c8609c0d944e3c5dd0c5b9ee31dd99eb29 (fix(env): guard remaining malformed int/float env var casts with utils helpers) implemented these exact sites and is contained in current main.

Closing as implemented on main.

@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/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint 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.

3 participants