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(engine): A22 reload a vision model's image part instead of blaming the model

purple512666ad51fb
diff --git a/src/api/__tests__/a22-image-part-reload.test.ts b/src/api/__tests__/a22-image-part-reload.test.ts
new file mode 100644
index 00000000..eb92ddd5
--- /dev/null
+++ b/src/api/__tests__/a22-image-part-reload.test.ts
@@ -0,0 +1,128 @@
+// A22 (boromirofgeo, 12.11.2026): Gemma 4 12B Abliterated said "This model
+// can't read images" while its image part (mmproj) lay next to it. The LU
+// Engine ran the model without the part; a restart fixed it.
+//
+// Run: npx vitest run src/api/__tests__/a22-image-part-reload.test.ts
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+
+const engine = vi.hoisted(() => ({
+ vision: false,
+ imagePart: true,
+ /** What a restart gives: the part fits now, or still not. */
+ fitsOnRestart: true,
+ imageNote: 'Loaded without image input: the graphics memory has no room for the image part next to the model. A smaller context makes room.' as string | null,
+ swaps: [] as string[],
+ stops: 0,
+ tunings: [] as unknown[],
+}))
+
+vi.mock('../backend', () => ({
+ isTauri: () => true,
+ backendCall: vi.fn(async (cmd: string, args?: { modelPath?: string }) => {
+ if (cmd === 'list_bundled_models') {
+ return {
+ dir: '/models',
+ models: [
+ { name: 'gemma-4-12b-it-abliterated-Q4_K_M', path: '/models/gemma-4-12b-it-abliterated-Q4_K_M.gguf', size: 1, loaded: true, vision: engine.vision, imagePart: engine.imagePart, ctx_train: 131072 },
+ { name: 'other', path: '/models/other.gguf', size: 1, loaded: false, vision: false, imagePart: false },
+ ],
+ }
+ }
+ if (cmd === 'bundled_engine_status') return { running: true, healthy: true, port: 8127, ctx: 32768, ctxRequested: 32768, imageNote: engine.vision ? null : engine.imageNote }
+ if (cmd === 'stop_bundled_engine') { engine.stops++; return null }
+ if (cmd === 'swap_bundled_model') {
+ engine.swaps.push(args!.modelPath!)
+ engine.tunings.push((args as { tuning?: unknown }).tuning)
+ if (engine.fitsOnRestart) engine.vision = true
+ return { status: 'ok', port: 8127, model_path: args!.modelPath }
+ }
+ throw new Error(`unexpected ${cmd}`)
+ }),
+}))
+
+import { __resetImagePartReloads, ensureImagePartLoaded, explainImageRefusal, imagePartState } from '../image-part-heal'
+import { useProviderStore } from '../../stores/providerStore'
+import { MULTIMODAL_UNSUPPORTED_MESSAGE } from '../../lib/ollama-errors'
+
+const MODEL = 'openai::gemma-4-12b-it-abliterated-Q4_K_M'
+
+beforeEach(() => {
+ engine.vision = false
+ engine.imagePart = true
+ engine.fitsOnRestart = true
+ engine.swaps = []
+ engine.stops = 0
+ engine.tunings = []
+ __resetImagePartReloads()
+ useProviderStore.setState((s) => ({ providers: { ...s.providers, openai: { ...s.providers.openai, enabled: true, managed: true } } }) as never)
+})
+
+describe('A22: the image part of a vision model on the LU Engine', () => {
+ it('sees that the part is on disk but not loaded, and why', async () => {
+ const st = await imagePartState(MODEL)
+ expect(st.kind).toBe('not-loaded')
+ expect(st.kind === 'not-loaded' && st.note).toMatch(/no room for the image part/)
+ })
+
+ it('before a send with a picture, restarts the engine with the part', async () => {
+ const said: string[] = []
+ const st = await ensureImagePartLoaded(MODEL, (m) => said.push(m))
+ expect(engine.swaps).toEqual(['/models/gemma-4-12b-it-abliterated-Q4_K_M.gguf'])
+ expect(said).toEqual(['gemma-4-12b-it-abliterated-Q4_K_M'])
+ expect(st.kind).toBe('sees')
+ // Pinned without its part: stopped first, or the start is a no-op.
+ expect(engine.stops).toBe(1)
+ // The 32K context the engine held survives the reload.
+ expect((engine.tunings[0] as { ctx?: number })?.ctx).toBe(32768)
+ })
+
+ it('a part that still does not fit is not reloaded on every picture', async () => {
+ engine.fitsOnRestart = false
+ expect((await ensureImagePartLoaded(MODEL)).kind).toBe('not-loaded')
+ expect((await ensureImagePartLoaded(MODEL)).kind).toBe('not-loaded')
+ expect(engine.swaps).toHaveLength(1)
+ })
+
+ it('started before the part was downloaded (no note): restarts without a stop', async () => {
+ engine.imageNote = null
+ expect((await ensureImagePartLoaded(MODEL)).kind).toBe('sees')
+ expect(engine.stops).toBe(0)
+ expect(engine.swaps).toHaveLength(1)
+ engine.imageNote = 'Loaded without image input: the graphics memory has no room for the image part next to the model. A smaller context makes room.'
+ })
+
+ it('a model that already sees is left alone', async () => {
+ engine.vision = true
+ expect((await ensureImagePartLoaded(MODEL)).kind).toBe('sees')
+ expect(engine.swaps).toEqual([])
+ })
+
+ it('a refusal names the true reason and the reload, not "can\'t read images"', async () => {
+ const msg = await explainImageRefusal(MODEL)
+ expect(msg).not.toBe(MULTIMODAL_UNSUPPORTED_MESSAGE)
+ expect(msg).toMatch(/was running without its image part \(mmproj\)\. LU has loaded it again/)
+ expect(engine.swaps).toHaveLength(1)
+ })
+
+ it('when the part still does not fit, says why and what helps', async () => {
+ engine.fitsOnRestart = false
+ const msg = await explainImageRefusal(MODEL)
+ expect(msg).toMatch(/can read images, but the LU Engine is running it without its image part \(mmproj\): the graphics memory has no room/)
+ expect(msg).toMatch(/Lower the context/)
+ })
+
+ it('a model with no image part installed says so', async () => {
+ engine.imagePart = false
+ const msg = await explainImageRefusal(MODEL)
+ expect(msg).toMatch(/has no image part installed/)
+ expect(engine.swaps).toEqual([])
+ })
+
+ it('Ollama, cloud and an unmanaged slot keep the old sentence and are not touched', async () => {
+ expect(await explainImageRefusal('ollama::gemma3:12b')).toBe(MULTIMODAL_UNSUPPORTED_MESSAGE)
+ expect(await explainImageRefusal('lu-cloud::some-model')).toBe(MULTIMODAL_UNSUPPORTED_MESSAGE)
+ useProviderStore.setState((s) => ({ providers: { ...s.providers, openai: { ...s.providers.openai, managed: false } } }) as never)
+ expect(await explainImageRefusal(MODEL)).toBe(MULTIMODAL_UNSUPPORTED_MESSAGE)
+ expect(engine.swaps).toEqual([])
+ })
+})
diff --git a/src/api/image-part-heal.ts b/src/api/image-part-heal.ts
new file mode 100644
index 00000000..7fffd8d4
--- /dev/null
+++ b/src/api/image-part-heal.ts
@@ -0,0 +1,171 @@
+/**
+ * A22 (boromirofgeo, Discord 12.11.2026): a vision model said "This model
+ * can't read images".
+ *
+ * Gemma 4 12B Abliterated can read images, and its image part (the mmproj
+ * GGUF llama.cpp needs for that) was on disk. The LU Engine was running the
+ * model WITHOUT it: either the start found no room for the part on the
+ * graphics card (engine.rs IMAGE_PART_NO_ROOM_NOTE), the part could not be
+ * loaded, or the engine was started before the part was downloaded. The
+ * server then refused the picture, and the chat blamed the model. A restart
+ * of the engine fixed it, which nobody could guess from that sentence.
+ *
+ * So, for the managed LU Engine only:
+ * 1. Before a send that carries a picture, the loaded model is asked
+ * whether it runs with its image part. When the part is on disk but not
+ * loaded, the engine is restarted with it first (a fresh start plans
+ * the memory again and takes the part when it fits).
+ * 2. When the server still refuses, the message names the true reason:
+ * the part is not loaded (and why), or it is not installed at all.
+ *
+ * Everything else (Ollama, LM Studio, cloud models) keeps the old message.
+ */
+import { backendCall } from './backend'
+import { listBundledModels, stopBundledEngine, swapBundledModel } from './engine'
+import { bareBuiltinModelName } from '../lib/builtin-model-identity'
+import { preservedSwapCtx } from '../lib/builtin-ctx'
+import { useSettingsStore } from '../stores/settingsStore'
+import { MULTIMODAL_UNSUPPORTED_MESSAGE } from '../lib/ollama-errors'
+import { useProviderStore } from '../stores/providerStore'
+import { log } from '../lib/logger'
+
+export type ImagePartState =
+ /** Not the managed LU Engine, not loaded, or a backend too old to say. */
+ | { kind: 'unknown' }
+ | { kind: 'sees'; model: string }
+ /** The model has no image part installed next to it. */
+ | { kind: 'no-part'; model: string }
+ /** The part is on disk, the running engine was started without it. */
+ | { kind: 'not-loaded'; model: string; path: string; note: string | null; ctx: number | null; ctxTrain: number | null }
+
+/**
+ * A reload that did not bring the part up, per model file. The next picture
+ * within this time does not restart the engine again: the card has no more
+ * room than a minute ago, and a restart per picture would be a loop.
+ */
+const RETRY_AFTER_MS = 10 * 60_000
+const failedReloads = new Map<string, number>()
+
+/** Test-only. */
+export function __resetImagePartReloads(): void {
+ failedReloads.clear()
+}
+
+function managedEngineModel(modelName: string): string | null {
+ const parts = modelName.split('::')
+ if (parts.length === 2 && parts[0] !== 'openai') return null
+ const cfg = useProviderStore.getState().providers.openai
+ if (!cfg?.enabled || cfg.managed !== true) return null
+ return bareBuiltinModelName(modelName) || null
+}
+
+export async function imagePartState(modelName: string | null | undefined): Promise<ImagePartState> {
+ const bare = modelName ? managedEngineModel(modelName) : null
+ if (!bare) return { kind: 'unknown' }
+ try {
+ const models = await listBundledModels()
+ const m = models.find((x) => x.name === bare)
+ if (!m || !m.loaded || typeof m.vision !== 'boolean' || typeof m.imagePart !== 'boolean') return { kind: 'unknown' }
+ if (m.vision) return { kind: 'sees', model: m.name }
+ if (!m.imagePart) return { kind: 'no-part', model: m.name }
+ const status = await backendCall<{ imageNote?: string | null; ctx?: number | null; ctxRequested?: number | null }>('bundled_engine_status').catch(() => null)
+ return {
+ kind: 'not-loaded',
+ model: m.name,
+ path: m.path,
+ note: status?.imageNote ?? null,
+ ctx: status?.ctxRequested ?? status?.ctx ?? null,
+ ctxTrain: m.ctx_train ?? null,
+ }
+ } catch {
+ return { kind: 'unknown' }
+ }
+}
+
+/**
+ * Restart the engine with the same model so it takes its image part again.
+ * Returns the state after the restart: `sees` when it worked.
+ */
+export async function reloadWithImagePart(state: Extract<ImagePartState, { kind: 'not-loaded' }>): Promise<ImagePartState> {
+ const failedAt = failedReloads.get(state.path)
+ if (failedAt !== undefined && Date.now() - failedAt < RETRY_AFTER_MS) return state
+ log.info('engine.image_part_reload', { model: state.model, note: state.note })
+ // The same tuning a self-heal uses, and the context the engine holds now,
+ // so the reload changes nothing but the image part (lib/builtin-ctx).
+ const settingsTuning = useSettingsStore.getState().settings.builtinEngine
+ const keepCtx = preservedSwapCtx({
+ tuningCtx: settingsTuning?.ctx,
+ tuningChosen: settingsTuning?.ctxChosen,
+ currentCtx: state.ctx,
+ ctxTrain: state.ctxTrain,
+ })
+ const tuning = keepCtx ? { ...(settingsTuning ?? {}), ctx: keepCtx } : settingsTuning
+ try {
+ // An engine pinned as running without its part answers a start for the
+ // same model with "already running" (engine.rs, argv idempotence). Only a
+ // stopped engine plans the memory again and takes the part when it fits.
+ if (state.note) await stopBundledEngine()
+ await swapBundledModel(state.path, tuning)
+ } catch (err) {
+ log.warn('engine.image_part_reload_failed', { model: state.model, err: String(err) })
+ failedReloads.set(state.path, Date.now())
+ return state
+ }
+ const after = await imagePartState(state.model)
+ log.info('engine.image_part_reloaded', { model: state.model, sees: after.kind === 'sees' })
+ if (after.kind === 'sees') {
+ failedReloads.delete(state.path)
+ return after
+ }
+ failedReloads.set(state.path, Date.now())
+ return after.kind === 'not-loaded' ? after : state
+}
+
+/**
+ * Before a send with a picture: make sure the loaded model runs with its
+ * image part. Quiet and cheap when there is nothing to do; never throws.
+ * `onReload` is told before the restart starts, so the caller can say so.
+ */
+export async function ensureImagePartLoaded(modelName: string | null | undefined, onReload?: (model: string) => void): Promise<ImagePartState> {
+ const state = await imagePartState(modelName)
+ if (state.kind !== 'not-loaded') return state
+ onReload?.(state.model)
+ return reloadWithImagePart(state)
+}
+
+/** The sentence a refused picture gets, with the true reason when we know it. */
+export function imagePartRefusalMessage(state: ImagePartState): string {
+ switch (state.kind) {
+ case 'no-part':
+ return (
+ `${state.model} has no image part installed, so it cannot see the picture. ` +
+ 'Add its image part (the mmproj file) on the Models page, or switch to a model that has one, then send again.'
+ )
+ case 'not-loaded':
+ return (
+ `${state.model} can read images, but the LU Engine is running it without its image part (mmproj)` +
+ (state.note ? `: ${state.note.replace(/^Loaded without image input: /, '')}` : '.') +
+ ' LU tried to load it again and it did not come up. ' +
+ (/smaller context/i.test(state.note ?? '')
+ ? 'Lower the context in the engine settings, then send again.'
+ : 'Restart the engine from the model picker, then send again.')
+ )
+ case 'sees':
+ return (
+ `${state.model} was running without its image part (mmproj). LU has loaded it again: send the message again and it will see the picture.`
+ )
+ default:
+ return MULTIMODAL_UNSUPPORTED_MESSAGE
+ }
+}
+
+/**
+ * After the server refused a picture: find out why, try the reload once,
+ * and return the sentence for the chat.
+ */
+export async function explainImageRefusal(modelName: string | null | undefined): Promise<string> {
+ const state = await imagePartState(modelName)
+ if (state.kind === 'not-loaded') return imagePartRefusalMessage(await reloadWithImagePart(state))
+ if (state.kind === 'sees') return MULTIMODAL_UNSUPPORTED_MESSAGE
+ return imagePartRefusalMessage(state)
+}
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index 31cddd7e..d1cadc6c 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -77,6 +77,7 @@ import { speaksOpenAIProtocol } from '../api/providers/compat-id'
import { useSendSizeStore } from '../stores/sendSizeStore'
import { resolveAgentNumCtx } from '../lib/agent-num-ctx'
import { ensureBuiltinAgentCtx } from '../api/builtin-ensure'
+import { ensureImagePartLoaded, explainImageRefusal } from '../api/image-part-heal'
import { approvalIsMoot } from '../api/mcp/builtin-tools'
import { useMemoryStore } from '../stores/memoryStore'
import { useVoiceStore } from '../stores/voiceStore'
@@ -2096,6 +2097,14 @@ export function useAgentChat() {
// A7: the first wait of a turn is the model reading the request.
// Said in words and with its size instead of a bare "Starting"; the
// first word, shown thought or tool call takes the line back.
+ // A22: a picture goes along and the LU Engine may be running this
+ // model without its image part. Load it again before the server
+ // refuses the picture.
+ if (stepNo === 1 && (sendMessages as Array<{ images?: unknown[] }>).some((m) => m.images?.length)) {
+ await ensureImagePartLoaded(activeModel, () =>
+ useRunActivityStore.getState().setActivity(convId, { label: 'Loading the image part of the model', kind: 'reading' }),
+ )
+ }
if (stepNo === 1) {
useRunActivityStore.getState().setActivity(convId, readingActivity(estPrompt))
// B26: a long first wait on a local Ollama model gets its reason
@@ -3635,7 +3644,8 @@ export function useAgentChat() {
useChatStore.getState().updateMessageContent(
convId!, assistantMessage.id,
reportMultimodalRefusal(visionFeedbackGiven)
- ? MULTIMODAL_UNSUPPORTED_MESSAGE
+ // A22: the true reason when it is the LU Engine's image part.
+ ? await explainImageRefusal(activeModel).catch(() => MULTIMODAL_UNSUPPORTED_MESSAGE)
: (runState.content.trim() || closingSummary())
)
} else if ((err as { code?: string })?.code === 'tools_unsupported' || errorMsg.includes('does not support tools')) {
diff --git a/src/hooks/useChat.ts b/src/hooks/useChat.ts
index 20354240..e1bc8f67 100644
--- a/src/hooks/useChat.ts
+++ b/src/hooks/useChat.ts
@@ -71,6 +71,7 @@ import { laterAnswersInRound, nextRoundSpeakers, regenerateSpeakers, copiesForNe
import { groupTurnStarted, groupRoundEnded } from "../stores/groupRoundStore"
import { forkStart } from "../lib/chat-forks"
import { builtinReloadNeeded, ensureBuiltinEngineAlive } from "../api/builtin-ensure"
+import { ensureImagePartLoaded, explainImageRefusal } from "../api/image-part-heal"
import { emptyAnswerExplanation } from "../lib/answer-notes"
import { beginModelSwitchWatch, cutByModelSwitch, finishReasonAfterSwitch, MODEL_SWITCH_FINISH } from "../lib/model-switch-stop"
import { log } from "../lib/logger"
@@ -1856,6 +1857,14 @@ export function useChat() {
// drives the honest empty-reply explanation below.
let finishReason: string | undefined
+ // A22: a picture goes along. When the LU Engine runs this model without
+ // its image part (no room at start, or started before the part was
+ // there), load it again first; the server would refuse the picture.
+ if ((messages as Array<{ images?: unknown[] }>).some((m) => m.images?.length)) {
+ await ensureImagePartLoaded(activeModel, () =>
+ useRunActivityStore.getState().setActivity(convId, { label: 'Loading the image part of the model', kind: 'reading' }),
+ )
+ }
// A7: until the first token the model reads the request; say so, with
// its size, instead of a bare "Starting" (stores/runActivityStore).
useRunActivityStore.getState().setActivity(convId, readingActivity(estimateMessageTokens(messages as unknown as Parameters<typeof estimateMessageTokens>[0])))
@@ -2095,10 +2104,11 @@ export function useChat() {
// (lib/logic-notes.ts): the field says it is not the answer.
useChatStore.getState().updateMessageError(run.convId, assistantMessage.id, { kind: 'generic', detail: rawMessage, at: run.content.length })
} else if (isMultimodalUnsupportedError(errorMsg)) {
+ // A22: the true reason when it is the LU Engine's image part.
useChatStore.getState().updateMessageContent(
run.convId,
assistantMessage.id,
- MULTIMODAL_UNSUPPORTED_MESSAGE
+ await explainImageRefusal(activeModel).catch(() => MULTIMODAL_UNSUPPORTED_MESSAGE)
)
// An empty wallet gets the same plain explanation everywhere, next to
// the dialog that offers the top-up (lib/credits-exhausted.ts).