From be1dcee823afe74c8243aeeabd16b685247b637c Mon Sep 17 00:00:00 2001 From: nainai Date: Wed, 13 May 2026 21:46:05 +0900 Subject: [PATCH] fix(gateway): expand env vars in fallback_providers/fallback_model config _load_fallback_model() was reading config.yaml via yaml.safe_load() directly, bypassing the _expand_env_vars() step that resolves references from .env / credential_pool. This caused fallback activation to send the literal string '' as the API key, resulting in 401. Switch to load_config() which already handles env expansion, aligning this loader with cli.py:load_cli_config() and all other config paths. Fixes #20974 --- gateway/run.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/gateway/run.py b/gateway/run.py index 46c508e4bde00..bb3c6c92a865f 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -2431,21 +2431,19 @@ def _load_provider_routing() -> dict: @staticmethod def _load_fallback_model() -> list | dict | None: - """Load fallback provider chain from config.yaml. + """Load fallback provider chain from config.yaml with env expansion. Returns a list of provider dicts (``fallback_providers``), a single dict (legacy ``fallback_model``), or None if not configured. AIAgent.__init__ normalizes both formats into a chain. + Uses load_config() so ${VAR} env references are expanded. """ try: - import yaml as _y - cfg_path = _hermes_home / "config.yaml" - if cfg_path.exists(): - with open(cfg_path, encoding="utf-8") as _f: - cfg = _y.safe_load(_f) or {} - fb = cfg.get("fallback_providers") or cfg.get("fallback_model") or None - if fb: - return fb + from hermes_cli.config import load_config + cfg = load_config() + fb = cfg.get("fallback_providers") or cfg.get("fallback_model") or None + if fb: + return fb except Exception: pass return None