fix(gateway): guard yaml.safe_load and float() env var casts against crash - #17905
Merged
Merged
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.
Follow-up to the try/except guards added in the previous commit. Four sibling call sites all read HERMES_AGENT_TIMEOUT / HERMES_AGENT_TIMEOUT_WARNING / HERMES_AGENT_NOTIFY_INTERVAL via the same read-env-or-fallback pattern, so factor it into _float_env(name, default) alongside the existing _auto_continue_freshness_window() helper.
2 tasks
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.
Salvage of #17857 by @vominh1919 onto current main, with a small follow-up refactor.
Summary
Empty
--configYAML no longer crashes gateway startup; a typo inHERMES_AGENT_TIMEOUT/HERMES_AGENT_TIMEOUT_WARNING/HERMES_AGENT_NOTIFY_INTERVALno longer crashes the gateway or an agent turn.Changes
yaml.safe_load(f) or {}at the one site inmain()that was missing it (the other 6 sibling sites already have it). Wraps 4float(os.getenv(...))env-var casts intry/except (ValueError, TypeError)with fallback to the existing defaults._float_env(name, default)helper next to the existing_auto_continue_freshness_window()so all 4 call sites share one implementation. Also handles unset/empty consistently.Validation
touch /tmp/empty.yaml && hermes gateway --config /tmp/empty.yamlNone.getHERMES_AGENT_TIMEOUT=abc hermes gatewayHERMES_AGENT_TIMEOUT=""Helper tested against unset / empty / typo / valid-float / integer-string / whitespace inputs.
Closes #17857.