Skip to content

Make the composer model picker per-chat instead of global - #282

Open
pufit wants to merge 1 commit into
mainfrom
pufit/per-chat-model-picker
Open

Make the composer model picker per-chat instead of global#282
pufit wants to merge 1 commit into
mainfrom
pufit/per-chat-model-picker

Conversation

@pufit

@pufit pufit commented Aug 6, 2026

Copy link
Copy Markdown
Member

Problem

Changing the model in the composer's picker changed it for all chats: the pick was a global selectedModels[backend] map in the chat store, persisted to localStorage, and sent as a per-message override with every message from every chat. Picking a model in one chat silently re-pointed every other chat's next turn (and every future new chat).

Fix

The pick is now scoped to the chat it was made in, using the session row as the source of truth (matching the engine's existing per-turn resolution per-message → sessions.model → backend default):

  • Existing sessions: the picker shows that session's own model (same source as the header badge) and changing it PATCHes {model} onto that session's rowPATCH /api/sessions/{id} now accepts model, validated against the session's sticky backend (same optional validate_model seam as creation). The engine re-reads the row each turn, so the switch applies on that session's next message. Optimistic UI update with revert if the server rejects the pick.
  • New (virtual) chats: the pick lives in newChatModels (analogous to newChatBackend), binds at session creation (existing POST /api/sessions model param), and resets afterwards. null = server default.
  • No more per-message override from the composer: ws.sendMessage no longer sends model (the server still accepts the WS field for compat).
  • Legacy global localStorage keys (nerve_selected_model*) are removed on load, so a stale global pick can't keep overriding new chats.
  • Picker also keeps a session's model visible when the catalog no longer offers it (retired id / uninstalled Ollama model) instead of snapping to the first option.

Tests

  • tests/test_session_create_model.py: +7 PATCH cases — re-point persists, pick in one chat leaves other chats untouched, blank model 400, backend validation (codex reject/accept), 404, title-only PATCH regression. Fixture lifted to module scope, shared by both classes.
  • Full suite: 3021 passed. npm run build clean.
  • Verified in the browser: sessions on claude-fable-5 / claude-opus-5 / claude-opus-4-8 each show their own model; a pick in a new chat no longer leaks into other chats; failed PATCH reverts cleanly.

Deploy note

Needs a gateway restart to pick up the PATCH support; until then, re-pointing an existing session from the UI is a graceful no-op (400 → picker reverts).

Generated by Nerve

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant