Skip to content

fix(gateway): expand env vars in fallback_providers/fallback_model config - #25005

Open
nainaism wants to merge 1 commit into
NousResearch:mainfrom
nainaism:fix/20974-expand-fallback-env-vars
Open

fix(gateway): expand env vars in fallback_providers/fallback_model config#25005
nainaism wants to merge 1 commit into
NousResearch:mainfrom
nainaism:fix/20974-expand-fallback-env-vars

Conversation

@nainaism

Copy link
Copy Markdown

Summary

_load_fallback_model() was reading config.yaml via yaml.safe_load() directly, bypassing the _expand_env_vars() step that resolves ${VAR} references from .env / credential_pool. This caused fallback activation to send the literal string '${VAR}' as the API key, resulting in 401 errors.

Switch to load_config() which already handles env expansion, aligning this loader with cli.py:load_cli_config() and all other config paths.

Changes

  • gateway/run.py: Replace raw yaml.safe_load() with load_config() in _load_fallback_model()

Related

Verification

  • load_config() is used by the CLI config bridge (cli.py:454) and correctly expands ${VAR} references
  • AIAgent.__init__ normalizes both fallback_providers (list) and fallback_model (legacy dict) formats
  • No behavior change for users with hardcoded API keys

…nfig

_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 NousResearch#20974
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery area/config Config system, migrations, profiles labels May 13, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing fix: this PR addresses the same issue (#20974) as #20980 and #21029. All three replace bare yaml.safe_load() with env-var-expanded config loading in _load_fallback_model(). Maintainer decision needed on which approach to merge.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for identifying the gateway config-expansion gap. The underlying issue remains on current main, but the original one-method patch needs adaptation to the newer fallback reload paths.

Problems

  • Current gateway agent construction calls _refresh_fallback_model() at gateway/run.py:13316 and gateway/run.py:18202; that method still reads raw YAML at gateway/run.py:5031-5032, so changing only the older static loader would not cover the active per-turn path.
  • _try_resolve_fallback_provider() has the same raw-YAML path at gateway/run.py:1948-1969; it can pass a literal ${VAR} as explicit_api_key during primary-auth failover.
  • gateway/run.py:2376-2393 already provides _load_gateway_runtime_config() for profile-aware gateway reads plus ${VAR} expansion. Please use it for all fallback readers and add a regression test for expanded fallback credentials.

This is an automated hermes-sweeper review.

Comment thread gateway/run.py
AIAgent.__init__ normalizes both formats into a chain.
Uses load_config() so ${VAR} env references are expanded.
"""
try:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current main now refreshes fallback entries per agent create/reuse through _refresh_fallback_model() (gateway/run.py:5011-5041), which still reads raw YAML. Salvage this by routing that method and _try_resolve_fallback_provider() through _load_gateway_runtime_config() as well; changing this static startup reader alone will not cover the active fallback path.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fallback_model.api_key in config.yaml is not expanded for ${VAR} references in gateway mode

3 participants