fix: guard int()/float() env var casts and unguarded flock(LOCK_UN) - #35871
Open
annguyenNous wants to merge 1 commit into
Open
fix: guard int()/float() env var casts and unguarded flock(LOCK_UN)#35871annguyenNous wants to merge 1 commit into
annguyenNous wants to merge 1 commit into
Conversation
Three categories of defensive-coding fixes across 9 files:
1. int()/float() env var casts without ValueError guard (6 files):
- plugins/platforms/irc/adapter.py: IRC_PORT
- plugins/platforms/discord/adapter.py: HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS,
HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDS
- plugins/platforms/google_chat/adapter.py: GOOGLE_CHAT_MAX_MESSAGES,
GOOGLE_CHAT_MAX_BYTES
- plugins/browser/firecrawl/provider.py: FIRECRAWL_BROWSER_TTL
- tools/browser_tool.py: BROWSER_INACTIVITY_TIMEOUT
- tools/checkpoint_manager.py: HERMES_CHECKPOINT_TIMEOUT
A non-numeric env var (e.g. typo) crashes the entire gateway on startup.
Wrap each in try/except (ValueError, TypeError) with the default as fallback.
This follows the established pattern from prior PRs NousResearch#29304 and NousResearch#32458 which
fixed the same pattern in core files but missed these plugin/tool locations.
2. Unguarded fcntl.flock(LOCK_UN) in hermes_cli/kanban_db.py:
If flock raises OSError (e.g. EBADF), the exception propagates past the
try/finally, potentially crashing the caller. Add try/except OSError: pass
around the unlock call, matching the pattern in all other flock locations.
3. logging.basicConfig() in library __init__ (2 files):
- trajectory_compressor.py
- mini_swe_runner.py
basicConfig() hijacks the root logger config. If these classes are
instantiated before the main app configures logging, it overrides
everything. Remove basicConfig(), keep getLogger(__name__).
The entry point (cli.py, gateway) is responsible for root logger config.
Collaborator
Contributor
|
Thanks for the defensive cleanup work. Most of this PR is now superseded on current main, but the kanban release guard remains worth salvaging. Problems
Suggested changes
Automated hermes-sweeper review. |
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.
Summary
Three categories of defensive-coding fixes across 9 files:
1. int()/float() env var casts without ValueError guard (6 files)
plugins/platforms/irc/adapter.py:IRC_PORTplugins/platforms/discord/adapter.py:HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS,HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDSplugins/platforms/google_chat/adapter.py:GOOGLE_CHAT_MAX_MESSAGES,GOOGLE_CHAT_MAX_BYTESplugins/browser/firecrawl/provider.py:FIRECRAWL_BROWSER_TTLtools/browser_tool.py:BROWSER_INACTIVITY_TIMEOUTtools/checkpoint_manager.py:HERMES_CHECKPOINT_TIMEOUTA non-numeric env var (e.g. typo) crashes the entire gateway on startup. Each cast is wrapped in
try/except (ValueError, TypeError)with the default as fallback.This follows the established pattern from prior PRs #29304 and #32458 which fixed the same pattern in core files but missed these plugin/tool locations.
2. Unguarded
flock(LOCK_UN)inhermes_cli/kanban_db.pyIf
fcntl.flock()raisesOSError(e.g.EBADF), the exception propagates past thetry/finally, potentially crashing the caller. Addedtry/except OSError: passaround the unlock call, matching the pattern in all otherflocklocations (8 other files already have this guard).3.
logging.basicConfig()in library__init__(2 files)trajectory_compressor.pymini_swe_runner.pybasicConfig()hijacks the root logger config. If these classes are instantiated before the main app configures logging, it overrides everything. RemovedbasicConfig(), keptgetLogger(__name__). The entry point (cli.py, gateway) is responsible for root logger config.Testing
ast.parse()syntax validation