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(models): ein blockierter Klick nennt die Wartezeit, in der er wirklich steht

purple3da47b1be3d5
diff --git a/src/api/__tests__/a-blocked-pick-names-the-right-wait.test.ts b/src/api/__tests__/a-blocked-pick-names-the-right-wait.test.ts
new file mode 100644
index 00000000..0a73d3cf
--- /dev/null
+++ b/src/api/__tests__/a-blocked-pick-names-the-right-wait.test.ts
@@ -0,0 +1,98 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * A16 counter-check follow-up 02.09.: the composer's picker answers a blocked
+ * LU Engine pick with one sentence, and one of the three conditions it asks
+ * about is not about our engine at all.
+ *
+ * if (selectingLms || togglingLms || !tryAcquireLuEngineSwap())
+ *
+ * The first two are the picker's own in-flight state and are also set while LM
+ * STUDIO warms a model of its own. "The LU Engine is still switching, one
+ * moment." was then a sentence about something that was not happening, and the
+ * person who read it went looking for an engine swap he never started.
+ *
+ * The bolt is what knows whether a swap of ours is running, so it decides
+ * which of the two waits the user is actually in.
+ *
+ * Run: npx vitest run src/api/__tests__/a-blocked-pick-names-the-right-wait.test.ts
+ */
+import { describe, it, expect, beforeEach, afterEach } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { resolve, dirname } from 'node:path'
+import { fileURLToPath } from 'node:url'
+
+const {
+ LU_ENGINE_SWAP_BUSY_NOTE, announceLuEngineSwapBusy,
+ LM_STUDIO_LOAD_BUSY_NOTE, announceLmStudioLoadBusy,
+} = await import('../lu-engine-switch')
+const { useLuEngineSwitchStore, LU_ENGINE_SWITCH_NOTE_MS } = await import('../../stores/luEngineSwitchStore')
+const { __resetLuEngineSwapLockForTests, tryAcquireLuEngineSwap } = await import('../lu-engine-swap-lock')
+
+function note() { return useLuEngineSwitchStore.getState().note }
+
+beforeEach(() => {
+ useLuEngineSwitchStore.setState({ note: null, tone: 'info', generation: 0 })
+ __resetLuEngineSwapLockForTests()
+})
+afterEach(() => {
+ useLuEngineSwitchStore.getState().dismiss()
+ __resetLuEngineSwapLockForTests()
+})
+
+describe('the sentence a blocked pick gets', () => {
+ it('names LM Studio when LM Studio is the one loading', () => {
+ announceLmStudioLoadBusy()
+ expect(note()).toBe('LM Studio is still loading a model, one moment.')
+ expect(note(), 'it still blames the LU Engine').not.toBe(LU_ENGINE_SWAP_BUSY_NOTE)
+ expect(useLuEngineSwitchStore.getState().tone, 'a wait is not a failure').toBe('info')
+ })
+
+ it('and the two sentences are not the same sentence', () => {
+ expect(LM_STUDIO_LOAD_BUSY_NOTE).not.toBe(LU_ENGINE_SWAP_BUSY_NOTE)
+ expect(LM_STUDIO_LOAD_BUSY_NOTE.toLowerCase()).not.toContain('lu engine')
+ })
+
+ // NEGATIVE CONTROL: the LU Engine line is untouched, holdWhile included. It
+ // is the one that has to outlive a cold GGUF load (A14-6).
+ it('leaves the LU Engine line saying what it always said', () => {
+ tryAcquireLuEngineSwap()
+ announceLuEngineSwapBusy()
+ expect(note()).toBe(LU_ENGINE_SWAP_BUSY_NOTE)
+ })
+
+ // 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 one sentence for both waits coming back, not a picker
+ // that fails to render.
+ it('and the picker asks the bolt which of the two waits it is in', () => {
+ const src = readFileSync(
+ resolve(dirname(fileURLToPath(import.meta.url)), '../../components/models/ModelSelector.tsx'),
+ 'utf8',
+ )
+ // The condition from A14-6 is unchanged: one condition, one answer, bolt
+ // asked last so a blocked pick does not take it.
+ expect(src).toContain('if (selectingLms || togglingLms || !tryAcquireLuEngineSwap()) {')
+ // And inside it, the split. `luEngineSwapInFlight()` is the only thing
+ // that can tell an LM Studio load from a swap of ours.
+ expect(src, 'the picker still says one sentence for both waits')
+ .toContain('if ((selectingLms || togglingLms) && !luEngineSwapInFlight()) {')
+ expect(src).toContain('announceLmStudioLoadBusy()')
+ expect(src).toContain('announceLuEngineSwapBusy()')
+ })
+
+ // NEGATIVE CONTROL: the LM Studio line is on the ordinary clock. It
+ // describes a condition the picker holds in component state, which this
+ // module cannot watch, so a hold here would be a line that never leaves.
+ it('lets the LM Studio line clear itself', async () => {
+ const { vi } = await import('vitest')
+ vi.useFakeTimers()
+ try {
+ announceLmStudioLoadBusy()
+ await vi.advanceTimersByTimeAsync(LU_ENGINE_SWITCH_NOTE_MS + 100)
+ expect(note(), 'the line never left').toBeNull()
+ } finally {
+ vi.useRealTimers()
+ }
+ })
+})
diff --git a/src/api/lu-engine-switch.ts b/src/api/lu-engine-switch.ts
index c295bc41..cee9ebde 100644
--- a/src/api/lu-engine-switch.ts
+++ b/src/api/lu-engine-switch.ts
@@ -62,6 +62,28 @@ export function announceLuEngineSwapBusy(): void {
useLuEngineSwitchStore.getState().announce(LU_ENGINE_SWAP_BUSY_NOTE, 'info', luEngineSwapInFlight)
}
+/**
+ * The other wait behind the same blocked pick.
+ *
+ * A16 counter-check follow-up: the picker answers "something is already going
+ * on" with one sentence, and one of the three conditions it asks about is not
+ * about our engine at all. `selectingLms` / `togglingLms` with no LU Engine
+ * swap running is LM Studio warming a model of its own, and telling the user
+ * that "The LU Engine is still switching" then describes something that is not
+ * happening. Someone who reads it goes looking for an engine swap he never
+ * started.
+ *
+ * No `holdWhile` here: the condition it describes lives in the picker's own
+ * component state, which this module cannot see, and an LM Studio load is a
+ * request over a socket rather than a cold GGUF off disk, so the ordinary
+ * twelve second clock is the right length for it.
+ */
+export const LM_STUDIO_LOAD_BUSY_NOTE = 'LM Studio is still loading a model, one moment.'
+
+export function announceLmStudioLoadBusy(): void {
+ useLuEngineSwitchStore.getState().announce(LM_STUDIO_LOAD_BUSY_NOTE, 'info')
+}
+
/**
* The reason behind an `activateBuiltinModel` that answered false.
*
diff --git a/src/components/models/ModelSelector.tsx b/src/components/models/ModelSelector.tsx
index 37aa1e78..a87ebcba 100644
--- a/src/components/models/ModelSelector.tsx
+++ b/src/components/models/ModelSelector.tsx
@@ -23,9 +23,10 @@ import { isBuiltinEngineEntry, type InstalledModelLike } from '../../lib/lmstudi
import {
ensureLuEngineIsChatProvider, LU_ENGINE_SWITCH_NOTE, LU_ENGINE_SWAP_BUSY_NOTE,
announceLuEngineSwapBusy, luEngineStartFailureNote,
+ LM_STUDIO_LOAD_BUSY_NOTE, announceLmStudioLoadBusy,
handBackChatProviderForRow, chatProviderSwitchNote,
} from '../../api/lu-engine-switch'
-import { tryAcquireLuEngineSwap, releaseLuEngineSwap } from '../../api/lu-engine-swap-lock'
+import { tryAcquireLuEngineSwap, releaseLuEngineSwap, luEngineSwapInFlight } from '../../api/lu-engine-swap-lock'
import { useLuEngineSwitchStore } from '../../stores/luEngineSwitchStore'
import type { AIModel } from '../../types/models'
@@ -769,9 +770,20 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
// 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.
+ // A16 counter-check follow-up: one condition, but not one wait. The
+ // first two flags are this component's own state and are also set
+ // while LM STUDIO loads a model, which has nothing to do with our
+ // engine. The bolt is what says a swap of ours is running, so it
+ // decides which of the two sentences is true.
+ //
+ // Both places in either case, 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.
+ if ((selectingLms || togglingLms) && !luEngineSwapInFlight()) {
+ announceLmStudioLoadBusy()
+ setSelectError(LM_STUDIO_LOAD_BUSY_NOTE)
+ return
+ }
announceLuEngineSwapBusy()
setSelectError(LU_ENGINE_SWAP_BUSY_NOTE)
return