Skip to content

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

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-0f6075f9
Apr 30, 2026
Merged

teknium1 merged 2 commits into
mainfrom
hermes/hermes-0f6075f9

Conversation

@teknium1

Copy link
Copy Markdown
Collaborator

Salvage of #17857 by @vominh1919 onto current main, with a small follow-up refactor.

Summary

Empty --config YAML no longer crashes gateway startup; a typo in HERMES_AGENT_TIMEOUT / HERMES_AGENT_TIMEOUT_WARNING / HERMES_AGENT_NOTIFY_INTERVAL no longer crashes the gateway or an agent turn.

Changes

  • Commit 1 (@vominh1919): yaml.safe_load(f) or {} at the one site in main() that was missing it (the other 6 sibling sites already have it). Wraps 4 float(os.getenv(...)) env-var casts in try/except (ValueError, TypeError) with fallback to the existing defaults.
  • Commit 2 (follow-up): Extract _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

Before After
touch /tmp/empty.yaml && hermes gateway --config /tmp/empty.yaml AttributeError on None.get starts with default config
HERMES_AGENT_TIMEOUT=abc hermes gateway ValueError crash falls back to 1800s
HERMES_AGENT_TIMEOUT="" ValueError crash falls back to default

Helper tested against unset / empty / typo / valid-float / integer-string / whitespace inputs.

Closes #17857.

vominh1919 and others added 2 commits April 30, 2026 03:31
…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.
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