Skip to content

fix: guard float()/int() env var casts against non-numeric input - #35790

Closed
annguyenNous wants to merge 1 commit into
NousResearch:mainfrom
annguyenNous:fix/env-var-type-cast-guards
Closed

fix: guard float()/int() env var casts against non-numeric input#35790
annguyenNous wants to merge 1 commit into
NousResearch:mainfrom
annguyenNous:fix/env-var-type-cast-guards

Conversation

@annguyenNous

Copy link
Copy Markdown
Contributor

Fix: Guard float()/int() env var casts across 6 files

Multiple platform adapters and streaming helpers cast environment variables via float()/int() without try/except. Setting any of these env vars to a non-numeric string (e.g. "abc") causes an unhandled ValueError that crashes adapter initialization or the streaming code path.

Files changed

File Env var Type
agent/chat_completion_helpers.py HERMES_API_TIMEOUT, HERMES_STREAM_READ_TIMEOUT, HERMES_STREAM_RETRIES, HERMES_STREAM_STALE_TIMEOUT float/int
plugins/platforms/irc/adapter.py IRC_PORT int
plugins/platforms/google_chat/adapter.py GOOGLE_CHAT_MAX_MESSAGES, GOOGLE_CHAT_MAX_BYTES int
plugins/platforms/discord/adapter.py HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS, HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDS float
plugins/browser/firecrawl/provider.py FIRECRAWL_BROWSER_TTL int

Pattern

For chat_completion_helpers.py, the file already has a _env_float() helper — the 2 bare float() calls are now routed through it. For int() locations, inline try/except (ValueError, TypeError) with default fallback is used, matching the existing defensive pattern in send_message_tool.py, terminal_tool.py, and line/adapter.py.

Multiple platform adapters and the streaming helpers cast env vars
via float()/int() without try/except. A non-numeric env var value
(e.g. "abc") causes an unhandled ValueError that crashes the
adapter initialization or streaming code path.

Fixed locations:
- agent/chat_completion_helpers.py: 4 bare float()/int() calls
  replaced with _env_float() helper or inline try/except
- plugins/platforms/irc/adapter.py: IRC_PORT int() guard
- plugins/platforms/google_chat/adapter.py: 2 int() guards
- plugins/platforms/discord/adapter.py: 2 float() guards
- plugins/browser/firecrawl/provider.py: FIRECRAWL_BROWSER_TTL guard
@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 comp/plugins Plugin system and bundled plugins platform/discord Discord bot adapter labels May 31, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Overlaps with #30274 (same float(os.getenv()) guards in chat_completion_helpers.py). Also same class of fix as #35789 (browser_tool.py int() guard). Related to #17905 (merged, gateway float guards).

@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 — PR #35790

Verdict: Approved

Author: annguyenNous | Type: bugfix | Files: 5 files, 31 additions, 10 deletions

Findings

  • Correct defensive pattern: routes bare float() through existing _env_float() helper in chat_completion_helpers.py (2 calls), wraps int() in try/except (ValueError, TypeError) for remaining 4 files.
  • Covers 7 env variable casts across streaming helpers (HERMES_API_TIMEOUT, HERMES_STREAM_READ_TIMEOUT, HERMES_STREAM_RETRIES, HERMES_STREAM_STALE_TIMEOUT) and 4 platform adapters (Discord batch delays, Google Chat flow control, IRC port, Firecrawl browser TTL).
  • Matches existing pattern in send_message_tool.py, terminal_tool.py, line/adapter.py.
  • Non-numeric env vars now fall back to sensible defaults instead of crashing.

No issues found.


Reviewed by Hermes Agent

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the defensive coverage. This automated hermes-sweeper review found that current main already provides the requested malformed-environment fallback behavior.

  • utils.py:410-429 supplies shared env_int() / env_float() helpers that return defaults on ValueError or TypeError.
  • agent/chat_completion_helpers.py:2171,2178,2695,2998 uses those helpers for all four streaming variables in this PR.
  • plugins/platforms/discord/adapter.py:829-830, plugins/platforms/google_chat/adapter.py:543-550, plugins/platforms/irc/adapter.py:110-113, and plugins/browser/firecrawl/provider.py:81-84 already guard the remaining targets.
  • These implementations are present in d682f320b35a13084371a541a835e1d988c982b8, included in v2026.7.7.2.

The member comment noting overlap with #30274 is consistent with the shared implementation now on main.

@teknium1 teknium1 closed this Jul 13, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 13, 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 comp/plugins Plugin system and bundled plugins 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