fix(runtime_provider, model_switch): resolve custom provider key_env from .env file - #41375
Closed
franksong2702 wants to merge 1 commit into
Closed
Conversation
…from .env file When a custom provider declares key_env in config.yaml (e.g. VOLCENGINE_CODING_PLAN_API_KEY), three code paths only read from os.environ instead of using get_env_value() which also checks ~/.hermes/.env. This causes named custom providers to silently fall back to 'no-key-required' when the key only exists in .env. Affected paths: - _get_named_custom_provider(): line 531, os.getenv() -> get_env_value() - _resolve_named_custom_runtime(): line 735, os.getenv() -> get_env_value() - switch_model() user-provider path: line 921, os.environ.get() -> get_env_value() Fix: All three now use get_env_value() from hermes_cli.config, which reads os.environ first then falls back to ~/.hermes/.env. This is a regression for any user who stores provider credentials in .env (the documented approach) rather than pre-loading them into the process environment.
tonydwb
approved these changes
Jun 7, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
- Consistent fix for provider key_env resolution: replaces raw
os.getenvwithget_env_valueat 3 call sites. - This aligns custom-provider credential lookup with the rest of the
hermes_clicode path, which is likely required for profile-aware.envresolution. - Small diff, focused scope, low regression risk.
Reviewed by Hermes Agent
19 tasks
Contributor
|
Thanks for the focused credential-resolution report and patch. This is an automated hermes-sweeper review; the requested behavior is already present on current
|
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
Named custom providers that declare
key_envinconfig.yaml(e.g.key_env: VOLCENGINE_CODING_PLAN_API_KEY) silently lose their credentials when the key only exists in~/.hermes/.env.Three code paths read
key_envviaos.getenv()/os.environ.get()instead ofget_env_value()— which means they only see process-level env vars and miss the.envfile entirely. The fallback chain then produces an empty string, and the next fallback is the inlineapi_keyfield (also empty for users who migrated to.env). The end result: the provider resolves to"no-key-required"and every/modelsprobe returns 401.Root Cause
get_env_value()inhermes_cli/config.pyreadsos.environfirst, then falls back to parsing~/.hermes/.env. Three call sites bypassed this helper:runtime_provider.py_get_named_custom_provideros.getenv(key_env, "")get_env_value(key_env)runtime_provider.py_resolve_named_custom_runtimeos.getenv(key_env)get_env_value(key_env)model_switch.pyswitch_model(user provider path)os.environ.get(_kenv, "")get_env_value(_kenv)Impact
Any user who:
config.yamlwithkey_env: SOME_VAR~/.hermes/.env(the documented approach)...will experience silent credential loss on that provider. The model switch still appears to succeed (because the validation override at line 1002-1041 catches models declared in the provider's
models:list), but:/modelsprobes fail with 401"could not reach the API to validate"Reproduction
Tests
All 207 tests in the relevant test files pass:
tests/hermes_cli/test_runtime_provider_resolution.pytests/hermes_cli/test_model_validation.pytests/hermes_cli/test_model_switch_copilot_api_mode.pyChecklist