fix(gateway): expand env vars in fallback_providers/fallback_model config - #25005
Open
nainaism wants to merge 1 commit into
Open
fix(gateway): expand env vars in fallback_providers/fallback_model config#25005nainaism wants to merge 1 commit into
nainaism wants to merge 1 commit into
Conversation
…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
Collaborator
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
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()atgateway/run.py:13316andgateway/run.py:18202; that method still reads raw YAML atgateway/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 atgateway/run.py:1948-1969; it can pass a literal${VAR}asexplicit_api_keyduring primary-auth failover.gateway/run.py:2376-2393already 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.
| AIAgent.__init__ normalizes both formats into a chain. | ||
| Uses load_config() so ${VAR} env references are expanded. | ||
| """ | ||
| try: |
Contributor
There was a problem hiding this comment.
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.
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.
Summary
_load_fallback_model()was readingconfig.yamlviayaml.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 withcli.py:load_cli_config()and all other config paths.Changes
yaml.safe_load()withload_config()in_load_fallback_model()Related
Verification
load_config()is used by the CLI config bridge (cli.py:454) and correctly expands${VAR}referencesAIAgent.__init__normalizes bothfallback_providers(list) andfallback_model(legacy dict) formats