hermes - 💡(How to fix) Fix Bug: Model switch mid-session not persisted to database (dashboard shows stale model)

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 a user switches models mid-session (via /model command in Telegram/Discord), the gateway updates the agent in memory and registers the session override, but does not update the database. This causes the dashboard "Models" page to show the stale original model instead of the actually-used model.

Root Cause

In hermes_state.py, the update_token_counts() method uses:

model = COALESCE(model, ?)

This only sets the model if the current value is NULL. Since the session was created with the original model, switching to a new model mid-session doesn't update the database record.

Additionally, the gateway's /model command handler (gateway/run.py, _handle_model_command()) updates the cached agent and stores the override in _session_model_overrides, but never calls any database update method to persist the new model.

Code Example

model = COALESCE(model, ?)

---

# After storing the session override
db.update_session_model(session_key, result.new_model)

---

model = ?  -- instead of COALESCE(model, ?)
RAW_BUFFERClick to expand / collapse

Description

When a user switches models mid-session (via /model command in Telegram/Discord), the gateway updates the agent in memory and registers the session override, but does not update the database. This causes the dashboard "Models" page to show the stale original model instead of the actually-used model.

Root Cause

In hermes_state.py, the update_token_counts() method uses:

model = COALESCE(model, ?)

This only sets the model if the current value is NULL. Since the session was created with the original model, switching to a new model mid-session doesn't update the database record.

Additionally, the gateway's /model command handler (gateway/run.py, _handle_model_command()) updates the cached agent and stores the override in _session_model_overrides, but never calls any database update method to persist the new model.

Steps to Reproduce

  1. Start a session with model A (e.g., xiaomi/mimo-v2.5-pro)
  2. Switch to model B mid-session via /model xiaomi/mimo-v2.5
  3. Continue using the session with model B
  4. Check the dashboard "Models" page — it still shows model A

Expected Behavior

The dashboard should show the model that was actually used, not the original model from session creation.

Impact

  • Dashboard analytics are inaccurate for sessions with model switches
  • Users can't track which models they actually used
  • The "Models Used" count may be incorrect

Suggested Fix

When a model switch occurs via /model, the gateway should update the database:

# After storing the session override
db.update_session_model(session_key, result.new_model)

Or modify update_token_counts() to always update the model when a new value is provided:

model = ?  -- instead of COALESCE(model, ?)

Environment

  • Hermes Agent version: latest (dev)
  • Platform: Telegram
  • Provider: OpenRouter
  • Models tested: xiaomi/mimo-v2.5-pro → xiaomi/mimo-v2.5

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

hermes - 💡(How to fix) Fix Bug: Model switch mid-session not persisted to database (dashboard shows stale model)