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 haengender Standby-Server haelt die Modell-Liste nicht mehr auf

purple508563350f9e
diff --git a/src/api/__tests__/a-hung-standby-server-does-not-hold-the-list.test.ts b/src/api/__tests__/a-hung-standby-server-does-not-hold-the-list.test.ts
new file mode 100644
index 00000000..7acaedde
--- /dev/null
+++ b/src/api/__tests__/a-hung-standby-server-does-not-hold-the-list.test.ts
@@ -0,0 +1,79 @@
+/**
+ * A16 counter-check follow-up 02.09.: `listStandbyBackendModels` is awaited in
+ * the middle of `fetchModels`, in front of the LU Engine rows, the Ollama rows
+ * and the whole ComfyUI inventory. A standby server that accepts the
+ * connection and then says nothing held every one of them up, on every
+ * refresh, for as long as the platform's own timeout ran.
+ *
+ * That is not an exotic server: LM Studio loading a large model off a busy
+ * disk does exactly this. The cost of giving up early is one missing heading
+ * until the next refresh; the cost of waiting is an empty Models page.
+ *
+ * Run: npx vitest run src/api/__tests__/a-hung-standby-server-does-not-hold-the-list.test.ts
+ */
+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
+
+const listModels = vi.fn()
+
+vi.mock('../providers/openai-provider', () => ({
+ OpenAIProvider: class {
+ listModels() { return listModels() }
+ },
+}))
+vi.mock('../backend', () => ({
+ isTauri: () => false, isMacOS: () => false, isWindows: () => false, isLinux: () => false,
+ backendCall: vi.fn(async () => null),
+ secretGet: vi.fn().mockRejectedValue(new Error('no vault')),
+ secretSet: vi.fn(), secretDelete: vi.fn(),
+}))
+
+const { listStandbyBackendModels, STANDBY_MODEL_LIST_TIMEOUT_MS } = await import('../lu-engine-switch')
+
+const LM_STUDIO = { name: 'LM Studio', baseUrl: 'http://localhost:1234/v1', isLocal: true }
+
+beforeEach(() => {
+ vi.useFakeTimers()
+ listModels.mockReset()
+})
+afterEach(() => { vi.useRealTimers() })
+
+describe('the standby backend asked for its models', () => {
+ it('gives up on a server that never answers, with an empty list', async () => {
+ // The hang: connected, and then nothing. Never settles on its own.
+ listModels.mockImplementation(() => new Promise(() => {}))
+
+ const asked = listStandbyBackendModels(LM_STUDIO)
+ await vi.advanceTimersByTimeAsync(STANDBY_MODEL_LIST_TIMEOUT_MS + 50)
+
+ await expect(asked, 'the model list is still waiting on a dead server').resolves.toEqual([])
+ })
+
+ it('and the list is not held up for longer than the budget', async () => {
+ listModels.mockImplementation(() => new Promise(() => {}))
+ let settled = false
+ void listStandbyBackendModels(LM_STUDIO).then(() => { settled = true })
+
+ await vi.advanceTimersByTimeAsync(STANDBY_MODEL_LIST_TIMEOUT_MS - 100)
+ expect(settled, 'it gave up before its own budget was spent').toBe(false)
+
+ await vi.advanceTimersByTimeAsync(200)
+ expect(settled, 'it was still waiting after the budget').toBe(true)
+ })
+
+ // NEGATIVE CONTROL: a server that answers in time is passed straight
+ // through. Without this the fix could be "always return nothing".
+ it('passes a real answer through untouched', async () => {
+ const rows = [{ id: 'qwen2.5-0.5b-instruct@q4_k_m', name: 'qwen2.5-0.5b-instruct@q4_k_m' }]
+ listModels.mockResolvedValue(rows)
+
+ await expect(listStandbyBackendModels(LM_STUDIO)).resolves.toEqual(rows)
+ })
+
+ // NEGATIVE CONTROL: a refused connection still rejects, exactly as before.
+ // The caller's catch is what turns that into "no rows", and swallowing it
+ // here would take a real error away from a lane that already handles it.
+ it('still throws when the server refuses outright', async () => {
+ listModels.mockRejectedValue(new Error('connection refused'))
+ await expect(listStandbyBackendModels(LM_STUDIO)).rejects.toThrow('connection refused')
+ })
+})
diff --git a/src/api/lu-engine-switch.ts b/src/api/lu-engine-switch.ts
index b708a048..c295bc41 100644
--- a/src/api/lu-engine-switch.ts
+++ b/src/api/lu-engine-switch.ts
@@ -181,6 +181,23 @@ export function handBackChatProviderForRow(row: InstalledModelLike | null | unde
return update.name ?? null
}
+/**
+ * How long the standby server gets to answer before it is treated as silent.
+ *
+ * A16 counter-check follow-up: this call is awaited in the middle of
+ * `fetchModels`, so a standby server that accepts the connection and then
+ * never answers held up the WHOLE model list, on every refresh, for as long as
+ * the platform's own timeout allowed. A local server that has hung is not an
+ * exotic case (LM Studio loading a large model on a busy disk does it), and
+ * the cost of guessing wrong here is one missing heading until the next
+ * refresh, against an empty Models page for minutes.
+ *
+ * Three seconds because the server is on this machine: `/v1/models` is a
+ * directory listing off local disk, and anything that has not answered in
+ * three seconds is not about to.
+ */
+export const STANDBY_MODEL_LIST_TIMEOUT_MS = 3_000
+
/**
* The standby backend's own model list, read straight from its server.
*
@@ -188,6 +205,10 @@ export function handBackChatProviderForRow(row: InstalledModelLike | null | unde
* keyed on the slot, and the slot is currently the LU Engine. Nothing is
* cached, so a server that has gone away since simply throws and the caller
* adds no rows, which is exactly the old behaviour.
+ *
+ * A server that hangs instead of refusing gets the same treatment after
+ * `STANDBY_MODEL_LIST_TIMEOUT_MS`: an empty list, not an error, because there
+ * is nothing here for the user to act on and the rest of the list must go up.
*/
export async function listStandbyBackendModels(occupant: SlotOccupant): Promise<ProviderModel[]> {
const client = new OpenAIProvider({
@@ -198,5 +219,17 @@ export async function listStandbyBackendModels(occupant: SlotOccupant): Promise<
apiKey: '',
isLocal: occupant.isLocal,
})
- return client.listModels()
+ let timer: ReturnType<typeof setTimeout> | undefined
+ try {
+ return await Promise.race([
+ client.listModels(),
+ new Promise<ProviderModel[]>((resolve) => {
+ timer = setTimeout(() => resolve([]), STANDBY_MODEL_LIST_TIMEOUT_MS)
+ }),
+ ])
+ } finally {
+ // Whichever side won, the timer goes. Left running it would hold this
+ // closure for three seconds after every single model refresh.
+ if (timer) clearTimeout(timer)
+ }
}