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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(models): swap the built-in engine when a different gguf is picked on the Models page
purple72bb2f2a24f5
diff --git a/src/api/__tests__/engine.test.ts b/src/api/__tests__/engine.test.tsindex ef6b3ddb..118d38b4 100644--- a/src/api/__tests__/engine.test.ts+++ b/src/api/__tests__/engine.test.ts@@ -142,12 +142,17 @@ describe('activateBuiltinModel', () => {expect(await activateBuiltinModel('qwen')).toBe(true)})- it('no-ops when the path is unknown', async () => {+ it('refreshes the listing once for an unknown name, then no-ops without a swap', async () => {vi.mocked(backendCall).mockResolvedValue({ dir: '/m', models: [] } as never)await listBundledModels()vi.mocked(backendCall).mockClear()const ok = await activateBuiltinModel('openai::ghost')expect(ok).toBe(false)- expect(backendCall).not.toHaveBeenCalled()+ // A caller may run before any listing populated the map (Models-page →+ // store chokepoint), so ONE refresh is expected — but never a swap for a+ // name that stays unknown.+ expect(backendCall).toHaveBeenCalledTimes(1)+ expect(backendCall).toHaveBeenCalledWith('list_bundled_models')+ expect(backendCall).not.toHaveBeenCalledWith('swap_bundled_model', expect.anything())})})diff --git a/src/api/engine.ts b/src/api/engine.tsindex 90f82665..4d3b21a6 100644--- a/src/api/engine.ts+++ b/src/api/engine.ts@@ -176,7 +176,13 @@ export function bundledToAIModels(models: BundledModel[]): CloudModel[] {*/export async function activateBuiltinModel(nameOrPrefixed: string, tuning?: BuiltinEngineTuning): Promise<boolean> {const name = nameOrPrefixed.includes('::') ? nameOrPrefixed.split('::')[1] : nameOrPrefixed- const path = pathByName.get(name)+ let path = pathByName.get(name)+ if (!path) {+ // Callers outside the picker (Models page via the store chokepoint) can+ // run before any listBundledModels() populated the map — refresh once.+ await listBundledModels().catch(() => undefined)+ path = pathByName.get(name)+ }if (!path) return falseawait swapBundledModel(path, tuning)return truediff --git a/src/stores/__tests__/modelStore-builtin-vram.test.ts b/src/stores/__tests__/modelStore-builtin-vram.test.tsindex bad88ca4..2d099b65 100644--- a/src/stores/__tests__/modelStore-builtin-vram.test.ts+++ b/src/stores/__tests__/modelStore-builtin-vram.test.ts@@ -53,10 +53,26 @@ describe('modelStore.setActiveModel — built-in engine VRAM exclusion (2.5.7)',expect(backendCall).toHaveBeenCalledWith('stop_bundled_engine')})- it('does NOT stop the engine on built-in → built-in (that is an in-place swap)', () => {+ it('built-in → built-in swaps the engine to the picked gguf instead of stopping it', async () => {+ // llama-server serves exactly ONE gguf and ignores the request's model+ // field, and the send-path self-heal only revives a DEAD server — so the+ // store itself must dispatch the swap, or a pick on the Models page keeps+ // every chat silently answering from the OLD model.+ backendCall.mockImplementation(async (...a: unknown[]) => {+ if (a[0] === 'list_bundled_models') {+ return { dir: '/m', models: [{ name: 'qwenB', path: '/m/qwenB.gguf', size: 1, loaded: false }] }+ }+ return {}+ })useModelStore.getState().setActiveModel('openai::qwenA')useModelStore.getState().setActiveModel('openai::qwenB')expect(backendCall).not.toHaveBeenCalledWith('stop_bundled_engine')+ await vi.waitFor(() => {+ expect(backendCall).toHaveBeenCalledWith(+ 'swap_bundled_model',+ expect.objectContaining({ modelPath: '/m/qwenB.gguf' }),+ )+ })})it('still unloads the previous Ollama model on Ollama → built-in (no regression)', () => {diff --git a/src/stores/modelStore.ts b/src/stores/modelStore.tsindex 52e109be..63f952ed 100644--- a/src/stores/modelStore.ts+++ b/src/stores/modelStore.ts@@ -3,6 +3,7 @@ import { persist } from 'zustand/middleware'import type { AIModel, PullProgress, ModelCategory } from '../types/models'import { unloadModel } from '../api/ollama'import { unloadLmStudioModel } from '../api/lmstudio'+import { activateBuiltinModel } from '../api/engine'import { isLmStudioProvider } from '../lib/hf-to-provider'import { isTauri, backendCall } from '../api/backend'import { log } from '../lib/logger'@@ -96,9 +97,6 @@ export const useModelStore = create<ModelState>()(log.warn('[modelStore] failed to unload previous LM Studio model', { model: prev, err: e }),)} else if (prevIsBuiltin) {- // built-in → built-in is a swap (activateBuiltinModel handles it on- // the same port), so only stop the engine when the NEXT model is not- // itself a built-in GGUF.const nextModel = get().models.find((m) => m.name === name)const nextIsBuiltin =!!nextModel && 'providerName' in nextModel && nextModel.providerName === 'Built-in Engine'@@ -106,6 +104,17 @@ export const useModelStore = create<ModelState>()(backendCall('stop_bundled_engine').catch((e) =>log.warn('[modelStore] failed to stop built-in engine on switch-away', { err: e }),)+ } else {+ // built-in → DIFFERENT built-in: llama-server serves exactly ONE+ // gguf and ignores the request's model field, and the send-path+ // self-heal only revives a DEAD server — so without a swap right+ // here, a pick on the Models page would keep every chat silently+ // answering from the OLD model. The composer picker awaits this+ // same call itself before setting the store; Rust's argv+ // idempotence turns that double-swap into a no-op.+ activateBuiltinModel(name).catch((e) =>+ log.warn('[modelStore] failed to swap built-in engine to the picked model', { model: name, err: e }),+ )}} else if (!prev.includes('::')) {unloadModel(prev).catch((e) =>