hermes - 💡(How to fix) Fix # Bug Report: `model.context_length` persists across `/model` provider switches

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

When switching providers mid-session via /model, the top-level model.context_length from config.yaml is stored as _config_context_length at startup and never re-resolved. This causes the context window of the new provider to be silently shadowed by the old provider's value.

Root Cause

In run_agent.py, _config_context_length is resolved once during __init__ from model.context_length (line ~2194) and stored as self._config_context_length. When switch_model() calls get_model_context_length() (line ~2679), it passes this stale value as config_context_length, which takes precedence over the new provider's context_length.

Fix Action

Fix

In switch_model(), re-resolve _config_context_length from the live config before updating the context compressor. If the new provider doesn't match the default provider, clear the stale value so the new provider's per-model/per-provider context_length takes effect.

Code Example

model:
  default: mimo-v2.5-pro
  provider: custom
  base_url: http://localhost:4000/v1
  api_key: sk-xxx
  context_length: 1000000

providers:
  local:
    name: local
    base_url: http://localhost:8080/v1
    api_key: "not-needed"
    model: gemma-4-26b
    context_length: 8192
RAW_BUFFERClick to expand / collapse

context-length-fix.patch

Summary

When switching providers mid-session via /model, the top-level model.context_length from config.yaml is stored as _config_context_length at startup and never re-resolved. This causes the context window of the new provider to be silently shadowed by the old provider's value.

Steps to Reproduce

  1. Configure config.yaml with a cloud provider as default:
model:
  default: mimo-v2.5-pro
  provider: custom
  base_url: http://localhost:4000/v1
  api_key: sk-xxx
  context_length: 1000000

providers:
  local:
    name: local
    base_url: http://localhost:8080/v1
    api_key: "not-needed"
    model: gemma-4-26b
    context_length: 8192
  1. Start Hermes — context window shows 1M (correct for cloud).
  2. Switch to local provider: /model gemma-4-26b --provider custom:local
  3. Check /status — context window still shows 1M instead of 8192.

Expected Behavior

After switching to a provider with context_length: 8192, the context window should reflect 8192.

Actual Behavior

The context window remains at 1,000,000 — the stale _config_context_length from startup shadows the new provider's value.

Root Cause

In run_agent.py, _config_context_length is resolved once during __init__ from model.context_length (line ~2194) and stored as self._config_context_length. When switch_model() calls get_model_context_length() (line ~2679), it passes this stale value as config_context_length, which takes precedence over the new provider's context_length.

Fix

In switch_model(), re-resolve _config_context_length from the live config before updating the context compressor. If the new provider doesn't match the default provider, clear the stale value so the new provider's per-model/per-provider context_length takes effect.

Environment

  • Hermes Agent v2026.4.x (Docker)
  • WSL2 / Linux
  • Multiple providers: cloud (LiteLLM proxy, 1M ctx) + local (llamacpp, 8K ctx)

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING