Skip to content

fix(auth): resolve base_url_env_var via get_env_value everywhere (closes #18757)#18948

Open
Sanjays2402 wants to merge 1 commit into
NousResearch:mainfrom
Sanjays2402:fix/18757-base-url-env-var-dotenv
Open

fix(auth): resolve base_url_env_var via get_env_value everywhere (closes #18757)#18948
Sanjays2402 wants to merge 1 commit into
NousResearch:mainfrom
Sanjays2402:fix/18757-base-url-env-var-dotenv

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Closes #18757

resolve_api_key_provider_credentials() and friends read base_url_env_var via os.getenv(), which never consults ~/.hermes/.env. A user who sets, e.g., XIAOMI_BASE_URL=https://token-plan-cn.xiaomimimo.com/v1 only in the dotenv file silently falls back to the registry default and gets 401s on auxiliary tasks. API keys are read correctly via get_env_value() — base URLs are not. This is the same bug class fixed for API keys in #16101 and for TTS/STT in #17434.

Why this PR rather than #17246

#17246 (diff) targets the same issue but only patches 2 of 6 buggy spots, and despite the PR description claiming runtime_provider.py was "aligned", the diff doesn't touch that file at all.

File Function #17246 This PR
hermes_cli/auth.py get_api_key_provider_status
hermes_cli/auth.py resolve_api_key_provider_credentials
hermes_cli/auth.py get_external_process_provider_status (Copilot ACP)
hermes_cli/auth.py resolve_external_process_provider_credentials
hermes_cli/runtime_provider.py resolve_runtime_provider (api_key branch) ❌ (claimed but absent)
hermes_cli/model_switch.py _refresh_curated_models builtin endpoint dedup

#17246 also bundles 5 unrelated fixes (cron, env precedence, moonshot detection, gateway lock, etc.) — this PR is scoped solely to #18757 so it can land without dragging the rest along.

Behavior

get_env_value() already preserves shell-export precedence — os.environ wins when the variable is exported, dotenv is the fallback. Existing deployments are unaffected; users who relied on the dotenv file finally get the right endpoint.

Tests

New tests/hermes_cli/test_base_url_dotenv_resolution.py (7 tests):

  • resolve_api_key_provider_credentials / get_api_key_provider_status read base URL from ~/.hermes/.env (Xiaomi)
  • resolve_external_process_provider_credentials / *_status read base URL from ~/.hermes/.env (Copilot ACP)
  • resolve_runtime_provider honours dotenv on the api_key branch
  • model_switch dedup helper is wired through get_env_value
  • Regression guard: shell exports still beat dotenv values
522 passed, 522 warnings in 6.24s

Run on the full intersection of test files touching the changed modules — full green, no regressions.

Files changed

  • hermes_cli/auth.py — top-level get_env_value import + 4 call sites
  • hermes_cli/runtime_provider.py — 1 call site
  • hermes_cli/model_switch.py — 1 call site (with os.environ fallback for safety)
  • tests/hermes_cli/test_base_url_dotenv_resolution.py — new

Closes #18757.

Closes NousResearch#18757.

resolve_api_key_provider_credentials() and friends used os.getenv() to
read `base_url_env_var`, which never consults ~/.hermes/.env. Result:
providers configured solely via the dotenv file (e.g. Xiaomi with a
custom `token-plan-cn.xiaomimimo.com` endpoint) silently fell back to
the registry default and returned 401s on auxiliary tasks.

The same os.getenv() vs get_env_value() pattern was fixed previously
in NousResearch#16101 and NousResearch#17434; this is the third pass for base_url_env_var.

PR NousResearch#17246 attempted this fix but only patched 2 of the 6 affected
spots and notably missed runtime_provider.py despite claiming to fix
it. This commit closes the remaining four:

  * hermes_cli/auth.py
      - get_api_key_provider_status (api_key path)              [PR NousResearch#17246 hit]
      - get_external_process_provider_status (Copilot ACP)      [missed]
      - resolve_api_key_provider_credentials                    [PR NousResearch#17246 hit]
      - resolve_external_process_provider_credentials           [missed]
  * hermes_cli/runtime_provider.py
      - resolve_runtime_provider api_key branch                 [missed]
  * hermes_cli/model_switch.py
      - _refresh_curated_models built-in endpoint dedup         [missed]

get_env_value() preserves shell-export precedence: os.environ wins
when the variable is exported, so existing deployments are unaffected.
The dotenv file is consulted only as a fallback, matching how API keys
have always been resolved.

Adds tests/hermes_cli/test_base_url_dotenv_resolution.py covering all
four fixed paths plus a guard test that shell exports still take
priority.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists area/auth Authentication, OAuth, credential pools area/config Config system, migrations, profiles comp/cli CLI entry point, hermes_cli/, setup wizard labels May 2, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #18797 and #18908 (same base_url dotenv bug). This PR claims more complete coverage (6/6 spots vs 2/6 in #17246). Supersedes #18797 if the coverage claim holds.

1 similar comment
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #18797 and #18908 (same base_url dotenv bug). This PR claims more complete coverage (6/6 spots vs 2/6 in #17246). Supersedes #18797 if the coverage claim holds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools area/config Config system, migrations, profiles comp/cli CLI entry point, hermes_cli/, setup wizard 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.

[Bug]: resolve_api_key_provider_credentials() uses os.getenv for base_url_env_var — misses ~/.hermes/.env values

2 participants