Skip to content

fix: warn and clear stale OPENAI_BASE_URL on provider switch#7601

Closed
kshitijk4poor wants to merge 1 commit intoNousResearch:mainfrom
kshitijk4poor:fix/clear-stale-openai-base-url
Closed

fix: warn and clear stale OPENAI_BASE_URL on provider switch#7601
kshitijk4poor wants to merge 1 commit intoNousResearch:mainfrom
kshitijk4poor:fix/clear-stale-openai-base-url

Conversation

@kshitijk4poor
Copy link
Copy Markdown
Collaborator

Problem

When users switch from a custom endpoint (e.g. local Ollama/vLLM) to a named provider (e.g. OpenRouter) via hermes model, OPENAI_BASE_URL persists in ~/.hermes/.env. The main inference client uses config.yaml correctly, but auxiliary clients (compression, vision, delegation) with provider:auto pick up the stale env var and route requests to the old custom endpoint.

Fixes #5161

Solution

Two-pronged fix:

1. Startup warning in auxiliary client (agent/auxiliary_client.py)

  • In _resolve_auto(), detect when OPENAI_BASE_URL is set but config.yaml model.provider is a named provider (not custom)
  • Log a WARNING once per process with actionable advice
  • Uses a module-level _stale_base_url_warned flag to avoid spamming

2. Proactive cleanup on provider switch (hermes_cli/main.py)

  • New _clear_stale_openai_base_url() helper called after every provider flow in select_provider_and_model()
  • When the user switches to any named provider, checks if OPENAI_BASE_URL is still set in .env and clears it
  • Skips cleanup for custom, cancel, remove-custom, and custom:* providers
  • Prints a confirmation message so the user knows what happened

Tests

4 new tests in tests/agent/test_auxiliary_client.py::TestStaleBaseUrlWarning:

  • Warning fires when OPENAI_BASE_URL conflicts with named provider
  • No warning when provider is custom (OPENAI_BASE_URL is expected)
  • No warning when OPENAI_BASE_URL is not set
  • Warning only fires once per process

4 new tests in tests/hermes_cli/test_clear_stale_base_url.py:

  • OPENAI_BASE_URL is cleared when provider is a named provider
  • OPENAI_BASE_URL is preserved when provider is custom
  • No error when OPENAI_BASE_URL is already empty
  • No cleanup when provider is not configured in config.yaml

All 8 tests pass. Pre-existing test failures are unrelated.

@teknium1
Copy link
Copy Markdown
Contributor

Merged via #7647. Your commit was cherry-picked onto current main with your authorship preserved in git log. Thanks @kshitijk4poor!

@teknium1 teknium1 closed this Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OPENAI_BASE_URL env var not cleared on provider switch — silently poisons auxiliary clients

2 participants