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): Unload all models frees every engine, not only Ollama (#235)

purplecba553c82ea9
diff --git a/src/components/models/ModelSelector.tsx b/src/components/models/ModelSelector.tsx
index f5b0b412..28b749c4 100644
--- a/src/components/models/ModelSelector.tsx
+++ b/src/components/models/ModelSelector.tsx
@@ -10,7 +10,7 @@ import { useProviderStore } from '../../stores/providerStore'
import { useSettingsStore } from '../../stores/settingsStore'
import { useUIStore } from '../../stores/uiStore'
import {
- unloadAllModels, loadModel, unloadModelAndLook, readLoadedModels, readRunningModels, modelsAheadOfLoad,
+ loadModel, unloadModelAndLook, readLoadedModels, readRunningModels, modelsAheadOfLoad,
} from '../../api/ollama'
import {
ollamaSwitchState, waitingForSentence, stillBusySentence, switchFailedSentence,
@@ -41,6 +41,7 @@ import {
lmStudioGoneMark, lmStudioWentAfter,
} from '../../lib/lmstudio-ended-loads'
import { isLmStudioProvider } from '../../lib/hf-to-provider'
+import { unloadEverything, unloadProblems, unloadedNames } from '../../lib/unload-everything'
import { detailOf } from '../../lib/error-text'
import { lmStudioSlotUpdate, adoptionReplacesBuiltinEngine } from '../../lib/lmstudio-backend-adopt'
import { nextProbeDelayMs } from '../../lib/probe-backoff'
@@ -1296,7 +1297,9 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
/**
* "Unload all models". It stays available while a load is pending and ends
* that load first: the load would bring its model in right after the unload.
- * It says "Unloaded" only when /api/ps is empty of what was loaded.
+ * GH #235 follow-up: it frees every engine, not only Ollama (Ollama, the LU
+ * Engine, LM Studio, ComfyUI's memory; lib/unload-everything.ts), and says
+ * per engine what did not go. "Unloaded" only when nothing was left.
*/
const unloadAllOllama = async () => {
if (unloading) return
@@ -1306,19 +1309,24 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
ollamaRunAbort.current?.abort()
yieldSilentLocalRuns()
try {
- const result = await unloadAllModels()
- setOllamaLoaded(new Set([...result.stillBusy, ...result.failed]))
- if (result.failed.length > 0) {
- setOllamaNote({ text: switchFailedSentence('unload', result.failed.map(ollamaLabel).join(', '), { timedOut: false }), tone: 'error' })
- } else if (result.stillBusy.length > 0) {
- setOllamaNote({ text: stillBusySentence(result.stillBusy.map(ollamaLabel)), tone: 'info' })
- } else {
+ const { outcomes, ollama } = await unloadEverything({ ollama: hasOllamaModels, lmstudio: hasLmStudioRows })
+ if (ollama) {
+ setOllamaLoaded(new Set([...ollama.stillBusy, ...ollama.failed]))
+ if (ollama.failed.length > 0) {
+ setOllamaNote({ text: switchFailedSentence('unload', ollama.failed.map(ollamaLabel).join(', '), { timedOut: false }), tone: 'error' })
+ } else if (ollama.stillBusy.length > 0) {
+ setOllamaNote({ text: stillBusySentence(ollama.stillBusy.map(ollamaLabel)), tone: 'info' })
+ }
+ }
+ if (outcomes.some((o) => o.engine === 'lmstudio' && o.freed)) setLmsLoaded([], lmStudioGoneMark())
+ const others = unloadProblems(outcomes.filter((o) => o.engine !== 'ollama' || !ollama))
+ log.info('[picker] "Unload all models"', { freed: unloadedNames(outcomes) })
+ if (others) {
+ setOllamaNote({ text: others, tone: 'error' })
+ } else if (!outcomes.some((o) => o.problem)) {
setUnloadDone(true)
setTimeout(() => setUnloadDone(false), 2000)
}
- } catch (e) {
- log.warn('[picker] "Unload all models" did not go through', { err: e })
- setOllamaNote({ text: 'Could not unload the models. Ollama did not answer.', tone: 'error' })
} finally {
setUnloading(false)
}
@@ -1677,6 +1685,10 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
const { groups, showHeadings, groupingFailed } =
computeModelGroups(textModels, luEngineHoldsChat, standbyName, holderName)
const hasOllamaModels = textModels.some(m => ('provider' in m && m.provider === 'ollama') || !('provider' in m))
+ // GH #235 follow-up: the unload button is there for every local engine, also
+ // when only the LU Engine runs (a managed engine exists on the desktop only).
+ const hasLmStudioRows = textModels.some((m) => isLmStudioProvider(m.providerName))
+ const showUnloadAll = hasOllamaModels || hasLmStudioRows || luEngineHoldsChat
textModelsEmptyRef.current = textModels.length === 0
// The one reason this picker switches rows off: a pick is already running.
@@ -2258,7 +2270,7 @@ export function ModelSelector({ openUpward = false, surface = 'chat', answeredBy
</div>
{/* Sticky footer: Unload */}
- {hasOllamaModels && (
+ {showUnloadAll && (
<div className="border-t border-black/[0.06] dark:border-white/[0.04] px-1 py-1">
<button
data-testid="ollama-unload-all"
diff --git a/src/hooks/__tests__/silent-run-yields-to-model-switch.test.ts b/src/hooks/__tests__/silent-run-yields-to-model-switch.test.ts
index 5258ca96..6a292661 100644
--- a/src/hooks/__tests__/silent-run-yields-to-model-switch.test.ts
+++ b/src/hooks/__tests__/silent-run-yields-to-model-switch.test.ts
@@ -186,7 +186,7 @@ describe('every model control calls it', () => {
expect(bodyOf(selector, 'const handleSelectModel = async')).toContain('yieldSilentLocalRuns()')
expect(bodyOf(selector, 'const toggleOllamaLoad = async')).toContain('yieldSilentLocalRuns()')
expect(bodyOf(selector, 'const toggleLmStudioLoad = async')).toContain('yieldSilentLocalRuns()')
- const unloadAll = selector.indexOf('await unloadAllModels()')
+ const unloadAll = selector.indexOf('await unloadEverything(')
expect(selector.slice(unloadAll - 200, unloadAll)).toContain('yieldSilentLocalRuns()')
})
diff --git a/src/lib/__tests__/unload-all-frees-every-engine-235.test.ts b/src/lib/__tests__/unload-all-frees-every-engine-235.test.ts
new file mode 100644
index 00000000..e20a5b26
--- /dev/null
+++ b/src/lib/__tests__/unload-all-frees-every-engine-235.test.ts
@@ -0,0 +1,92 @@
+/**
+ * GH #235 follow-up (LU-Admin, 15.11.2026): "Unload all models" in the model
+ * picker unloaded Ollama only, said "Ollama did not answer" for any failure,
+ * and was missing when only the LU Engine ran. It now frees Ollama, the LU
+ * Engine, LM Studio and ComfyUI's memory, and names each engine that did not go.
+ *
+ * Run: npx vitest run src/lib/__tests__/unload-all-frees-every-engine-235.test.ts
+ */
+import { describe, it, expect, vi } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+import { unloadEverything, unloadProblems, unloadedNames, type UnloadDeps } from '../unload-everything'
+
+function deps(over: Partial<UnloadDeps> = {}): UnloadDeps & Record<string, ReturnType<typeof vi.fn>> {
+ let lms = ['qwen3-8b']
+ const d = {
+ unloadOllama: vi.fn(async () => ({ unloaded: ['llama3:8b'], stillBusy: [], failed: [] })),
+ offload: vi.fn(async () => ({ offloaded: ['bundled-engine', 'comfyui'], notOurs: [] })),
+ lmsLoaded: vi.fn(async () => lms),
+ lmsUnloadAll: vi.fn(async () => { lms = [] }),
+ desktop: vi.fn(() => true),
+ ...over,
+ }
+ return d as never
+}
+
+describe('Unload all models frees every engine', () => {
+ it('Ollama, the LU Engine, LM Studio and ComfyUI, and says nothing went wrong', async () => {
+ const d = deps()
+ const r = await unloadEverything({ ollama: true, lmstudio: true }, d)
+ expect(d.unloadOllama).toHaveBeenCalledOnce()
+ expect(d.offload).toHaveBeenCalledOnce()
+ expect(d.lmsUnloadAll).toHaveBeenCalledOnce()
+ expect(unloadedNames(r.outcomes)).toEqual(['Ollama', 'LU Engine', 'ComfyUI', 'LM Studio'])
+ expect(unloadProblems(r.outcomes)).toBeNull()
+ })
+
+ it('with only the LU Engine running, Ollama and LM Studio are not asked', async () => {
+ const d = deps()
+ const r = await unloadEverything({ ollama: false, lmstudio: false }, d)
+ expect(d.unloadOllama).not.toHaveBeenCalled()
+ expect(d.lmsLoaded).not.toHaveBeenCalled()
+ expect(unloadedNames(r.outcomes)).toEqual(['LU Engine', 'ComfyUI'])
+ })
+
+ it('a failure names its own engine, the others still go', async () => {
+ const d = deps({
+ unloadOllama: vi.fn(async () => { throw new Error('ECONNREFUSED') }),
+ lmsLoaded: vi.fn(async () => { throw new Error('lms gone') }),
+ })
+ const r = await unloadEverything({ ollama: true, lmstudio: true }, d)
+ const text = unloadProblems(r.outcomes)!
+ expect(text).toContain('Ollama did not answer')
+ expect(text).toContain('LM Studio did not answer')
+ expect(text).not.toMatch(/LU Engine|ComfyUI/)
+ expect(unloadedNames(r.outcomes)).toEqual(['LU Engine', 'ComfyUI'])
+ })
+
+ it('the LU Engine failing is said as the LU Engine, not as Ollama', async () => {
+ const d = deps({ offload: vi.fn(async () => { throw new Error('ipc') }) })
+ const text = unloadProblems((await unloadEverything({ ollama: true, lmstudio: false }, d)).outcomes)!
+ expect(text).toContain('The LU Engine did not stop')
+ expect(text).not.toContain('Ollama')
+ })
+
+ it('a ComfyUI on another computer is said as such', async () => {
+ const d = deps({ offload: vi.fn(async () => ({ offloaded: ['bundled-engine'], notOurs: [{ backend: 'comfyui' }] })) })
+ expect(unloadProblems((await unloadEverything({ ollama: false, lmstudio: false }, d)).outcomes)).toMatch(/ComfyUI runs on another computer/)
+ })
+
+ it('LM Studio still holding a model after the unload is named', async () => {
+ const d = deps({ lmsUnloadAll: vi.fn(async () => {}) })
+ expect(unloadProblems((await unloadEverything({ ollama: false, lmstudio: true }, d)).outcomes)).toBe('LM Studio still has qwen3-8b loaded.')
+ })
+
+ it('NEGATIVE CONTROL: in the browser only Ollama is asked', async () => {
+ const d = deps({ desktop: vi.fn(() => false) })
+ const r = await unloadEverything({ ollama: true, lmstudio: true }, d)
+ expect(d.offload).not.toHaveBeenCalled()
+ expect(d.lmsLoaded).not.toHaveBeenCalled()
+ expect(r.outcomes.map((o) => o.engine)).toEqual(['ollama'])
+ })
+})
+
+describe('the button', () => {
+ const src = readFileSync(resolve(__dirname, '../../components/models/ModelSelector.tsx'), 'utf8')
+ it('is there for every local engine, also the LU Engine alone', () => {
+ expect(src).toMatch(/const showUnloadAll = hasOllamaModels \|\| hasLmStudioRows \|\| luEngineHoldsChat\n/)
+ expect(src).toMatch(/\{showUnloadAll && \(/)
+ expect(src).not.toContain("'Could not unload the models. Ollama did not answer.'")
+ })
+})
diff --git a/src/lib/unload-everything.ts b/src/lib/unload-everything.ts
new file mode 100644
index 00000000..be61b0f7
--- /dev/null
+++ b/src/lib/unload-everything.ts
@@ -0,0 +1,122 @@
+// GH #235 follow-up (LU-Admin, 15.11.2026): "Unload all models" in the model
+// picker unloaded Ollama and nothing else, and it was only there when the list
+// had an Ollama model. It now frees whatever is loaded: Ollama, the LU Engine,
+// LM Studio and ComfyUI's memory, and says per engine what did not go.
+import { unloadAllModels, type UnloadAllResult } from '../api/ollama'
+import { readLoadedLmStudioModels } from '../api/lmstudio'
+import { backendCall, isTauri } from '../api/backend'
+import { log } from './logger'
+
+export type UnloadEngine = 'ollama' | 'engine' | 'lmstudio' | 'comfyui'
+
+/** One engine's part of the answer. `problem` is set when it did not go. */
+export interface UnloadOutcome {
+ engine: UnloadEngine
+ freed: boolean
+ problem?: string
+}
+
+export interface UnloadEverythingResult {
+ outcomes: UnloadOutcome[]
+ /** Ollama's own answer, for the per-model switches. Null when not asked. */
+ ollama: UnloadAllResult | null
+}
+
+/** Which engines to ask. Ollama and LM Studio only when the list has them;
+ * the LU Engine and ComfyUI are freed by the app itself (desktop only). */
+export interface UnloadScope {
+ ollama: boolean
+ lmstudio: boolean
+}
+
+interface OffloadReply { offloaded?: string[]; notOurs?: Array<{ backend?: string }> }
+
+export interface UnloadDeps {
+ unloadOllama: () => Promise<UnloadAllResult>
+ offload: () => Promise<OffloadReply>
+ lmsLoaded: () => Promise<string[]>
+ lmsUnloadAll: () => Promise<unknown>
+ desktop: () => boolean
+}
+
+const defaultDeps: UnloadDeps = {
+ unloadOllama: () => unloadAllModels(),
+ offload: () => backendCall<OffloadReply>('offload_local_models', { includeComfyui: true }),
+ lmsLoaded: () => readLoadedLmStudioModels(),
+ lmsUnloadAll: () => backendCall('lmstudio_unload_model', { model: '--all' }),
+ desktop: () => isTauri(),
+}
+
+const NAME: Record<UnloadEngine, string> = { ollama: 'Ollama', engine: 'The LU Engine', lmstudio: 'LM Studio', comfyui: 'ComfyUI' }
+
+export async function unloadEverything(scope: UnloadScope, deps: UnloadDeps = defaultDeps): Promise<UnloadEverythingResult> {
+ const outcomes: UnloadOutcome[] = []
+ let ollama: UnloadAllResult | null = null
+
+ if (scope.ollama) {
+ try {
+ ollama = await deps.unloadOllama()
+ if (ollama.failed.length > 0) {
+ outcomes.push({ engine: 'ollama', freed: false, problem: `Ollama refused to unload ${ollama.failed.join(', ')}.` })
+ } else if (ollama.stillBusy.length > 0) {
+ outcomes.push({ engine: 'ollama', freed: false, problem: `Ollama is still answering with ${ollama.stillBusy.join(', ')} and unloads it when that is done.` })
+ } else {
+ outcomes.push({ engine: 'ollama', freed: ollama.unloaded.length > 0 })
+ }
+ } catch (err) {
+ log.warn('unload_everything.ollama_failed', { err })
+ outcomes.push({ engine: 'ollama', freed: false, problem: 'Ollama did not answer, so its models may still be loaded.' })
+ }
+ }
+
+ if (deps.desktop()) {
+ // The LU Engine (with its embedding helper and dictation) and ComfyUI's
+ // memory, in one call of the app. Ollama was asked above; asked again here
+ // it has nothing left.
+ try {
+ const reply = await deps.offload()
+ const freed = new Set(reply.offloaded ?? [])
+ outcomes.push({ engine: 'engine', freed: freed.has('bundled-engine') })
+ if ((reply.notOurs ?? []).some((n) => n.backend === 'comfyui')) {
+ outcomes.push({ engine: 'comfyui', freed: false, problem: 'ComfyUI runs on another computer, so LU cannot free its memory from here.' })
+ } else {
+ outcomes.push({ engine: 'comfyui', freed: freed.has('comfyui') })
+ }
+ } catch (err) {
+ log.warn('unload_everything.offload_failed', { err })
+ outcomes.push({ engine: 'engine', freed: false, problem: 'The LU Engine did not stop, so its model may still be loaded.' })
+ outcomes.push({ engine: 'comfyui', freed: false, problem: 'ComfyUI did not answer, so its memory may still be in use.' })
+ }
+
+ if (scope.lmstudio) {
+ try {
+ const before = await deps.lmsLoaded()
+ if (before.length === 0) {
+ outcomes.push({ engine: 'lmstudio', freed: false })
+ } else {
+ await deps.lmsUnloadAll()
+ const after = await deps.lmsLoaded()
+ outcomes.push(after.length === 0
+ ? { engine: 'lmstudio', freed: true }
+ : { engine: 'lmstudio', freed: false, problem: `LM Studio still has ${after.join(', ')} loaded.` })
+ }
+ } catch (err) {
+ log.warn('unload_everything.lmstudio_failed', { err })
+ outcomes.push({ engine: 'lmstudio', freed: false, problem: 'LM Studio did not answer, so its models may still be loaded.' })
+ }
+ }
+ }
+
+ return { outcomes, ollama }
+}
+
+/** The sentence under the button: every engine that did not go, one by one. */
+export function unloadProblems(outcomes: readonly UnloadOutcome[]): string | null {
+ const problems = outcomes.filter((o) => o.problem).map((o) => o.problem!)
+ return problems.length > 0 ? problems.join(' ') : null
+}
+
+/** What was freed, for the log and the done line. */
+export function unloadedNames(outcomes: readonly UnloadOutcome[]): string[] {
+ return outcomes.filter((o) => o.freed).map((o) => NAME[o.engine].replace(/^The /, ''))
+}