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): the models of a stopped LM Studio server leave the local list
purplea874b05fd78d
diff --git a/src/components/models/ModelSelector.tsx b/src/components/models/ModelSelector.tsxindex 5c06876c..12c124d0 100644--- a/src/components/models/ModelSelector.tsx+++ b/src/components/models/ModelSelector.tsx@@ -186,7 +186,11 @@ const LMSTUDIO_START_WAIT_MS = 30_000// One line with a state dot, a short sentence and a text button (David,// 05.10.2026). It used to be a box of three text blocks and a full-width// button, about as tall as five model rows. What the click does is unchanged.-function LmStudioStatusLine({ onStarted }: { onStarted: () => void }) {+//+// `onServerOff` tells the list below what the line knows: with the server off+// its rows cannot be picked, so they leave the list for as long as the line+// stands and come back with the server.+function LmStudioStatusLine({ onStarted, onServerOff }: { onStarted: () => void; onServerOff: (off: boolean) => void }) {const [status, setStatus] = useState<LmStudioServerStatus | null>(null)const [starting, setStarting] = useState(false)const [startError, setStartError] = useState('')@@ -203,7 +207,8 @@ function LmStudioStatusLine({ onStarted }: { onStarted: () => void }) {const refreshRef = useRef<() => Promise<void>>(async () => {})const startAsked = useRef(false)const onStartedRef = useRef(onStarted)- useEffect(() => { onStartedRef.current = onStarted }, [onStarted])+ const onServerOffRef = useRef(onServerOff)+ useEffect(() => { onStartedRef.current = onStarted; onServerOffRef.current = onServerOff }, [onStarted, onServerOff])useEffect(() => {let cancelled = falselet timer: ReturnType<typeof setTimeout> | undefined@@ -223,6 +228,9 @@ function LmStudioStatusLine({ onStarted }: { onStarted: () => void }) {// last knew and asks again.const detected = !!fresh && (fresh.lms_present || fresh.models_detected)if (!fresh && following) timer = setTimeout(() => void refresh(), LMSTUDIO_STATUS_POLL_MS)+ // Only an answer moves the list. A reopened menu keeps what the last+ // answer said until the next one is in.+ if (fresh) onServerOffRef.current(detected && !fresh.running)if (!fresh || !detected) returnfollowing = trueconst cameUp = fresh.running && wasRunning === false@@ -1243,6 +1251,8 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy// with nothing installed. Asked only while the dropdown is open and the list// is empty, and never repairs, because opening a dropdown must not boot a server.const [emptyReason, setEmptyReason] = useState('')+ // What the LM Studio line last heard from the server, see `allTextModels`.+ const [lmStudioServerOff, setLmStudioServerOff] = useState(false)useEffect(() => {if (!open || textModelsEmptyRef.current === false) returnlet cancelled = false@@ -1315,7 +1325,12 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy// FAMILY (Qwen/Gemma/Llama/…), not by provider, because users pick// models by lineage first and the backend that serves them is a// per-row badge.- const allTextModels = models.filter(m => m.type === 'text')+ // Minus the rows of an LM Studio whose server is off (Windows box,+ // 05.10.2026: "server off" stood above seven of its models for 160 s, and a+ // click on one could only fail). The pick itself is not touched.+ const allTextModels = models+ .filter((m) => m.type === 'text')+ .filter((m) => !(lmStudioServerOff && isLmStudioProvider(m.providerName)))// Code needs tools to do literally anything. A hosted model that has told us// it cannot call them is not a degraded choice there, it is a dead one, so it// does not get listed. Keep the ACTIVE model visible even if it fails the@@ -1599,7 +1614,7 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBysymptom. One line with a "Start" button. Local mode only: inCloud the list shows hosted models, and what the line promises(pick LM Studio models here) would not come true there. */}- <LmStudioStatusLine onStarted={fetchModels} />+ <LmStudioStatusLine onStarted={fetchModels} onServerOff={setLmStudioServerOff} />{/* K6: grouping threw and was caught above instead of crashing thewhole chat view. Says so, in the dropdown itself, with a waydiff --git a/src/components/models/__tests__/lmstudio-status-line.test.tsx b/src/components/models/__tests__/lmstudio-status-line.test.tsxindex a9054949..21698afa 100644--- a/src/components/models/__tests__/lmstudio-status-line.test.tsx+++ b/src/components/models/__tests__/lmstudio-status-line.test.tsx@@ -11,18 +11,24 @@* Run: npx vitest run src/components/models/__tests__/lmstudio-status-line.test.tsx*/import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'-import { createElement } from 'react'+import { createElement, type ReactNode } from 'react'import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'import type { AIModel } from '../../../types/models'import type { ProviderConfig } from '../../../api/providers/types'-const MODELS: AIModel[] = [{+const OLLAMA_ROW = {name: 'qwen3:8b', model: 'qwen3:8b', size: 0, type: 'text', provider: 'ollama', providerName: 'Ollama',-} as AIModel]+} as AIModel+const lmStudioRow = (id: string) => ({+ name: `openai::${id}`, model: id, displayName: id, size: 0, type: 'text', provider: 'openai', providerName: 'LM Studio',+} as AIModel)+const LMS_ROWS = [lmStudioRow('qwen3-4b'), lmStudioRow('gemma-3-4b-it')]+let MODELS: AIModel[] = [OLLAMA_ROW]+let ACTIVE = 'qwen3:8b'const fetchModels = vi.fn(async () => {})vi.mock('../../../hooks/useModels', () => ({- useModels: () => ({ models: MODELS, activeModel: 'qwen3:8b', setActiveModel: vi.fn(), fetchModels }),+ useModels: () => ({ models: MODELS, activeModel: ACTIVE, setActiveModel: vi.fn(), fetchModels }),}))vi.mock('../../../api/lmstudio', () => ({loadLmStudioModel: vi.fn(async () => {}),@@ -38,6 +44,12 @@ vi.mock('../../../api/ollama', () => ({const backendCall = vi.fn(async (_cmd: string): Promise<unknown> => null)vi.mock('../../../api/backend', () => ({ backendCall: (cmd: string) => backendCall(cmd), isTauri: () => false }))vi.mock('../../../api/builtin-ensure', () => ({ diagnoseBuiltinEngine: vi.fn(async () => null) }))+// A closed menu is gone at once. The exit animation never ends in jsdom, and+// the menu would stay mounted, with the line in it.+vi.mock('framer-motion', async (actual) => ({+ ...(await actual<typeof import('framer-motion')>()),+ AnimatePresence: ({ children }: { children?: ReactNode }) => children,+}))const { ModelSelector, lmStudioLineText, lmStudioStartTitle } = await import('../ModelSelector')const { useProviderStore } = await import('../../../stores/providerStore')@@ -75,6 +87,8 @@ beforeEach(() => {cleanup()backendCall.mockReset()fetchModels.mockClear()+ MODELS = [OLLAMA_ROW]+ ACTIVE = 'qwen3:8b'useModelStore.setState({ foldedRows: null, inventoryLoaded: true } as never)setSlot(slot({}))useProviderStore.setState({ engineOptedOut: false })@@ -278,3 +292,69 @@ describe('the line follows the server while the menu is open', () => {expect(statusCalls()).toBe(before)})})++// Windows box, 05.10.2026 (probe 7): the server was stopped from outside, the+// line came back after 2 to 3 s, and the seven LM Studio models stood under+// "server off" for 160 s, also after closing and reopening the menu.+describe('the models of a stopped server leave the list', () => {+ const rowNames = () => Array.from(+ screen.getByTestId('model-picker-menu').querySelectorAll('[role="button"]'),+ ).map((row) => row.textContent ?? '')+ const lmsRows = () => rowNames().filter((text) => text.includes('LM Studio'))+ const trigger = () => screen.getByLabelText('Select chat model')++ beforeEach(() => { MODELS = [OLLAMA_ROW, ...LMS_ROWS] })++ it('lists them while the server runs', async () => {+ await open(RUNNING)+ expect(lmsRows()).toHaveLength(2)+ expect(rowNames()).toHaveLength(3)+ })++ it('takes them out as soon as the line says "server off", and leaves the other rows', async () => {+ vi.useFakeTimers()+ const probe = await open(RUNNING)+ probe.setStatus(OFF)+ await act(async () => { await vi.advanceTimersByTimeAsync(1600) })+ expect(line()!.getAttribute('data-state')).toBe('off')+ expect(lmsRows()).toHaveLength(0)+ expect(rowNames()).toHaveLength(1)+ expect(rowNames()[0]).toContain('qwen3:8b')+ })++ it('keeps them out when the menu is closed and opened again', async () => {+ await open(OFF)+ expect(lmsRows()).toHaveLength(0)+ await act(async () => { fireEvent.click(trigger()) })+ expect(screen.queryByTestId('model-picker-menu')).toBeNull()+ // A new line, which knows nothing yet: the list keeps the last answer.+ await act(async () => { fireEvent.click(trigger()) })+ expect(lmsRows()).toHaveLength(0)+ expect(rowNames()).toHaveLength(1)+ })++ it('keeps the pick: the button still names the chosen LM Studio model', async () => {+ ACTIVE = LMS_ROWS[0].name+ await open(OFF)+ expect(lmsRows()).toHaveLength(0)+ expect(trigger().textContent).toContain('qwen3-4b')+ })++ it('brings them back once the server is up after Start', async () => {+ vi.useFakeTimers()+ const probe = await open(OFF)+ await act(async () => { fireEvent.click(startButton()) })+ expect(lmsRows()).toHaveLength(0)+ probe.setStatus(RUNNING)+ await act(async () => { await vi.advanceTimersByTimeAsync(1600) })+ expect(line()).toBeNull()+ expect(lmsRows()).toHaveLength(2)+ })++ it('says the list is empty when LM Studio had the only models', async () => {+ MODELS = [...LMS_ROWS]+ await open(OFF)+ expect(rowNames()).toHaveLength(0)+ expect(screen.getByTestId('model-picker-menu').textContent).toContain('No models available')+ })+})