fix(gateway): guard yaml.safe_load and float() env var casts against crash - #17857
Closed
vominh1919 wants to merge 1 commit into
Closed
vominh1919 wants to merge 1 commit into
vominh1919 wants to merge 1 commit into
Conversation
…crash
Two defensive fixes in gateway/run.py:
1. yaml.safe_load returning None on empty config files (line 12706):
GatewayConfig.from_dict(data) crashes with AttributeError when the YAML
file is empty because safe_load returns None. All 6 other yaml.safe_load
call sites already use `or {}` — this one was missed.
Impact: gateway fails to start with empty --config file.
2. float() on env vars without ValueError guard (lines 3951, 11757, 11805,
11807): HERMES_AGENT_TIMEOUT, HERMES_AGENT_TIMEOUT_WARNING, and
HERMES_AGENT_NOTIFY_INTERVAL are cast via float() directly from
os.getenv(). A typo (e.g. "abc") raises ValueError and crashes the
agent turn or gateway startup.
Impact: single misconfigured env var crashes the entire gateway.
Collaborator
|
Merged via #17905 (#17905). Your commit was cherry-picked onto current main with your authorship preserved — it's now commit ca87c82 on main. Added a small follow-up commit that extracts a shared |
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
Two defensive fixes in
gateway/run.pythat prevent crashes from common misconfiguration:Bug 1:
yaml.safe_loadreturningNoneon empty config files (line 12706)GatewayConfig.from_dict(data)crashes withAttributeErrorwhen the YAML file is empty becauseyaml.safe_load()returnsNone. All 6 otheryaml.safe_loadcall sites in the same file already useor {}— this one was missed.Impact: Gateway fails to start with an empty
--configfile.Reproduction:
touch /tmp/empty.yaml hermes gateway --config /tmp/empty.yaml # → AttributeError: 'NoneType' object has no attribute 'get'Fix:
yaml.safe_load(f) or {}Bug 2:
float()on env vars withoutValueErrorguard (lines 3951, 11757, 11805, 11807)HERMES_AGENT_TIMEOUT,HERMES_AGENT_TIMEOUT_WARNING, andHERMES_AGENT_NOTIFY_INTERVALare cast viafloat()directly fromos.getenv(). A typo (e.g."abc") raisesValueErrorand crashes the agent turn or gateway startup.Impact: A single misconfigured env var crashes the entire gateway.
Reproduction:
HERMES_AGENT_TIMEOUT=abc hermes gateway # → ValueError: could not convert string to float: 'abc'Fix: Wrap each
float()call intry/except (ValueError, TypeError)with fallback to the default value.Changes
yaml.safe_load(f)yaml.safe_load(f) or {}float(os.getenv(...))try/exceptwith fallback to1800.0float(os.getenv(...))try/exceptwith fallback to180.0float(os.getenv(...))try/exceptwith fallback to1800.0float(os.getenv(...))try/exceptwith fallback to900.0