Make the composer model picker per-chat instead of global - #282
Open
pufit wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):model(same source as the header badge) and changing it PATCHes{model}onto that session's row —PATCH /api/sessions/{id}now acceptsmodel, validated against the session's sticky backend (same optionalvalidate_modelseam 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.newChatModels(analogous tonewChatBackend), binds at session creation (existingPOST /api/sessionsmodelparam), and resets afterwards.null= server default.ws.sendMessageno longer sendsmodel(the server still accepts the WS field for compat).nerve_selected_model*) are removed on load, so a stale global pick can't keep overriding new chats.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.npm run buildclean.claude-fable-5/claude-opus-5/claude-opus-4-8each 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).