fix(env): guard int() casts on env vars against ValueError#40427
Closed
annguyenNous wants to merge 1 commit into
Closed
fix(env): guard int() casts on env vars against ValueError#40427annguyenNous wants to merge 1 commit into
annguyenNous wants to merge 1 commit into
Conversation
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
Contributor
|
Salvaged into #40598 with credit. Kept your fix but unified it onto the existing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
int(os.getenv('VAR', 'default'))crashes withValueErrorwhen 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 unprotectedint()on env var locations found via codebase-wide grep.Files fixed (8)
agent/chat_completion_helpers.pyHERMES_STREAM_RETRIES(+ new_env_inthelper)plugins/platforms/irc/adapter.pyIRC_PORTplugins/platforms/google_chat/adapter.pyGOOGLE_CHAT_MAX_MESSAGES,GOOGLE_CHAT_MAX_BYTESplugins/browser/firecrawl/provider.pyFIRECRAWL_BROWSER_TTLhermes_cli/kanban_specify.pyHERMES_KANBAN_SPECIFY_MAX_TOKENS(+ new_safe_int_env)hermes_cli/runtime_provider.pyHERMES_NOUS_MIN_KEY_TTL_SECONDSx2 (+ new_safe_int_env)tools/browser_tool.pyBROWSER_INACTIVITY_TIMEOUTtools/checkpoint_manager.pyHERMES_CHECKPOINT_TIMEOUTTesting
All 8 files pass
python3 -m py_compile.