From 1055d4356a56b5c5420040279d661ff20f813107 Mon Sep 17 00:00:00 2001 From: Test Date: Thu, 19 Mar 2026 19:42:11 -0700 Subject: [PATCH] fix: skip model auto-detection for custom/local providers When the user is on a custom provider (provider=custom, localhost, or 127.0.0.1 endpoint), /model no longer tries to auto-detect a provider switch. The model name changes on the current endpoint as-is. To switch away from a custom endpoint, users must use explicit provider:model syntax (e.g. /model openai-codex:gpt-5.2-codex). A helpful tip is printed when changing models on a custom endpoint. This prevents the confusing case where someone on LM Studio types /model gpt-5.2-codex, the auto-detection tries to switch providers, fails or partially succeeds, and requests still go to the old endpoint. Also fixes the missing prompt_toolkit.auto_suggest mock stub in test_cli_init.py (same issue already fixed in test_cli_new_session.py). --- cli.py | 20 ++++++++++++++++++-- tests/test_cli_init.py | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cli.py b/cli.py index ccc1e0d68..af8ac4efc 100755 --- a/cli.py +++ b/cli.py @@ -3517,8 +3517,17 @@ class HermesCLI: # Parse provider:model syntax (e.g. "openrouter:anthropic/claude-sonnet-4.5") current_provider = self.provider or self.requested_provider or "openrouter" target_provider, new_model = parse_model_input(raw_input, current_provider) - # Auto-detect provider when no explicit provider:model syntax was used - if target_provider == current_provider: + # Auto-detect provider when no explicit provider:model syntax was used. + # Skip auto-detection for custom providers — the model name might + # coincidentally match a known provider's catalog, but the user + # intends to use it on their custom endpoint. Require explicit + # provider:model syntax (e.g. /model openai-codex:gpt-5.2-codex) + # to switch away from a custom endpoint. + _base = self.base_url or "" + is_custom = current_provider == "custom" or ( + "localhost" in _base or "127.0.0.1" in _base + ) + if target_provider == current_provider and not is_custom: from hermes_cli.models import detect_provider_for_model detected = detect_provider_for_model(new_model, current_provider) if detected: @@ -3586,6 +3595,13 @@ class HermesCLI: if message: print(f" Reason: {message}") print(" Note: Model will revert on restart. Use a verified model to save to config.") + + # Helpful hint when staying on a custom endpoint + if is_custom and not provider_changed: + endpoint = self.base_url or "custom endpoint" + print(f" Endpoint: {endpoint}") + print(f" Tip: To switch providers, use /model provider:model") + print(f" e.g. /model openai-codex:gpt-5.2-codex") else: self._show_model_and_providers() elif canonical == "provider": diff --git a/tests/test_cli_init.py b/tests/test_cli_init.py index 5ebd301ed..f41f81bb8 100644 --- a/tests/test_cli_init.py +++ b/tests/test_cli_init.py @@ -42,6 +42,7 @@ def _make_cli(env_overrides=None, config_overrides=None, **kwargs): "prompt_toolkit.key_binding": MagicMock(), "prompt_toolkit.completion": MagicMock(), "prompt_toolkit.formatted_text": MagicMock(), + "prompt_toolkit.auto_suggest": MagicMock(), } with patch.dict(sys.modules, prompt_toolkit_stubs), \ patch.dict("os.environ", clean_env, clear=False):