Skip to content

fix: provider selection not persisting when switching via hermes model#881

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-b0162f8d
Mar 11, 2026
Merged

fix: provider selection not persisting when switching via hermes model#881
teknium1 merged 1 commit into
mainfrom
hermes/hermes-b0162f8d

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Two related bugs prevented users from reliably switching providers via hermes model and /model:

Bug 1: OPENAI_BASE_URL poisons OpenRouter resolution

When a user has a custom endpoint (OPENAI_BASE_URL set) and tries /model openrouter:anthropic/claude-opus-4.6, the runtime provider resolution picks up OPENAI_BASE_URL instead of the OpenRouter URL. Model validation probes the wrong API and rejects valid models.

Fix: Skip OPENAI_BASE_URL in the URL resolution chain when the user explicitly requests openrouter.

Bug 2: Provider never saved to config after model selection

_save_model_choice() could save config.model as a plain string (not a dict). All five _model_flow_* functions then checked isinstance(model, dict) before writing the provider — which silently failed on strings. With no provider in config, resolve_requested_provider() fell through to "auto" detection, which would pick up stale credentials (e.g. Codex desktop app tokens) instead of the user's explicit choice.

Fix:

  • _save_model_choice() now always saves in dict format: {"default": model_id}
  • All 5 flow functions normalize string→dict before writing provider (safety net)

Files Changed

  • hermes_cli/runtime_provider.py — skip OPENAI_BASE_URL for explicit openrouter
  • hermes_cli/auth.py — _save_model_choice always uses dict format
  • hermes_cli/main.py — 5 flow functions hardened
  • tests/test_runtime_provider_resolution.py — 1 regression test
  • tests/test_model_provider_persistence.py — 3 regression tests

Test Plan

  • 2873 tests pass (4 new)
  • Verified: selecting Kimi via hermes model now correctly persists provider: kimi-coding to config even when config.model started as a plain string
  • Verified: /model openrouter:model works correctly when OPENAI_BASE_URL is set to a custom endpoint

Two related bugs prevented users from reliably switching providers:

1. OPENAI_BASE_URL poisoning OpenRouter resolution: When a user with a
   custom endpoint ran /model openrouter:model, _resolve_openrouter_runtime
   picked up OPENAI_BASE_URL instead of the OpenRouter URL, causing model
   validation to probe the wrong API and reject valid models.

   Fix: skip OPENAI_BASE_URL when requested_provider is explicitly
   'openrouter'.

2. Provider never saved to config: _save_model_choice() could save
   config.model as a plain string. All five _model_flow_* functions then
   checked isinstance(model, dict) before writing the provider — which
   silently failed on strings. With no provider in config, auto-detection
   would pick up stale credentials (e.g. Codex desktop app) instead of
   the user's explicit choice.

   Fix: _save_model_choice() now always saves as dict format. All flow
   functions also normalize string->dict as a safety net before writing
   provider.

Adds 4 regression tests. 2873 tests pass.
@teknium1 teknium1 merged commit ac53bf1 into main Mar 11, 2026
1 check passed
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…0162f8d

fix: provider selection not persisting when switching via hermes model
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…0162f8d

fix: provider selection not persisting when switching via hermes model
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
…0162f8d

fix: provider selection not persisting when switching via hermes model
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…0162f8d

fix: provider selection not persisting when switching via hermes model
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.

1 participant