Skip to content

fix the auto reset of main model after altered by /model.#14654

Closed
Readon wants to merge 1 commit into
NousResearch:mainfrom
Readon:fix-slash-model-custom-provider
Closed

fix the auto reset of main model after altered by /model.#14654
Readon wants to merge 1 commit into
NousResearch:mainfrom
Readon:fix-slash-model-custom-provider

Conversation

@Readon

@Readon Readon commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes an issue where models selected via /model custom:yyyy are automatically overridden by the default_model from the provider configuration.
When users configure a custom provider (such as Ollama, vLLM, etc.) with a default_model, switching to a different model using the /model command would be overridden in the next conversation turn, resetting back to the default model.
Root Cause: The _ensure_runtime_credentials() method in cli.py calls resolve_runtime_provider() at the start of each conversation turn, which retrieves the provider configuration including the default_model. The original code unconditionally overwrote the user's model selection with this runtime model, without distinguishing between:

  • User's explicitly chosen model (should be preserved)
  • Provider name as model (needs resolution to default_model)
    Fix: Added conditional logic to only apply the runtime default_model when:
  1. No model is set (first-time use)
  2. The model equals the provider name (needs resolution to default_model)
  3. The model matches the provider's display name
    This preserves the user's explicit model selection while maintaining the existing auto-resolution functionality.

Related Issue

Fixes # (fill in if there's a related issue)

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • cli.py (lines 3149-3158): Modified model override logic in _ensure_runtime_credentials() method
    • Added conditional check should_use_runtime_model
    • Only applies runtime default_model when model is unset or equals provider name
    • Preserves user's explicit model selection via /model command

How to Test

Steps to reproduce the bug (before fix):

  1. Configure a custom provider:
# ~/.hermes/config.yaml
providers:
  my-ollama:
    base_url: "http://localhost:11434/v1"
    default_model: "llama3.2"
  1. Start Hermes CLI and switch model:
/model my-ollama:qwen2.5
  1. Send a message
  2. Model gets overridden to llama3.2
    Steps to verify the fix (after fix):
  3. Repeat the above steps
  4. After sending a message, model remains my-ollama:qwen2.5
    Run tests:
pytest tests/hermes_cli/test_user_providers_model_switch.py -v
pytest tests/run_agent/test_switch_model_* -v

All tests should pass (20/20).

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Ubuntu 24.04

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — N/A (internal logic fix, no doc updates needed)
  • I've updated cli-config.yaml.example if I added/changed config keys — N/A (no config changes)
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — Change only involves Python logic, no platform-specific code
  • I've updated tool descriptions/schemas if I changed tool behavior — N/A (no tool changes)

For New Skills

N/A (not adding a new skill)

Screenshots / Logs

Before fix:

User: /model my-ollama:qwen2.5
✓ Model switched: my-ollama:qwen2.5
User: (send message)
[internal log] Overriding model to llama3.2  ← Bug!

After fix:

User: /model my-ollama:qwen2.5
✓ Model switched: my-ollama:qwen2.5
User: (send message)
✓ Model remains my-ollama:qwen2.5  ← Fixed!

Test output:

tests/hermes_cli/test_user_providers_model_switch.py::test_switch_model_resolves_user_provider_credentials PASSED
============================== 15 passed in 1.21s ===============================

@Readon Readon changed the title fix the reset of model change by /model. fix the auto reset of main model after altered by /model. Apr 23, 2026
@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 labels Apr 23, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #15605 — your fix was cherry-picked onto current main with your authorship preserved in git log (branch was 93 commits stale so a direct merge wasn't possible). Thanks for the careful root-cause analysis + tests!

#15605

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants