Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10549,6 +10549,22 @@ async def _on_model_selected(
except Exception as exc:
logger.warning("Picker model switch failed for cached agent: %s", exc)

# Persist the new model to the session DB so the
# dashboard shows the updated model (#34850).
_sess_db = getattr(_self, "_session_db", None)
if _sess_db is not None:
try:
_sess_entry = _self.session_store.get_or_create_session(
event.source
)
_sess_db.update_session_model(
_sess_entry.session_id, result.new_model
)
except Exception as exc:
logger.debug(
"Failed to persist model switch to DB: %s", exc
)

# Store model note + session override
if not hasattr(_self, "_pending_model_notes"):
_self._pending_model_notes = {}
Expand Down Expand Up @@ -10686,6 +10702,19 @@ async def _on_model_selected(
except Exception as exc:
logger.warning("In-place model switch failed for cached agent: %s", exc)

# Persist the new model to the session DB so the dashboard
# shows the updated model (#34850).
if self._session_db is not None:
try:
_sess_entry = self.session_store.get_or_create_session(source)
self._session_db.update_session_model(
_sess_entry.session_id, result.new_model
)
except Exception as exc:
logger.debug(
"Failed to persist model switch to DB: %s", exc
)

# Store a note to prepend to the next user message so the model
# knows about the switch (avoids system messages mid-history).
if not hasattr(self, "_pending_model_notes"):
Expand Down
14 changes: 14 additions & 0 deletions hermes_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,20 @@ def _do(conn):
)
self._execute_write(_do)

def update_session_model(self, session_id: str, model: str) -> None:
"""Update the model for a session after a mid-session switch.

Unlike ``update_token_counts`` which uses ``COALESCE(model, ?)``
(only filling in NULL), this unconditionally sets the model column
so that the dashboard reflects the user's latest /model choice.
"""
def _do(conn):
conn.execute(
"UPDATE sessions SET model = ? WHERE id = ?",
(model, session_id),
)
self._execute_write(_do)

def update_token_counts(
self,
session_id: str,
Expand Down