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(vision-feedback): feed the generated image to non-Ollama vision models too (konata)

purple775af9811326
diff --git a/src/api/__tests__/vision-feedback.test.ts b/src/api/__tests__/vision-feedback.test.ts
index e7761f2a..491afdb6 100644
--- a/src/api/__tests__/vision-feedback.test.ts
+++ b/src/api/__tests__/vision-feedback.test.ts
@@ -6,6 +6,12 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
// got fed to Ollama as an image → HTTP 400 "Failed to load image or audio file".
// Fix: only image_generate produces a feedable still — video_generate always
// no-ops, regardless of output container (mp4 / webm / animated webp / gif).
+//
+// 2026-06-22 (konata): the loop was Ollama-only, so a non-Ollama vision model
+// never received the image and described from the prompt (hallucination). Now
+// provider-aware: Ollama uses modelSupportsVision (/api/show); other providers
+// use the STRICT model-name family match (modelNameSuggestsVision) so a
+// text-only LM Studio model is never sent an image (which would SSE-error).
const { modelSupportsVision, fetchComfyImageBase64 } = vi.hoisted(() => ({
modelSupportsVision: vi.fn(),
@@ -15,6 +21,8 @@ const { modelSupportsVision, fetchComfyImageBase64 } = vi.hoisted(() => ({
vi.mock('../ollama', () => ({ modelSupportsVision: (...a: unknown[]) => modelSupportsVision(...a) }))
vi.mock('../comfyui', () => ({ fetchComfyImageBase64: (...a: unknown[]) => fetchComfyImageBase64(...a) }))
vi.mock('../../lib/logger', () => ({ log: { info: vi.fn(), warn: vi.fn(), error: vi.fn() } }))
+// NOTE: ../../lib/model-compatibility is intentionally NOT mocked — the
+// non-Ollama tests exercise the real modelNameSuggestsVision family match.
import { buildVisionFeedback } from '../vision-feedback'
@@ -30,26 +38,26 @@ beforeEach(() => {
describe('buildVisionFeedback — video_generate never feeds the model an image', () => {
it('video_generate with an animated .webp output → null (the live bug: webp slipped past urlIsVideo)', async () => {
const result = `Video generated: ocean_waves_vid_00001_.webp (prompt: "waves")\n${VIEW('ocean_waves_vid_00001_.webp')}`
- expect(await buildVisionFeedback('gemma4:e4b', 'video_generate', result)).toBeNull()
+ expect(await buildVisionFeedback('gemma4:e4b', 'video_generate', result, 'ollama')).toBeNull()
// must NOT even fetch the file — bails on the tool name, before any image work
expect(fetchComfyImageBase64).not.toHaveBeenCalled()
})
it('video_generate with .gif output → null', async () => {
const result = `Video generated: clip.gif (prompt: "x")\n${VIEW('clip.gif')}`
- expect(await buildVisionFeedback('gemma4:e4b', 'video_generate', result)).toBeNull()
+ expect(await buildVisionFeedback('gemma4:e4b', 'video_generate', result, 'ollama')).toBeNull()
})
it('video_generate with .mp4 output → null', async () => {
const result = `Video generated: clip.mp4 (prompt: "x")\n${VIEW('clip.mp4')}`
- expect(await buildVisionFeedback('gemma4:e4b', 'video_generate', result)).toBeNull()
+ expect(await buildVisionFeedback('gemma4:e4b', 'video_generate', result, 'ollama')).toBeNull()
})
})
-describe('buildVisionFeedback — image_generate still feeds a still to a vision model', () => {
+describe('buildVisionFeedback — image_generate feeds a still to a vision model (Ollama)', () => {
it('image_generate .png on a vision model → returns a vf message carrying the image', async () => {
const result = `Image generated: cat.png (prompt: "a cat")\n${VIEW('cat.png')}`
- const vf = await buildVisionFeedback('gemma4:e4b', 'image_generate', result)
+ const vf = await buildVisionFeedback('gemma4:e4b', 'image_generate', result, 'ollama')
expect(vf).not.toBeNull()
expect(vf!.role).toBe('user')
expect(vf!.images[0].data).toBe('BASE64DATA')
@@ -58,20 +66,49 @@ describe('buildVisionFeedback — image_generate still feeds a still to a vision
it('image_generate .webp STILL is still fed (webp is a valid still image — do not over-block)', async () => {
const result = `Image generated: art.webp (prompt: "art")\n${VIEW('art.webp')}`
- expect(await buildVisionFeedback('gemma4:e4b', 'image_generate', result)).not.toBeNull()
+ expect(await buildVisionFeedback('gemma4:e4b', 'image_generate', result, 'ollama')).not.toBeNull()
})
- it('text-only model → null (no useless base64 blob)', async () => {
+ it('text-only Ollama model → null (no useless base64 blob)', async () => {
modelSupportsVision.mockResolvedValue(false)
const result = `Image generated: cat.png (prompt: "x")\n${VIEW('cat.png')}`
- expect(await buildVisionFeedback('qwen2.5-coder:14b', 'image_generate', result)).toBeNull()
+ expect(await buildVisionFeedback('qwen2.5-coder:14b', 'image_generate', result, 'ollama')).toBeNull()
})
it('non-generation tool → null', async () => {
- expect(await buildVisionFeedback('gemma4:e4b', 'web_search', 'some search text')).toBeNull()
+ expect(await buildVisionFeedback('gemma4:e4b', 'web_search', 'some search text', 'ollama')).toBeNull()
})
it('no ComfyUI /view url in the result → null', async () => {
- expect(await buildVisionFeedback('gemma4:e4b', 'image_generate', 'Image generated: x.png (no url here)')).toBeNull()
+ expect(await buildVisionFeedback('gemma4:e4b', 'image_generate', 'Image generated: x.png (no url here)', 'ollama')).toBeNull()
+ })
+})
+
+describe('buildVisionFeedback — provider-aware: non-Ollama uses the strict name check (konata)', () => {
+ it('non-Ollama VISION model (llava on an openai-compatible endpoint) → feeds the image', async () => {
+ const result = `Image generated: frog.png (prompt: "a frog")\n${VIEW('frog.png')}`
+ const vf = await buildVisionFeedback('openai::llava-v1.6-mistral-7b', 'image_generate', result, 'openai')
+ expect(vf).not.toBeNull()
+ expect(vf!.images[0].data).toBe('BASE64DATA')
+ // never calls the Ollama-only /api/show capability probe for a non-Ollama model
+ expect(modelSupportsVision).not.toHaveBeenCalled()
+ })
+
+ it('non-Ollama VISION model with provider:: prefix (gemma) → feeds (prefix stripped before family match)', async () => {
+ const result = `Image generated: bird.png (prompt: "a bird")\n${VIEW('bird.png')}`
+ expect(await buildVisionFeedback('lmstudio::gemma-3-12b-it', 'image_generate', result, 'lmstudio')).not.toBeNull()
+ })
+
+ it('non-Ollama TEXT model (mistral-7b) → null — NOT fed an image (avoids the image→text SSE error)', async () => {
+ const result = `Image generated: cat.png (prompt: "x")\n${VIEW('cat.png')}`
+ expect(await buildVisionFeedback('openai::mistral-7b-instruct', 'image_generate', result, 'openai')).toBeNull()
+ expect(fetchComfyImageBase64).not.toHaveBeenCalled()
+ })
+
+ it('non-Ollama path ignores the Ollama capability probe even when it would say yes', async () => {
+ // modelSupportsVision defaults to true in beforeEach; a non-Ollama text
+ // model must STILL be null because the non-Ollama branch never consults it.
+ const result = `Image generated: x.png (prompt: "x")\n${VIEW('x.png')}`
+ expect(await buildVisionFeedback('openai::some-unknown-text-llm', 'image_generate', result, 'openai')).toBeNull()
})
})
diff --git a/src/api/vision-feedback.ts b/src/api/vision-feedback.ts
index 0c43e15c..ccf402c8 100644
--- a/src/api/vision-feedback.ts
+++ b/src/api/vision-feedback.ts
@@ -15,6 +15,7 @@
*/
import { modelSupportsVision } from './ollama'
+import { modelNameSuggestsVision } from '../lib/model-compatibility'
import { fetchComfyImageBase64 } from './comfyui'
import { log } from '../lib/logger'
@@ -54,6 +55,7 @@ export async function buildVisionFeedback(
model: string,
toolName: string,
result: string,
+ providerId: string,
): Promise<VisionFeedbackMessage | null> {
if (!result) return null
// ONLY image_generate produces a still the vision model can read. A video_generate
@@ -67,8 +69,17 @@ export async function buildVisionFeedback(
if (!m) return null
const url = m[1]
if (urlIsVideo(url)) return null // can't feed a video to the model as an image
+ // Vision capability, provider-aware (konata 2026-06-21: on a non-Ollama
+ // provider the generated image never reached the model's vision input, so it
+ // described from the prompt and hallucinated). Ollama: the accurate /api/show
+ // capability list. Other providers: a STRICT model-name family match — never
+ // the lenient isVisionCompatible, which would feed an image to a text-only
+ // LM Studio model and trip the image→text SSE error.
try {
- if (!(await modelSupportsVision(model))) return null
+ const canSee = providerId === 'ollama'
+ ? await modelSupportsVision(model)
+ : modelNameSuggestsVision(model)
+ if (!canSee) return null
} catch {
return null
}
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index 44b3f2f7..d4f066f0 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -1276,24 +1276,26 @@ export function useAgentChat() {
}
// Vision feedback (David 2026-06-03): after image_generate, hand the
- // generated picture to a vision-capable local model so it SEES the
- // result and can comment — and learns the filename to chain into
- // video_generate. Local Ollama only; buildVisionFeedback no-ops for
- // text-only models, video results, or fetch failures.
- if (providerId === 'ollama') {
- for (const { tc, ac } of batch) {
- const result = results.find((r) => r.id === ac.id)
- if (result?.status === 'completed' && result.result) {
- try {
- const vf = await buildVisionFeedback(modelToUse, tc.function.name, result.result)
- if (vf) {
- agentMessages.push(vf as unknown as ChatMessage)
- visionFeedbackGiven = true
- log.info('agent.vision_feedback_attached', { tool: tc.function.name })
- break // one image per batch is enough context
- }
- } catch { /* non-fatal — flow still works without the visual */ }
- }
+ // generated picture to a vision-capable model so it SEES the result and
+ // can comment — and learns the filename to chain into video_generate.
+ // Provider-aware (konata 2026-06-21: a non-Ollama vision model never got
+ // the image → it described from the prompt and hallucinated). Now runs
+ // for every provider; buildVisionFeedback no-ops for text-only models,
+ // video results, or fetch failures — and on non-Ollama only feeds models
+ // whose name matches a vision family (so a text LM Studio model isn't
+ // sent an image and made to SSE-error).
+ for (const { tc, ac } of batch) {
+ const result = results.find((r) => r.id === ac.id)
+ if (result?.status === 'completed' && result.result) {
+ try {
+ const vf = await buildVisionFeedback(modelToUse, tc.function.name, result.result, providerId)
+ if (vf) {
+ agentMessages.push(vf as unknown as ChatMessage)
+ visionFeedbackGiven = true
+ log.info('agent.vision_feedback_attached', { tool: tc.function.name, provider: providerId })
+ break // one image per batch is enough context
+ }
+ } catch { /* non-fatal — flow still works without the visual */ }
}
}
diff --git a/src/lib/model-compatibility.ts b/src/lib/model-compatibility.ts
index ca389673..1ca06942 100644
--- a/src/lib/model-compatibility.ts
+++ b/src/lib/model-compatibility.ts
@@ -201,6 +201,26 @@ export function isVisionCompatible(modelName: string | null): boolean {
return VISION_COMPATIBLE.some(f => containsFamily(f, baseName))
}
+/**
+ * STRICT, provider-agnostic vision check: true only when the model NAME matches
+ * a known vision family. Unlike isVisionCompatible (lenient — returns true for
+ * ANY openai/anthropic-prefixed model so the manual attach UI stays permissive),
+ * this never returns true for an unknown name. The auto vision-feedback loop
+ * uses it for non-Ollama providers so it won't feed a generated image to a
+ * text-only OpenAI-compatible model (e.g. an LM Studio text GGUF), which would
+ * otherwise trip the image→text-model SSE error. Cloud vision models whose tag
+ * doesn't match a family (gpt-4o, claude-*) simply get no feedback — the safe
+ * no-op, same as before this loop existed.
+ *
+ * Strips a `provider::` prefix first because normalizeFamily cuts at the first
+ * ':' and would otherwise collapse `openai::llava` to `openai`.
+ */
+export function modelNameSuggestsVision(modelName: string | null): boolean {
+ if (!modelName) return false
+ const bare = modelName.includes('::') ? modelName.split('::').slice(1).join('::') : modelName
+ return VISION_COMPATIBLE.some(f => containsFamily(f, normalizeFamily(bare)))
+}
+
/**
* Gemma 3/4 are thinking-compatible but their `think: false` path produces
* plain-text structured planning (`Plan:`, `Constraint Checklist:`,