Skip to content

fix(env): guard int() casts on env vars against ValueError#40427

Closed
annguyenNous wants to merge 1 commit into
NousResearch:mainfrom
annguyenNous:fix/int-env-var-valueerror-guard
Closed

fix(env): guard int() casts on env vars against ValueError#40427
annguyenNous wants to merge 1 commit into
NousResearch:mainfrom
annguyenNous:fix/int-env-var-valueerror-guard

Conversation

@annguyenNous

Copy link
Copy Markdown
Contributor

Bug

int(os.getenv('VAR', 'default')) crashes with ValueError when the env var is set to a non-numeric string (e.g. HERMES_STREAM_RETRIES=abc). A typo in any env var crashes the entire component.

Fix

Added try/except (ValueError, TypeError) guards or _safe_int_env() / _env_int() helpers to all unprotected int() on env var locations found via codebase-wide grep.

Files fixed (8)

File Env var(s)
agent/chat_completion_helpers.py HERMES_STREAM_RETRIES (+ new _env_int helper)
plugins/platforms/irc/adapter.py IRC_PORT
plugins/platforms/google_chat/adapter.py GOOGLE_CHAT_MAX_MESSAGES, GOOGLE_CHAT_MAX_BYTES
plugins/browser/firecrawl/provider.py FIRECRAWL_BROWSER_TTL
hermes_cli/kanban_specify.py HERMES_KANBAN_SPECIFY_MAX_TOKENS (+ new _safe_int_env)
hermes_cli/runtime_provider.py HERMES_NOUS_MIN_KEY_TTL_SECONDS x2 (+ new _safe_int_env)
tools/browser_tool.py BROWSER_INACTIVITY_TIMEOUT
tools/checkpoint_manager.py HERMES_CHECKPOINT_TIMEOUT

Testing

All 8 files pass python3 -m py_compile.

int(os.getenv('VAR', 'default')) crashes when the env var is set to a
non-numeric string (e.g. HERMES_STREAM_RETRIES=abc). Added try/except
guards or _safe_int_env() helpers to all unprotected locations.

Files fixed:
- agent/chat_completion_helpers.py: added _env_int helper, used for
  HERMES_STREAM_RETRIES
- plugins/platforms/irc/adapter.py: IRC_PORT
- plugins/platforms/google_chat/adapter.py: GOOGLE_CHAT_MAX_MESSAGES,
  GOOGLE_CHAT_MAX_BYTES
- plugins/browser/firecrawl/provider.py: FIRECRAWL_BROWSER_TTL
- hermes_cli/kanban_specify.py: HERMES_KANBAN_SPECIFY_MAX_TOKENS
- hermes_cli/runtime_provider.py: HERMES_NOUS_MIN_KEY_TTL_SECONDS (x2)
- tools/browser_tool.py: BROWSER_INACTIVITY_TIMEOUT
- tools/checkpoint_manager.py: HERMES_CHECKPOINT_TIMEOUT
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent loop, run_agent.py, prompt builder comp/cli CLI entry point, hermes_cli/, setup wizard labels Jun 6, 2026
@teknium1

teknium1 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Salvaged into #40598 with credit. Kept your fix but unified it onto the existing utils.env_int helper (utils.py:289) instead of the three duplicate local helpers — plugins keep minimal inline guards since they don't import core utils. All your hardened sites covered, wrappers preserved. Thanks!

#40598

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

Labels

comp/agent Core agent loop, run_agent.py, prompt builder comp/cli CLI entry point, hermes_cli/, setup wizard 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.

3 participants