Skip to content

fix(persistence): persist provider in model_config on model switch (#79536) - #79811

Closed
RelaxJonh wants to merge 1 commit into
NousResearch:mainfrom
RelaxJonh:fix/persist-provider-on-model-switch-79536
Closed

fix(persistence): persist provider in model_config on model switch (#79536)#79811
RelaxJonh wants to merge 1 commit into
NousResearch:mainfrom
RelaxJonh:fix/persist-provider-on-model-switch-79536

Conversation

@RelaxJonh

Copy link
Copy Markdown
Contributor

Problem

When a session falls back to a model on a different provider and the user switches to it with (or the Desktop model selector), writes only the model name to the table — the provider is lost. On the next session resume, the runtime recombines the persisted model with the primary provider from , producing a guaranteed on every turn.

Root Cause

sets but never writes or keys into the JSON blob. The session-resume code has no way to recover the correct provider/model pair.

Fix

Add an optional keyword argument to . When given, the provider and model are persisted into via , so session resume recombines the correct pair.

Files Changed

File Change
Add kwarg to , persist via
Pass at both call sites
Pass at fallback call site
Add 2 tests: provider persistence + backward compat

Backward Compatibility

  • When is not passed (default ), behavior is identical to before — only is removed from .
  • All existing tests pass unchanged.

Fixes #79536

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery comp/tui Terminal UI (ui-tui/ + tui_gateway/) area/config Config system, migrations, profiles area/sessions Session lifecycle, resume, persistence, history P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Aug 6, 2026
…ousResearch#79536)

When a session falls back to a model on a different provider and the
user switches to it with /model, update_session_model() previously
wrote only the model name to the sessions table — the provider was
lost. On the next session resume, the runtime recombined the persisted
model with the primary provider from config.yaml, producing a
guaranteed 404 on every turn.

Fix: add an optional `provider` keyword argument to
update_session_model(). When given, the provider and model are also
written into the model_config JSON blob via json_set(), so session
resume can recombine the correct provider + model pair.

Call sites in gateway/slash_commands.py and tui_gateway/server.py now
pass the resolved provider (result.target_provider and
model_config["provider"] respectively).

Fixes NousResearch#79536
@RelaxJonh
RelaxJonh force-pushed the fix/persist-provider-on-model-switch-79536 branch from 9f69538 to 5bac2f7 Compare August 6, 2026 01:32
@teknium1

teknium1 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Thanks — reviewed against current origin/main. The write-side gap is real (update_session_model never writes provider into the model_config blob), but PR #79604 by @webtecnica was filed ~7 hours earlier, fixes the identical bug with near-identical SQL at the same two call sites, and is a superset (adds the gateway_runtime.provider legacy-row fallback on resume plus resume tests). Earliest-submitter rule applies, so we'll take #79604 as the landing vehicle.

One note for the record that applies to both PRs: the WHEN model_config IS NULL THEN NULL arm means sessions with a NULL blob (the common case) still lose the provider — that will need to be handled in the surviving PR before/at merge.

Closing as duplicate — thanks for the fix and for confirming the read-side loop.

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

Labels

area/config Config system, migrations, profiles area/sessions Session lifecycle, resume, persistence, history comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(persistence): update_session_model() doesn't persist provider in model_config → cross-provider fallback sessions 404 on resume

3 participants