Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(chat): the open chat records the model it is actually running on

purple48f30a32f57c
diff --git a/src/stores/__tests__/conversation-model-follows-switch.test.ts b/src/stores/__tests__/conversation-model-follows-switch.test.ts
new file mode 100644
index 00000000..52283383
--- /dev/null
+++ b/src/stores/__tests__/conversation-model-follows-switch.test.ts
@@ -0,0 +1,119 @@
+/**
+ * Befund 4 of the abnahme counter-check on the 2.6.7 Windows build
+ * (2026-08-29, ergebnis-abnahme-durchklick.md).
+ *
+ * The tester switched the model mid-chat. The wire of that same turn carried
+ * model=Qwen3-4B-Q4_K_M, correctly, and the saved chat still read
+ * "openai::Hermes-3-Llama-3.2-3B" (wire-p3b.txt). The request was right; the
+ * record was not, and the record is what an export, a reopened chat and every
+ * later reader see.
+ *
+ * Pure bookkeeping, so it is fixed as bookkeeping: every path that changes
+ * the selection goes through modelStore.setActiveModel, and that is where the
+ * open chat is told.
+ *
+ * Run: npx vitest run src/stores/__tests__/conversation-model-follows-switch.test.ts
+ */
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+
+vi.mock('@tauri-apps/api/core', () => ({ invoke: vi.fn(async () => undefined) }))
+vi.mock('../../api/backend', () => ({
+ isTauri: vi.fn(() => false),
+ backendCall: vi.fn(async () => undefined),
+}))
+vi.mock('../../api/ollama', () => ({ unloadModel: vi.fn(async () => undefined) }))
+vi.mock('../../api/lmstudio', () => ({ unloadLmStudioModel: vi.fn(async () => undefined) }))
+vi.mock('../../api/engine', () => ({ activateBuiltinModel: vi.fn(async () => undefined) }))
+
+import { useModelStore } from '../modelStore'
+import { useChatStore } from '../chatStore'
+
+const HERMES = 'openai::Hermes-3-Llama-3.2-3B.Q4_K_M'
+const QWEN = 'openai::Qwen3-4B-Q4_K_M'
+
+const openChat = (model: string) => {
+ const id = useChatStore.getState().createConversation(model, '')
+ return id
+}
+
+beforeEach(() => {
+ useChatStore.setState({ conversations: [], activeConversationId: null })
+ useModelStore.setState({ models: [], activeModel: null })
+})
+
+describe('the open chat records the model it is actually running on', () => {
+ it('THE FIX: the exact counter-check frame, Hermes chat switched to Qwen3', () => {
+ useModelStore.setState({ activeModel: HERMES })
+ const id = openChat(HERMES)
+
+ useModelStore.getState().setActiveModel(QWEN)
+
+ expect(useChatStore.getState().conversations.find((c) => c.id === id)!.model).toBe(QWEN)
+ })
+
+ it('NEGATIVE CONTROL: the chats beside it are not rewritten', () => {
+ const other = openChat(HERMES)
+ const open = openChat(HERMES)
+ useChatStore.setState({ activeConversationId: open })
+ useModelStore.setState({ activeModel: HERMES })
+
+ useModelStore.getState().setActiveModel(QWEN)
+
+ const byId = new Map(useChatStore.getState().conversations.map((c) => [c.id, c.model]))
+ expect(byId.get(open)).toBe(QWEN)
+ expect(byId.get(other)).toBe(HERMES)
+ })
+
+ it('NEGATIVE CONTROL: no open chat is not an error, and writes nothing', () => {
+ openChat(HERMES)
+ useChatStore.setState({ activeConversationId: null })
+
+ expect(() => useModelStore.getState().setActiveModel(QWEN)).not.toThrow()
+ expect(useChatStore.getState().conversations[0].model).toBe(HERMES)
+ })
+
+ it('NEGATIVE CONTROL: clearing the selection does not blank the record', () => {
+ // The Local/Cloud switch clears the pick when the new mode has nothing to
+ // offer. That is a state of the picker, not a statement about the chat.
+ const id = openChat(HERMES)
+ useModelStore.setState({ activeModel: HERMES })
+
+ useModelStore.getState().setActiveModel(null)
+
+ expect(useChatStore.getState().conversations.find((c) => c.id === id)!.model).toBe(HERMES)
+ })
+
+ it('NEGATIVE CONTROL: picking a model does not move the chat up the sidebar', () => {
+ // updatedAt orders the list. Choosing a model is not activity in the chat.
+ const id = openChat(HERMES)
+ const before = useChatStore.getState().conversations.find((c) => c.id === id)!.updatedAt
+ useModelStore.setState({ activeModel: HERMES })
+
+ useModelStore.getState().setActiveModel(QWEN)
+
+ expect(useChatStore.getState().conversations.find((c) => c.id === id)!.updatedAt).toBe(before)
+ })
+
+ it('NEGATIVE CONTROL: re-picking the same model touches no state at all', () => {
+ const id = openChat(QWEN)
+ const before = useChatStore.getState().conversations
+ useModelStore.setState({ activeModel: HERMES })
+
+ useModelStore.getState().setActiveModel(QWEN)
+
+ // Same array identity: nothing to write means no persist round either.
+ expect(useChatStore.getState().conversations).toBe(before)
+ expect(useChatStore.getState().conversations.find((c) => c.id === id)!.model).toBe(QWEN)
+ })
+
+ it('a first pick with no previous model is recorded too', () => {
+ // setActiveModel returns early on the VRAM handling when there was no
+ // previous model. The record must still be written.
+ const id = openChat(HERMES)
+ useModelStore.setState({ activeModel: null })
+
+ useModelStore.getState().setActiveModel(QWEN)
+
+ expect(useChatStore.getState().conversations.find((c) => c.id === id)!.model).toBe(QWEN)
+ })
+})
diff --git a/src/stores/chatStore.ts b/src/stores/chatStore.ts
index 53f3fb4e..3f2d287f 100644
--- a/src/stores/chatStore.ts
+++ b/src/stores/chatStore.ts
@@ -43,6 +43,17 @@ interface ChatState {
setConversationPersonaEnabled: (id: string, enabled: boolean) => void
/** Group chat v1: the models that answer in turn (capped at 4). */
setGroupModels: (id: string, models: string[]) => void
+ /** Write the model the open chat is actually running on.
+ *
+ * Befund 4 of the abnahme counter-check (2026-08-29): switching the model
+ * mid-chat left conversation.model on whatever was picked when the chat
+ * was created. The saved chat said Hermes while the wire of that same turn
+ * already went to Qwen3. The request was right, the record was not, and
+ * the record is what an export, a reopened chat and every later reader see.
+ *
+ * No updatedAt bump on purpose: picking a model is not activity in the
+ * chat, and bumping it would jump the chat to the top of the sidebar. */
+ setActiveConversationModel: (model: string) => void
addMessage: (conversationId: string, message: Message) => void
insertMessageBefore: (conversationId: string, beforeId: string, message: Message) => void
insertMessagesBefore: (conversationId: string, beforeId: string, messages: Message[]) => void
@@ -188,6 +199,19 @@ export const useChatStore = create<ChatState>()(
),
})),
+ setActiveConversationModel: (model) =>
+ set((state) => {
+ const id = state.activeConversationId
+ if (!id || !model) return state
+ const open = state.conversations.find((c) => c.id === id)
+ if (!open || open.model === model) return state
+ return {
+ conversations: state.conversations.map((c) =>
+ c.id === id ? { ...c, model } : c
+ ),
+ }
+ }),
+
addMessage: (conversationId, message) =>
set((state) => ({
conversations: state.conversations.map((c) =>
diff --git a/src/stores/modelStore.ts b/src/stores/modelStore.ts
index 62f70f49..98056343 100644
--- a/src/stores/modelStore.ts
+++ b/src/stores/modelStore.ts
@@ -6,6 +6,7 @@ import { unloadLmStudioModel } from '../api/lmstudio'
import { activateBuiltinModel } from '../api/engine'
import { isLmStudioProvider } from '../lib/hf-to-provider'
import { isTauri, backendCall } from '../api/backend'
+import { useChatStore } from './chatStore'
import { log } from '../lib/logger'
export interface PullState {
@@ -94,6 +95,15 @@ export const useModelStore = create<ModelState>()(
const prev = get().activeModel
const prevModel = prev ? get().models.find((m) => m.name === prev) : undefined
set({ activeModel: name })
+ // Befund 4 of the abnahme counter-check (2026-08-29): the open chat
+ // kept the model it was created with while the wire of that same turn
+ // already carried the new one. Every path that changes the selection
+ // comes through here, so the record is written here, once. A cleared
+ // selection has nothing to write.
+ if (name) {
+ try { useChatStore.getState().setActiveConversationModel(name) }
+ catch (e) { log.warn('[modelStore] could not note the model on the open chat', { err: e }) }
+ }
if (!prev || prev === name) return
// Exactly ONE local model stays in VRAM at a time (David 2026-06-12:
// "darf niemals 2 gleichzeitig geladen sein, außer man macht Compare").