Skip to content

[Bug]: CLI _ensure_runtime_credentials() overwrites manual model switch with custom_providers.model field #9679

@happy5318

Description

@happy5318

Bug Description

When a user manually switches models via /model command in CLI, the _ensure_runtime_credentials() method unconditionally overwrites self.model with the model field from custom_providers config on every message, ignoring the user's choice.

Root Cause

This is a side effect of PR #7935 which fixed #7828. The fix added this code in cli.py:2736-2738:

runtime_model = runtime.get("model")
if runtime_model and isinstance(runtime_model, str):
    self.model = runtime_model

This runs on every _ensure_runtime_credentials() call (before each API request), unconditionally setting the model from custom_providers[].model without checking if:

  1. User has manually switched models via /model
  2. A model.default config exists with a different model

Steps to Reproduce

  1. Configure custom_providers with a model field:
custom_providers:
- name: my-provider
  base_url: https://api.example.com/v1
  api_key: xxx
  model: default-model  # This will override manual switches
  models:
    model-a:
      context_length: 128000
    model-b:
      context_length: 192000
  1. Start CLI and switch model:
\model model-b --provider custom:my-provider
  1. Send a message like "hello"

  2. Expected: Model stays as model-b
    Actual: Model is overwritten to default-model from custom_providers[].model

Workaround

Remove the model field from custom_providers entries:

custom_providers:
- name: my-provider
  base_url: https://api.example.com/v1
  api_key: xxx
  # model: default-model  <-- remove this line
  models:
    model-a:
      context_length: 128000

Suggested Fix

The _ensure_runtime_credentials() method should:

  1. Check if self.model is already set from a manual switch or model.default config
  2. Only use runtime.get("model") when no model is configured
# Proposed fix: only use custom_providers.model when self.model is not set
runtime_model = runtime.get("model")
if runtime_model and isinstance(runtime_model, str) and not self.model:
    self.model = runtime_model

Or compare against config's model.default to determine if user has overridden.

Environment

  • Hermes Agent Version: v0.9.0 (2026.4.13)
  • Platform: CLI
  • Python: 3.11

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existsarea/configConfig system, migrations, profilescomp/cliCLI entry point, hermes_cli/, setup wizardtype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions