Skip to content

fix(cli): dedupe .env keys in save_env_value#40753

Open
chrislazar25 wants to merge 1 commit into
NousResearch:mainfrom
chrislazar25:fix/issue-8270
Open

fix(cli): dedupe .env keys in save_env_value#40753
chrislazar25 wants to merge 1 commit into
NousResearch:mainfrom
chrislazar25:fix/issue-8270

Conversation

@chrislazar25

@chrislazar25 chrislazar25 commented Jun 6, 2026

Copy link
Copy Markdown

save_env_value() only updated the first KEY= value it found in .env, then stopped. But python-dotenv reads with last-occurrence-wins semantics, so if you had two OPENROUTER_API_KEY lines, the second (stale) one always won at runtime - even though save_env_value wrote the correct value to the first line.

The fix is removing the break in save_env_value() so every matching line gets updated. No more shadowing.

How to test:

  1. Create a .env with duplicate OPENROUTER_API_KEY lines with different values
  2. Run hermes config set openrouter_api_key
  3. Check that both lines now have the same correct value
  4. Verify hermes connects to OpenRouter successfully (it was failing with HTTP 400 before)

Platforms tested:
Linux (Pop!_OS 22.04). Standard file I/O - works on macOS, Linux, and WSL2.

Fixes #8270

@daimon-nous daimon-nous Bot 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 Jun 6, 2026
save_env_value() only updated the first matching line in .env, then broke out of the loop. python-dotenv resolves env vars with last-occurrence-wins semantics, so any stale duplicate key lower in the file silently shadowed the corrected value.

Fix: remove the break so ALL matching lines are updated. Duplicate keys get the same value, eliminating the shadowing.

Tests added for both the fix and a regression case.

Fixes NousResearch#8270
@chrislazar25 chrislazar25 changed the title fix(config): deduplicate .env keys in save_env_value fix(cli): dedupe .env keys in save_env_value Jun 6, 2026
@chrislazar25 chrislazar25 marked this pull request as ready for review June 6, 2026 20:58
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.

HTTP 400 on all OpenRouter models - curl works fine

1 participant