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): der zweite schnelle Klick bekommt seinen Hinweis wirklich zu sehen
purplec090571c0999
diff --git a/src/api/lu-engine-switch.ts b/src/api/lu-engine-switch.tsindex f25c263d..8c8c866c 100644--- a/src/api/lu-engine-switch.ts+++ b/src/api/lu-engine-switch.ts@@ -16,6 +16,8 @@* one the user already knows.*/+import { useLuEngineSwitchStore } from '../stores/luEngineSwitchStore'+import { luEngineSwapInFlight } from './lu-engine-swap-lock'import { useProviderStore } from '../stores/providerStore'import { PROVIDER_PRESETS } from './providers/types'import { slotTakeoverUpdate } from '../lib/openai-slot-handover'@@ -35,6 +37,24 @@ export const LU_ENGINE_SWITCH_NOTE = 'Switched your chat provider to the LU Engi*/export const LU_ENGINE_SWAP_BUSY_NOTE = 'The LU Engine is still switching, one moment.'+/**+ * Say it, from whichever door was blocked.+ *+ * A16 (A14-6): the Windows counter-check clicked two LU Engine tiles 150 ms+ * apart and reported that the second click vanished without a word. Two things+ * were behind that. The composer's picker checked its own `selectingLms` first+ * and returned in silence BEFORE it ever reached the bolt that has this+ * sentence, so on that door the line could not appear at all. And the line, on+ * the door where it did appear, was on the ordinary twelve second clock, so it+ * could be gone again while the swap it describes was still running, which is+ * exactly the moment someone looks.+ *+ * One call for both doors now, and the line stands while the swap does.+ */+export function announceLuEngineSwapBusy(): void {+ useLuEngineSwitchStore.getState().announce(LU_ENGINE_SWAP_BUSY_NOTE, 'info', luEngineSwapInFlight)+}+/*** The reason behind an `activateBuiltinModel` that answered false.*diff --git a/src/components/models/ModelSelector.tsx b/src/components/models/ModelSelector.tsxindex c8830bca..6c5ea01d 100644--- a/src/components/models/ModelSelector.tsx+++ b/src/components/models/ModelSelector.tsx@@ -21,7 +21,8 @@ import { cloudTeaserModels } from '../../lib/cloud-teaser-models'import { splitLuEngineRows, needsLuEngineHeading, LU_ENGINE_GROUP } from '../../lib/lu-engine-rows'import { isBuiltinEngineEntry, type InstalledModelLike } from '../../lib/lmstudio-match'import {- ensureLuEngineIsChatProvider, LU_ENGINE_SWITCH_NOTE, LU_ENGINE_SWAP_BUSY_NOTE, luEngineStartFailureNote,+ ensureLuEngineIsChatProvider, LU_ENGINE_SWITCH_NOTE, LU_ENGINE_SWAP_BUSY_NOTE,+ announceLuEngineSwapBusy, luEngineStartFailureNote,} from '../../api/lu-engine-switch'import { tryAcquireLuEngineSwap, releaseLuEngineSwap } from '../../api/lu-engine-swap-lock'import { useLuEngineSwitchStore } from '../../stores/luEngineSwitchStore'@@ -741,15 +742,26 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy// first and says so.if ((isManagedBuiltinActive() && getProviderIdFromModel(model.name) === 'openai')|| isBuiltinEngineEntry(model as unknown as InstalledModelLike)) {- if (selectingLms || togglingLms) return// A14 fourth review: `selectingLms` is this component's own state and it// only ever knew about this dropdown, while the Installed card had a// bolt of its own that only ever knew about the card. Two doors into one// llama-server, and a pick here while a card swap is running sent the// second swap_bundled_model at a process the first was still restarting.// Both doors share one bolt now (api/lu-engine-swap-lock), and a blocked- // pick says so in the dropdown's own line instead of doing nothing.- if (!tryAcquireLuEngineSwap()) {+ // pick says so instead of doing nothing.+ //+ // A16 (A14-6): it did not, on this door. `if (selectingLms ||+ // togglingLms) return` stood one line ABOVE the bolt and returned in+ // total silence, so the second quick pick never reached the sentence+ // written for it. The three conditions are one condition, "something is+ // already going on", and they get one answer. The order matters: the+ // bolt is only asked for, and therefore only taken, when the first two+ // are clear.+ if (selectingLms || togglingLms || !tryAcquireLuEngineSwap()) {+ // Both places, because they outlive different things: the dropdown+ // line dies when the dropdown closes, the standing row above the+ // composer survives that and is where the card writes too.+ announceLuEngineSwapBusy()setSelectError(LU_ENGINE_SWAP_BUSY_NOTE)return}diff --git a/src/hooks/__tests__/installed-card-click-switches-the-backend.test.ts b/src/hooks/__tests__/installed-card-click-switches-the-backend.test.tsindex 2683fd92..9cc29fa2 100644--- a/src/hooks/__tests__/installed-card-click-switches-the-backend.test.ts+++ b/src/hooks/__tests__/installed-card-click-switches-the-backend.test.ts@@ -328,7 +328,11 @@ describe('the bolt is shared with the composer picker', () => {'utf8',)expect(src).toContain("from '../../api/lu-engine-swap-lock'")- expect(src).toContain('if (!tryAcquireLuEngineSwap()) {')+ // A16: the picker's own in-flight state and the shared bolt are one+ // condition now, with the bolt asked last so it is only taken when the+ // other two are clear.+ expect(src).toContain('if (selectingLms || togglingLms || !tryAcquireLuEngineSwap()) {')+ expect(src, 'and a blocked pick says so on both surfaces').toContain('announceLuEngineSwapBusy()')expect(src, 'and gives it back in a finally').toContain('releaseLuEngineSwap()')})})diff --git a/src/hooks/__tests__/the-second-quick-click-says-something.test.ts b/src/hooks/__tests__/the-second-quick-click-says-something.test.tsnew file mode 100644index 00000000..a12577fb--- /dev/null+++ b/src/hooks/__tests__/the-second-quick-click-says-something.test.ts@@ -0,0 +1,179 @@+/**+ * @vitest-environment jsdom+ *+ * A16 (A14-6), Windows counter-check 02.09.: two LU Engine tiles clicked+ * 150 ms apart. Exactly one engine started, which is the point of the bolt and+ * was right. The second click, though, "verpufft ohne jede Rueckmeldung": no+ * queue, no line, nothing. Round 5 had written a sentence for exactly this+ * ("The LU Engine is still switching, one moment.") and the counter-check+ * never saw it.+ *+ * Two reasons, and both are fixed here.+ *+ * 1. The composer's picker never reached the sentence at all. One line above+ * the bolt sat `if (selectingLms || togglingLms) return`, a silent early+ * return on the component's own in-flight state, so on that door a quick+ * second pick fell out before anything could be said.+ *+ * 2. On the door where the line WAS written, the Installed tile, it was on+ * the ordinary twelve second clock. A cold multi-gigabyte GGUF outlives+ * that, so the line could clear itself while the swap it describes was+ * still running, leaving behind the same silence that made the user click+ * twice. It stands while the swap does now.+ *+ * Run: npx vitest run src/hooks/__tests__/the-second-quick-click-says-something.test.ts+ */+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'+import { renderHook, act } from '@testing-library/react'++const activateBuiltinModel = vi.fn(async () => true)++vi.mock('../../api/backend', () => ({+ isTauri: () => true, isMacOS: () => false, isWindows: () => true, isLinux: () => false,+ backendCall: vi.fn(async () => null),+ secretGet: vi.fn().mockRejectedValue(new Error('no vault')),+ secretSet: vi.fn(), secretDelete: vi.fn(),+}))+vi.mock('../../api/comfyui', () => ({+ getInstalledImageModels: vi.fn(async () => []),+ getInstalledVideoModels: vi.fn(async () => []),+ checkComfyConnection: vi.fn(async () => false),+ readModelDiskSizes: vi.fn(async () => new Map()),+}))+vi.mock('../../api/ollama', () => ({+ listModels: vi.fn(async () => []), unloadModel: vi.fn(async () => undefined),+ pullModel: vi.fn(), pullModelTauri: vi.fn(), deleteModel: vi.fn(), showModel: vi.fn(),+}))+vi.mock('../../api/providers', async () => {+ const actual = await vi.importActual<typeof import('../../api/providers')>('../../api/providers')+ return { ...actual, getEnabledProviders: () => [] }+})+vi.mock('../../api/engine', async () => {+ const actual = await vi.importActual<typeof import('../../api/engine')>('../../api/engine')+ return {+ ...actual,+ listBundledModels: vi.fn(async () => []),+ isManagedBuiltinActive: () => true,+ bundledEngineStatus: vi.fn(async () => ({ running: true, healthy: true, port: 8127 })),+ bundledEmbedStatus: vi.fn(async () => ({ running: true, healthy: true, port: 8128 })),+ startBundledEmbed: vi.fn(),+ activateBuiltinModel: (...a: unknown[]) => activateBuiltinModel(...(a as [])),+ }+})++const { useModels } = await import('../useModels')+const { useModelStore } = await import('../../stores/modelStore')+const { useProviderStore } = await import('../../stores/providerStore')+const { useLuEngineSwitchStore, LU_ENGINE_SWITCH_NOTE_MS } = await import('../../stores/luEngineSwitchStore')+const { LU_ENGINE_SWAP_BUSY_NOTE } = await import('../../api/lu-engine-switch')+const { __resetLuEngineSwapLockForTests } = await import('../../api/lu-engine-swap-lock')++// The two tiles the counter-check clicked, in the state it clicked them in:+// the LU Engine already holds the chat, so the first click has nothing to+// announce and the only line that can appear is the one for the second.+const FIRST = 'openai::Phi-4-mini-instruct-Q4_K_M'+const SECOND = 'openai::mlabonne_gemma-3-4b-it-abliterated-Q4_K_M'++/** The gap the counter-check used between the two clicks. */+const CLICK_GAP_MS = 150++beforeEach(() => {+ vi.useFakeTimers()+ activateBuiltinModel.mockReset()+ activateBuiltinModel.mockResolvedValue(true)+ useLuEngineSwitchStore.setState({ note: null, tone: 'info', generation: 0 })+ __resetLuEngineSwapLockForTests()+ useProviderStore.getState().resetProvidersToDefaults()+ useProviderStore.getState().setProviderConfig('openai', {+ enabled: true, managed: true, name: 'LU Engine', baseUrl: 'http://127.0.0.1:8127/v1',+ })+ useModelStore.setState({+ models: [+ { name: FIRST, model: 'Phi-4-mini-instruct-Q4_K_M', size: 1, type: 'text', provider: 'openai', providerName: 'LU Engine' },+ { name: SECOND, model: 'mlabonne_gemma-3-4b-it-abliterated-Q4_K_M', size: 1, type: 'text', provider: 'openai', providerName: 'LU Engine' },+ ] as never,+ activeModel: FIRST,+ })+})+afterEach(() => { vi.useRealTimers(); __resetLuEngineSwapLockForTests() })++describe('two LU Engine tiles clicked 150 ms apart', () => {+ it('tells the user the second one is waiting, not broken', async () => {+ // A swap that does not finish on its own: exactly the window the second+ // click lands in.+ let release: (v: boolean) => void = () => {}+ activateBuiltinModel.mockImplementation(() => new Promise<boolean>((r) => { release = r }))++ const { result } = renderHook(() => useModels())+ await act(async () => { void result.current.setActiveModel(FIRST) })+ expect(useLuEngineSwitchStore.getState().note, 'the first click had nothing to report').toBeNull()++ await act(async () => { await vi.advanceTimersByTimeAsync(CLICK_GAP_MS) })+ await act(async () => { void result.current.setActiveModel(SECOND) })++ expect(useLuEngineSwitchStore.getState().note).toBe(LU_ENGINE_SWAP_BUSY_NOTE)+ expect(useLuEngineSwitchStore.getState().tone, 'a wait is not a failure').toBe('info')+ // And the bolt did its own job: one swap, on the first tile.+ expect(activateBuiltinModel).toHaveBeenCalledTimes(1)+ expect(activateBuiltinModel).toHaveBeenCalledWith(FIRST)++ await act(async () => { release(true); await Promise.resolve() })+ })++ it('leaves the line standing while the swap it describes is still running', async () => {+ // The counter-check's screenshot of this case shows no line at all. A+ // multi-gigabyte GGUF loading off a cold disk outlives the twelve seconds+ // an info line normally gets, and a sentence that says "still switching"+ // must not leave before the switching does.+ let release: (v: boolean) => void = () => {}+ activateBuiltinModel.mockImplementation(() => new Promise<boolean>((r) => { release = r }))++ const { result } = renderHook(() => useModels())+ await act(async () => { void result.current.setActiveModel(FIRST) })+ await act(async () => { await vi.advanceTimersByTimeAsync(CLICK_GAP_MS) })+ await act(async () => { void result.current.setActiveModel(SECOND) })++ await act(async () => { await vi.advanceTimersByTimeAsync(LU_ENGINE_SWITCH_NOTE_MS * 2) })+ expect(+ useLuEngineSwitchStore.getState().note,+ 'the line walked off while the swap was still going',+ ).toBe(LU_ENGINE_SWAP_BUSY_NOTE)++ // NEGATIVE CONTROL in the same frame: it is a hold, not a line that never+ // goes away. Once the swap is done it clears on the normal clock.+ await act(async () => { release(true); await Promise.resolve(); await Promise.resolve() })+ await act(async () => { await vi.advanceTimersByTimeAsync(LU_ENGINE_SWITCH_NOTE_MS + 100) })+ expect(useLuEngineSwitchStore.getState().note, 'the line never left').toBeNull()+ })++ // NEGATIVE CONTROL: a single click still says nothing when there is nothing+ // to say. Otherwise the fix would be a line on every pick.+ it('says nothing at all when only one tile is clicked', async () => {+ const { result } = renderHook(() => useModels())+ await act(async () => { await result.current.setActiveModel(SECOND) })+ expect(useLuEngineSwitchStore.getState().note).toBeNull()+ expect(useModelStore.getState().activeModel).toBe(SECOND)+ })++ // The picker has no render harness (see model-selector-lms.test.ts), so its+ // half is pinned by reading the source. The weaker proof, and labelled as+ // such: it catches the silent early return coming back, not a picker that+ // fails to render.+ it('and the composer picker no longer drops the second pick in silence', async () => {+ const { readFileSync } = await import('node:fs')+ const { resolve, dirname } = await import('node:path')+ const { fileURLToPath } = await import('node:url')+ const src = readFileSync(+ resolve(dirname(fileURLToPath(import.meta.url)), '../../components/models/ModelSelector.tsx'),+ 'utf8',+ )+ // The LU Engine branch: one condition, one answer, and the bolt asked last+ // so a blocked pick does not take it.+ expect(src).toContain('if (selectingLms || togglingLms || !tryAcquireLuEngineSwap()) {')+ expect(src, 'and it says so on the standing row, not only in the dropdown')+ .toContain('announceLuEngineSwapBusy()')+ // The shape that hid the sentence: a bare `return` on the component's own+ // in-flight state, above the bolt.+ expect(src, 'the silent early return is back').not.toContain('if (selectingLms || togglingLms) return\n // A14 fourth review')+ })+})diff --git a/src/hooks/useModels.ts b/src/hooks/useModels.tsindex 7185311c..8043779a 100644--- a/src/hooks/useModels.ts+++ b/src/hooks/useModels.ts@@ -19,8 +19,8 @@ import { commandIsUnavailable } from '../lib/engine-command-availability'import { dropDuplicateLuEngineRows } from '../lib/lu-engine-rows'import { isBuiltinEngineEntry, type InstalledModelLike } from '../lib/lmstudio-match'import {- ensureLuEngineIsChatProvider, LU_ENGINE_SWITCH_NOTE, LU_ENGINE_FILE_GONE, LU_ENGINE_SWAP_BUSY_NOTE,- luEngineStartFailureNote,+ ensureLuEngineIsChatProvider, LU_ENGINE_SWITCH_NOTE, LU_ENGINE_FILE_GONE,+ announceLuEngineSwapBusy, luEngineStartFailureNote,} from '../api/lu-engine-switch'import { tryAcquireLuEngineSwap, releaseLuEngineSwap } from '../api/lu-engine-swap-lock'import { useLuEngineSwitchStore } from '../stores/luEngineSwitchStore'@@ -533,7 +533,7 @@ export function useModels() {// And it says so. The click used to return in silence, which reads as a// dead button and gets clicked again.if (!tryAcquireLuEngineSwap()) {- useLuEngineSwitchStore.getState().announce(LU_ENGINE_SWAP_BUSY_NOTE)+ announceLuEngineSwapBusy()return Promise.resolve()}switched = ensureLuEngineIsChatProvider()diff --git a/src/stores/luEngineSwitchStore.ts b/src/stores/luEngineSwitchStore.tsindex 77b24345..331bcc6f 100644--- a/src/stores/luEngineSwitchStore.ts+++ b/src/stores/luEngineSwitchStore.ts@@ -36,7 +36,7 @@ interface LuEngineSwitchState {/** Bumped on every announcement, so a timer belonging to an older one cannot* clear a newer line. Same reason the slot-eviction timer keeps one. */generation: number- announce: (note: string, tone?: LuEngineNoteTone) => void+ announce: (note: string, tone?: LuEngineNoteTone, holdWhile?: () => boolean) => voiddismiss: () => void}@@ -58,7 +58,7 @@ export const useLuEngineSwitchStore = create<LuEngineSwitchState>((set, get) =>note: null,tone: 'info',generation: 0,- announce: (note, tone = 'info') => {+ announce: (note, tone = 'info', holdWhile) => {cancelPending()const generation = get().generation + 1set({ note, tone, generation })@@ -73,10 +73,23 @@ export const useLuEngineSwitchStore = create<LuEngineSwitchState>((set, get) =>// So an error stands until it is dismissed by hand or replaced by the next// announcement, and the bar carries a Dismiss button for exactly that.if (tone === 'error') return- pending = setTimeout(() => {- pending = null- if (get().generation === generation) set({ note: null, tone: 'info' })- }, LU_ENGINE_SWITCH_NOTE_MS)+ // A16 (A14-6): some info lines describe a condition rather than an event,+ // and "The LU Engine is still switching, one moment." is one of them. A+ // cold GGUF of a few gigabytes takes longer to load than the twelve+ // seconds this timer allows, so the sentence could walk off the screen+ // while the thing it describes was still going on, and the user who came+ // back to look found the same nothing that made him click twice in the+ // first place. `holdWhile` keeps such a line standing for as long as its+ // condition holds, and it then clears on the normal clock afterwards.+ const arm = () => {+ pending = setTimeout(() => {+ pending = null+ if (get().generation !== generation) return+ if (holdWhile?.()) { arm(); return }+ set({ note: null, tone: 'info' })+ }, LU_ENGINE_SWITCH_NOTE_MS)+ }+ arm()},dismiss: () => {cancelPending()