Skip to content

fix(gateway): guard yaml.safe_load and float() env var casts against crash - #17857

Closed
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/gateway-yaml-and-envvar-guards
Closed

vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/gateway-yaml-and-envvar-guards

Conversation

@vominh1919

Copy link
Copy Markdown
Contributor

Summary

Two defensive fixes in gateway/run.py that prevent crashes from common misconfiguration:

Bug 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 yaml.safe_load() returns None. All 6 other yaml.safe_load call sites in the same file already use or {} — this one was missed.

Impact: Gateway fails to start with an empty --config file.

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 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: 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 in try/except (ValueError, TypeError) with fallback to the default value.

Changes

Line(s) Before After
12706 yaml.safe_load(f) yaml.safe_load(f) or {}
3951 float(os.getenv(...)) try/except with fallback to 1800.0
11757 float(os.getenv(...)) try/except with fallback to 180.0
11805 float(os.getenv(...)) try/except with fallback to 1800.0
11807 float(os.getenv(...)) try/except with fallback to 900.0

…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.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery labels Apr 30, 2026
@teknium1

Copy link
Copy Markdown
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 _float_env(name, default) helper so all 4 sites use one implementation alongside the existing _auto_continue_freshness_window helper. Thanks for the fix!

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

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants