fix: a chat switched to Codex no longer sends its model to the previous provider's endpoint

The messaging gateway's /model wrote only model + provider to the session row. A row the
Desktop/TUI had persisted with the Nous Portal route kept that base_url and api_mode, so resuming
a chat switched to openai-codex built provider=openai-codex on the Portal URL and posted
gpt-6-luna-900k to inference-api.nousresearch.com/v1/chat/completions: "Model 'gpt-6-luna-900k'
isn't available on ChatGPT or Codex Subscription".

- SessionDB.update_session_model writes the whole route (provider, base_url, api_mode) in both
  shapes resume reads (top-level for TUI/Desktop, gateway_runtime for the CLI) whenever a
  provider is given; the gateway /model passes the switch result's endpoint.
- Resume readers (TUI/Desktop, CLI, gateway rehydrate) drop a persisted base_url that is another
  built-in provider's canonical endpoint, so rows already written by older builds heal.
- A gateway session override whose credentials failed to re-resolve is resolved for its own
  provider on the turn instead of being layered over the default provider's runtime (which
  produced openai-codex + Nous key + Nous URL). If it still cannot resolve, that turn runs on the
  whole default route with the existing one-shot "Provider fallback" notice; the override is kept
  and retried next turn.
This commit is contained in:
teknium1
2026-09-23 03:43:12 -07:00
committed by Teknium
parent 24f03c41c1
commit 07646a7f72
9 changed files with 127 additions and 10 deletions

View File

@@ -61,6 +61,10 @@ def stored_session_route(session_meta, *, current_model, current_provider):
if stored_model == current_model and not provider_changed:
return None
api_mode = runtime.get("api_mode") or None
from hermes_cli.runtime_provider import is_foreign_provider_endpoint
if is_foreign_provider_endpoint(provider, base_url):
# The endpoint and its wire belong to the provider this chat left; resolve the stored one's own.
base_url = api_mode = None
# A row's api_mode/base_url were written for whichever model the session last ran. Providers that
# pick the wire per model (OpenCode Zen/Go, Copilot, Nous) re-derive both from the stored model, or a
# resumed opencode-go session keeps a MiniMax-era anthropic_messages route for a chat_completions