Skip to content

fix(doctor): use get_env_value for API keys and base URLs instead of os.getenv#18989

Closed
shellybotmoyer wants to merge 1 commit into
NousResearch:mainfrom
shellybotmoyer:fix/doctor-get-env-value
Closed

fix(doctor): use get_env_value for API keys and base URLs instead of os.getenv#18989
shellybotmoyer wants to merge 1 commit into
NousResearch:mainfrom
shellybotmoyer:fix/doctor-get-env-value

Conversation

@shellybotmoyer

Copy link
Copy Markdown
Contributor

Problem

hermes_cli/doctor.py uses os.getenv() to read API keys and base URL env vars, which only reads from os.environ. Values stored in ~/.hermes/.env (the standard location for API keys) are silently missed.

This causes:

  • API key blindspot: doctor reports keys as "not configured" when they exist only in ~/.hermes/.env
  • Base URL fallback: providers with custom BASE_URL in .env (like DASHSCOPE_BASE_URL) fall back to wrong registry defaults, causing false "invalid key" reports

Same pattern as #18757 (fixed in auth.py) — os.getenv() vs get_env_value() inconsistency.

Fix

Replace os.getenv() with get_env_value() (with os.getenv() fallback) at 3 call sites:

  1. Line 998: openrouter_key = os.getenv("OPENROUTER_API_KEY")_get_env_value("OPENROUTER_API_KEY") or os.getenv("OPENROUTER_API_KEY")
  2. Line 1111: _key = os.getenv(_ev, "") in provider loop → _get_env_value(_ev) or os.getenv(_ev, "")
  3. Line 1123: _base = os.getenv(_base_env, "") for base URL → _get_env_value(_base_env) or os.getenv(_base_env, "")

The fallback to os.getenv() ensures values injected directly into the process environment (e.g., Docker, CI) still work.

Related

…os.getenv

os.getenv() only reads os.environ, missing values stored in ~/.hermes/.env. doctor would report keys as missing and base URLs as default when they were configured in .env. Same pattern as NousResearch#18757 fix in auth.py.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard area/config Config system, migrations, profiles labels May 2, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #18910 — same root cause: doctor.py uses os.getenv() instead of get_env_value(), missing keys in ~/.hermes/.env. Also related to #18797 (same pattern in auth.py).

@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #18910.

@shellybotmoyer

Copy link
Copy Markdown
Contributor Author

Superseded by #23352, which rebases this fix onto current main. Closing in favor of the clean replacement.

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/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.

2 participants