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(chat): a finished picture stops ending on a red vision error

purple49c24f6f95d1
diff --git a/src-tauri/src/commands/engine.rs b/src-tauri/src/commands/engine.rs
index 97ba2583..02d28d4e 100644
--- a/src-tauri/src/commands/engine.rs
+++ b/src-tauri/src/commands/engine.rs
@@ -159,11 +159,25 @@ pub(crate) fn is_projector_file(file_name: &str) -> bool {
/// Absolute path of the projector belonging to `model_path`, if it is on disk.
/// Absence is the normal case (text-only model) and never an error.
-fn existing_mmproj(model_path: &str) -> Option<String> {
+pub(crate) fn existing_mmproj(model_path: &str) -> Option<String> {
let p = mmproj_sibling_path(model_path);
p.is_file().then(|| p.to_string_lossy().to_string())
}
+/// Can this GGUF read images once the built-in engine loads it?
+///
+/// Exactly the question `existing_mmproj` answers when the server is started:
+/// llama-server sees images only with `--mmproj`, and that flag rides the argv
+/// only when the projector file sits next to the model. Reported with the
+/// model list so the frontend stops guessing from the model NAME. Nebenbefund
+/// N3 of the D1 counter-check (Windows build, 2026-08-29): a text-only
+/// gemma-3-4b conversion is a gemma3 by name, the app fed it the picture it
+/// had just generated, and the run ended on a red "This model can't read
+/// images" line under a picture that came out fine.
+pub(crate) fn model_can_see_images(model_path: &str) -> bool {
+ existing_mmproj(model_path).is_some()
+}
+
/// Build the `llama-server` argv for a chat engine. `-ngl 999` offloads every
/// layer to the GPU (Metal on mac); llama-server clamps to the real layer
/// count, so an over-large value is the idiomatic "all layers" request.
@@ -1102,6 +1116,7 @@ fn list_bundled_models_blocking(state: &AppState) -> Result<serde_json::Value, S
"size": m.size,
"loaded": is_loaded,
"ctx_train": ctx_train,
+ "vision": model_can_see_images(&m.path),
})
})
.collect();
@@ -1654,6 +1669,29 @@ mod tests {
assert!(args.iter().any(|a| a == "--mmproj"));
}
+ #[test]
+ fn vision_is_reported_from_the_projector_on_disk() {
+ // Nebenbefund N3 of the D1 counter-check: the model list has to answer
+ // "can this model read images" from the SAME file the engine passes as
+ // --mmproj, not from the model name.
+ let dir = tempfile::tempdir().unwrap();
+ let vision = dir.path().join("Qwen3.8-27B-UD-Q4_K_M.gguf");
+ std::fs::write(&vision, b"weights").unwrap();
+ std::fs::write(dir.path().join("Qwen3.8-27B-UD-Q4_K_M.mmproj.gguf"), b"projector").unwrap();
+ assert!(model_can_see_images(&vision.to_string_lossy()));
+
+ // Negative control: a gemma3 by NAME with no projector next to it. This
+ // is the exact file the counter-check ran, and the old name heuristic
+ // called it vision-capable.
+ let text_only = dir.path().join("gemma-3-4b-it-abliterated-Q4_K_M.gguf");
+ std::fs::write(&text_only, b"weights").unwrap();
+ assert!(!model_can_see_images(&text_only.to_string_lossy()));
+
+ // Negative control: a projector belonging to ANOTHER model in the same
+ // flat folder must not lend its vision to this one.
+ assert!(!model_can_see_images(&dir.path().join("nothing-here.gguf").to_string_lossy()));
+ }
+
#[test]
fn mmproj_sibling_path_follows_the_model_name() {
assert_eq!(
diff --git a/src/api/__tests__/engine.test.ts b/src/api/__tests__/engine.test.ts
index 118d38b4..bd787c1e 100644
--- a/src/api/__tests__/engine.test.ts
+++ b/src/api/__tests__/engine.test.ts
@@ -113,6 +113,30 @@ describe('bundledToAIModels', () => {
})
expect(models[1].name).toBe('openai::llama3')
})
+
+ /**
+ * Runde 4, Nebenbefund N3 of the D1 counter-check: whether a built-in model
+ * can read images is a file on disk (the projector next to the GGUF, which
+ * Rust reports as `vision`), not a guess from the model name.
+ */
+ it('carries the projector answer through as supportsVision, both ways', () => {
+ const models = bundledToAIModels([
+ { name: 'Qwen3.8-27B-UD-Q4_K_M', path: '/m/q.gguf', size: 1, loaded: true, vision: true },
+ { name: 'gemma-3-4b-it-abliterated-Q4_K_M', path: '/m/g.gguf', size: 1, loaded: false, vision: false },
+ ])
+ expect(models[0].supportsVision).toBe(true)
+ // The N3 witness: a gemma3 by name with no projector next to it.
+ expect(models[1].supportsVision).toBe(false)
+ })
+
+ it('negative control: a backend that does not report the field leaves it absent', () => {
+ // An older sidecar. The flag must stay undefined so the name heuristic
+ // keeps deciding, instead of every built-in model losing vision.
+ const models = bundledToAIModels([
+ { name: 'llama3', path: '/m/llama3.gguf', size: 1, loaded: false },
+ ])
+ expect('supportsVision' in models[0]).toBe(false)
+ })
})
describe('activateBuiltinModel', () => {
diff --git a/src/api/__tests__/vision-feedback.test.ts b/src/api/__tests__/vision-feedback.test.ts
index 491afdb6..303529b2 100644
--- a/src/api/__tests__/vision-feedback.test.ts
+++ b/src/api/__tests__/vision-feedback.test.ts
@@ -112,3 +112,54 @@ describe('buildVisionFeedback — provider-aware: non-Ollama uses the strict nam
expect(await buildVisionFeedback('openai::some-unknown-text-llm', 'image_generate', result, 'openai')).toBeNull()
})
})
+
+/**
+ * Runde 4, Nebenbefund N3 of the D1 counter-check (Windows build 2026-08-29):
+ * every successful picture was followed by a red "This model can't read
+ * images" line, because the built-in engine ran a text-only conversion of a
+ * vision family (gemma-3-4b-it-abliterated, no projector on disk) and the
+ * name heuristic called it vision-capable.
+ *
+ * The app knows the truth: the built-in engine reports whether the projector
+ * sits next to the GGUF, the same file it passes as --mmproj. That answer is
+ * handed in as `declaredVision` and beats the heuristic in both directions.
+ */
+describe('buildVisionFeedback, a declared capability beats the name', () => {
+ const RESULT = `Image generated: cat.png (prompt: "a cat")\n${VIEW('cat.png')}`
+
+ it('N3 witness: a gemma3 by name with no projector on disk is never fed the picture', async () => {
+ expect(await buildVisionFeedback('gemma-3-4b-it-abliterated', 'image_generate', RESULT, 'openai', false)).toBeNull()
+ // The bytes are not even fetched, so a text-only model costs nothing.
+ expect(fetchComfyImageBase64).not.toHaveBeenCalled()
+ })
+
+ it('a declared false overrides Ollama capability reporting too', async () => {
+ modelSupportsVision.mockResolvedValue(true)
+ expect(await buildVisionFeedback('gemma4:e4b', 'image_generate', RESULT, 'ollama', false)).toBeNull()
+ expect(modelSupportsVision).not.toHaveBeenCalled()
+ })
+
+ it('a declared true feeds a model whose name the strict family match misses', async () => {
+ const vf = await buildVisionFeedback('my-own-import-q4', 'image_generate', RESULT, 'openai', true)
+ expect(vf).not.toBeNull()
+ expect(vf!.images).toHaveLength(1)
+ expect(vf!.visionFeedback).toBe(true)
+ })
+
+ // ── Negative controls: nothing declared, and the old heuristics decide. ──
+ it('negative control: undefined keeps the strict name match on a non-Ollama provider', async () => {
+ expect(await buildVisionFeedback('gemma-3-4b-it-abliterated', 'image_generate', RESULT, 'openai')).not.toBeNull()
+ expect(await buildVisionFeedback('qwen2.5-coder:14b', 'image_generate', RESULT, 'openai')).toBeNull()
+ })
+
+ it('negative control: undefined keeps Ollama asking the server', async () => {
+ modelSupportsVision.mockResolvedValue(false)
+ expect(await buildVisionFeedback('gemma4:e4b', 'image_generate', RESULT, 'ollama')).toBeNull()
+ expect(modelSupportsVision).toHaveBeenCalledWith('gemma4:e4b')
+ })
+
+ it('negative control: a declared true still refuses a video result', async () => {
+ const video = `Video generated: clip.mp4 (prompt: "x")\n${VIEW('clip.mp4')}`
+ expect(await buildVisionFeedback('gemma4:e4b', 'video_generate', video, 'ollama', true)).toBeNull()
+ })
+})
diff --git a/src/api/engine.ts b/src/api/engine.ts
index 082df54a..1a108157 100644
--- a/src/api/engine.ts
+++ b/src/api/engine.ts
@@ -40,6 +40,12 @@ export interface BundledModel {
* (ENG-6c). null/absent when the header doesn't carry it — presets then
* stay uncapped, exactly the pre-2.6.0 behavior. */
ctx_train?: number | null
+ /** Can the built-in engine show this model a picture? True only when the
+ * vision projector sits next to the GGUF, which is the same file Rust turns
+ * into `--mmproj` at start (engine.rs model_can_see_images). Absent when the
+ * installed backend predates the field, and the callers then fall back to
+ * the model-name heuristic exactly as before. */
+ vision?: boolean
}
export interface EngineStatus {
@@ -245,6 +251,11 @@ export function bundledToAIModels(models: BundledModel[]): CloudModel[] {
type: 'text' as const,
provider: 'openai' as const,
providerName: 'Built-in Engine',
+ // The projector answer from disk, carried as the app-wide capability flag
+ // so the composer and the agent loop stop guessing from the model name.
+ // Deliberately left absent (not false) when the backend did not report it,
+ // so an older sidecar keeps the old heuristic instead of losing vision.
+ ...(typeof m.vision === 'boolean' ? { supportsVision: m.vision } : {}),
}))
}
diff --git a/src/api/vision-feedback.ts b/src/api/vision-feedback.ts
index 62737024..01ad1e0a 100644
--- a/src/api/vision-feedback.ts
+++ b/src/api/vision-feedback.ts
@@ -55,12 +55,19 @@ export interface VisionFeedbackMessage {
* can look at it. Returns null when this isn't an image result, the model can't
* see images, or the fetch fails (all non-fatal — the flow still works, the
* model just won't visually comment).
+ *
+ * `declaredVision` is the app's OWN answer where it has one, and it beats every
+ * guess below in both directions: the built-in engine reports whether the
+ * vision projector sits next to the GGUF (the file it turns into `--mmproj`),
+ * and a server model listing reports its input modalities. Undefined means
+ * nobody declared anything and the name heuristics decide, exactly as before.
*/
export async function buildVisionFeedback(
model: string,
toolName: string,
result: string,
providerId: string,
+ declaredVision?: boolean,
): Promise<VisionFeedbackMessage | null> {
if (!result) return null
// ONLY image_generate produces a still the vision model can read. A video_generate
@@ -80,10 +87,20 @@ export async function buildVisionFeedback(
// 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.
+ //
+ // Nebenbefund N3 of the D1 counter-check (Windows build, 2026-08-29): a
+ // text-only gemma-3-4b conversion on the built-in engine is a `gemma3` to
+ // the name heuristic, so the loop attached the picture it had just made and
+ // the engine answered "image input is not supported". A successful render
+ // ended on a red error line. The projector on disk is the honest answer and
+ // is asked first now.
+ if (declaredVision === false) return null
try {
- const canSee = providerId === 'ollama'
- ? await modelSupportsVision(model)
- : modelNameSuggestsVision(model)
+ const canSee = declaredVision === true
+ ? true
+ : providerId === 'ollama'
+ ? await modelSupportsVision(model)
+ : modelNameSuggestsVision(model)
if (!canSee) return null
} catch {
return null
diff --git a/src/components/chat/ChatInput.tsx b/src/components/chat/ChatInput.tsx
index a7d18a86..cbf44a2c 100644
--- a/src/components/chat/ChatInput.tsx
+++ b/src/components/chat/ChatInput.tsx
@@ -7,7 +7,7 @@ import { ApprovalDialog } from './ApprovalDialog'
import { useVoiceStore } from '../../stores/voiceStore'
import { useSettingsStore } from '../../stores/settingsStore'
import { useModelStore } from '../../stores/modelStore'
-import { isThinkingCompatible, isVisionCompatible } from '../../lib/model-compatibility'
+import { isThinkingCompatible, isVisionCompatible, declaredVision } from '../../lib/model-compatibility'
import type { AgentToolCall } from '../../types/agent-mode'
import type { ImageAttachment } from '../../types/chat'
@@ -88,9 +88,10 @@ export function ChatInput({ onSend, onStop, isGenerating, pendingApproval, onApp
const thinkLockedOn = thinkMode === 'always'
const canThink = thinkMode ? thinkMode === 'toggle' : isThinkingCompatible(activeModel)
// Same server-over-heuristic precedence for vision (input_modalities →
- // supportsVision). The flag is `true` or undefined (never false), so
- // models without it still fall back to the name heuristic.
- const serverVision = activeModelMeta && 'supportsVision' in activeModelMeta ? activeModelMeta.supportsVision : undefined
+ // supportsVision, and the built-in engine's projector-on-disk answer). A
+ // declared flag counts in both directions; models without one still fall
+ // back to the name heuristic.
+ const serverVision = declaredVision(activeModelMeta)
const canSeeImages = serverVision !== undefined ? serverVision : isVisionCompatible(activeModel)
useEffect(() => {
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index 1aed5466..6432fcc0 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -27,10 +27,10 @@ import { retrieveContext } from '../api/rag'
import { toolRegistry } from '../api/mcp'
import { usePermissionStore } from '../stores/permissionStore'
import { CODEX_CONFIRM_TOOLS, codexConfirmEnabled } from './codexShellGate'
-import { isThinkingCompatible, isPlainTextPlanner } from '../lib/model-compatibility'
+import { isThinkingCompatible, isPlainTextPlanner, declaredVision } from '../lib/model-compatibility'
import { resolveToolCallingStrategy } from '../lib/agent-strategy'
import { isMultimodalUnsupportedError, MULTIMODAL_UNSUPPORTED_MESSAGE } from '../lib/ollama-errors'
-import { stripVisionFeedbackMessages } from '../lib/vision-heal'
+import { stripVisionFeedbackMessages, reportMultimodalRefusal } from '../lib/vision-heal'
import { log } from '../lib/logger'
import { buildHermesToolPrompt, buildHermesToolResult, buildHermesToolCall, parseHermesToolCalls, stripToolCallTags, hasToolCallTags } from '../api/hermes-tool-calling'
import { parseLooseToolCalls, stripMatchedCalls, stripToolCallText, canonicalToolName } from '../lib/loose-tool-parse'
@@ -694,6 +694,23 @@ export function useAgentChat() {
// rightly weakened. Windowed batch repeats, per-epoch identical reads and
// repeated narration now watch this loop too.
const loopGuard = new AgentLoopGuard()
+ // The closing line a turn gets when the model itself said nothing usable.
+ // Read from the live counters at call time, so both the normal end of the
+ // run and the swallowed multimodal refusal below produce the same text.
+ const closingSummary = () =>
+ summarizeTurn({
+ calls: blocksRef.current
+ .filter((b) => b.phase === 'tool_call' && b.toolCall)
+ .map((b) => ({
+ toolName: b.toolCall!.toolName,
+ status: b.toolCall!.status,
+ result: b.toolCall!.result,
+ })),
+ imageGenDone,
+ videoGenDone,
+ visionFeedbackGiven,
+ planGap: openPlanGap(useTodoStore.getState().getTodos(convId!)),
+ })
// Which read produced which result message, so the request builder can
// tell the guard that a re-read of a CAPPED result is legitimate rather
// than a loop (plan A1, LOOP-GUARD). Keyed by the message object, which
@@ -1947,13 +1964,22 @@ export function useAgentChat() {
// 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).
+ //
+ // Runde 4 / Nebenbefund N3 (D1 counter-check, Windows build
+ // 2026-08-29): the app's own capability answer now goes in with the
+ // call. For the built-in engine that is the vision projector on disk,
+ // the same file the engine passes as --mmproj, so a text-only
+ // conversion of a vision family is never handed a picture again.
+ const declaredSight = declaredVision(
+ useModelStore.getState().models.find((m) => m.name === activeModel),
+ )
for (const { tc, ac } of batch) {
const result = results.find((r) => r.id === ac.id)
// G22: once this run proved the model text-only, stop attaching.
if (visionRefused) break
if (result?.status === 'completed' && result.result) {
try {
- const vf = await buildVisionFeedback(modelToUse, tc.function.name, result.result, providerId)
+ const vf = await buildVisionFeedback(modelToUse, tc.function.name, result.result, providerId, declaredSight)
if (vf) {
agentMessages.push(vf as unknown as ChatMessage)
visionFeedbackGiven = true
@@ -1981,23 +2007,11 @@ export function useAgentChat() {
// Closing line when the model said nothing itself. Pure logic lives in
// summarizeTurn so the D#81 rules (a failed picture is not a completed
// task, and its reason gets shown) are locked by tests.
- contentRef.current = summarizeTurn({
- calls: blocksRef.current
- .filter((b) => b.phase === 'tool_call' && b.toolCall)
- .map((b) => ({
- toolName: b.toolCall!.toolName,
- status: b.toolCall!.status,
- result: b.toolCall!.result,
- })),
- imageGenDone,
- videoGenDone,
- visionFeedbackGiven,
- // G27: the reconcile steers above have a budget of two; when it is
- // spent the run ends with the plan still open, and this line is the
- // last thing the user reads. It may not say "completed" while the
- // PlanBar next to it says otherwise.
- planGap: openPlanGap(useTodoStore.getState().getTodos(convId!)),
- })
+ // G27: the reconcile steers above have a budget of two; when it is
+ // spent the run ends with the plan still open, and this line is the
+ // last thing the user reads. It may not say "completed" while the
+ // PlanBar next to it says otherwise. closingSummary carries that rule.
+ contentRef.current = closingSummary()
}
// Final store update
@@ -2015,9 +2029,16 @@ export function useAgentChat() {
const sendRefusal = explainSendRefusal(err)
if (isMultimodalUnsupportedError(errorMsg)) {
+ // N3: only a picture the USER attached earns this error. When the run
+ // attached its own render and the model turned out unable to look at
+ // it, the render still succeeded and is on screen, so the turn closes
+ // with its normal summary instead of a red line under a finished
+ // image (D1 counter-check, Windows build 2026-08-29).
useChatStore.getState().updateMessageContent(
convId!, assistantMessage.id,
- MULTIMODAL_UNSUPPORTED_MESSAGE
+ reportMultimodalRefusal(visionFeedbackGiven)
+ ? MULTIMODAL_UNSUPPORTED_MESSAGE
+ : (contentRef.current.trim() || closingSummary())
)
} else if ((err as { code?: string })?.code === 'tools_unsupported' || errorMsg.includes('does not support tools')) {
// G26: record the refusal so the layered resolution (toolStrategyFor)
diff --git a/src/lib/__tests__/vision-heal.test.ts b/src/lib/__tests__/vision-heal.test.ts
index 67956d64..4d7b3a68 100644
--- a/src/lib/__tests__/vision-heal.test.ts
+++ b/src/lib/__tests__/vision-heal.test.ts
@@ -15,7 +15,7 @@ import { describe, it, expect } from 'vitest'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'node:path'
-import { stripVisionFeedbackMessages, VISION_FALLBACK_TEXT, type HealableMessage } from '../vision-heal'
+import { stripVisionFeedbackMessages, reportMultimodalRefusal, VISION_FALLBACK_TEXT, type HealableMessage } from '../vision-heal'
const here = dirname(fileURLToPath(import.meta.url))
const read = (rel: string) => readFileSync(resolve(here, rel), 'utf8')
@@ -95,3 +95,43 @@ describe('the agent loop actually wires the heal', () => {
expect(vf).toContain('fallbackText:')
})
})
+
+/**
+ * Runde 4, Nebenbefund N3 of the D1 counter-check (Windows build 2026-08-29):
+ * a finished render ended with a red "This model can't read images" line, the
+ * last thing in the chat, because the run had fed its own picture back to a
+ * model that could not look at it. The guess was ours, so the blame may not
+ * land on the user, and a successful render may not read as a failure.
+ */
+describe('reportMultimodalRefusal', () => {
+ it('N3 witness: our own attachment is swallowed, the turn keeps its summary', () => {
+ expect(reportMultimodalRefusal(true)).toBe(false)
+ })
+
+ it('NEGATIVE CONTROL: a user-attached image still earns the honest error', () => {
+ expect(reportMultimodalRefusal(false)).toBe(true)
+ })
+})
+
+describe('the agent loop actually wires the N3 rules', () => {
+ const hook = read('../../hooks/useAgentChat.ts')
+
+ it('the multimodal branch asks whose picture it was before painting the error', () => {
+ expect(hook).toContain('reportMultimodalRefusal(visionFeedbackGiven)')
+ // The swallowed case closes with the normal turn summary, not an error.
+ expect(hook).toContain('(contentRef.current.trim() || closingSummary())')
+ })
+
+ it('the loop hands its own capability answer to the vision feedback', () => {
+ expect(hook).toContain('const declaredSight = declaredVision(')
+ expect(hook).toContain('result.result, providerId, declaredSight)')
+ })
+
+ it('the built-in engine reports the projector on disk as that answer', () => {
+ const rust = read('../../../src-tauri/src/commands/engine.rs')
+ expect(rust).toContain('pub(crate) fn model_can_see_images(model_path: &str) -> bool')
+ expect(rust).toContain('"vision": model_can_see_images(&m.path)')
+ // The same file the engine turns into --mmproj, not a second opinion.
+ expect(rust).toContain('existing_mmproj(model_path).is_some()')
+ })
+})
diff --git a/src/lib/__tests__/vision-multimodal.test.ts b/src/lib/__tests__/vision-multimodal.test.ts
index 1d2df520..76661027 100644
--- a/src/lib/__tests__/vision-multimodal.test.ts
+++ b/src/lib/__tests__/vision-multimodal.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
-import { isVisionCompatible } from '../model-compatibility'
+import { isVisionCompatible, declaredVision } from '../model-compatibility'
import { isMultimodalUnsupportedError, MULTIMODAL_UNSUPPORTED_MESSAGE } from '../ollama-errors'
// #67 (gthvidsten, GH Discussion) — attaching an image to a text-only model.
@@ -69,3 +69,38 @@ describe('isMultimodalUnsupportedError', () => {
expect(MULTIMODAL_UNSUPPORTED_MESSAGE).toMatch(/vision/i)
})
})
+
+/**
+ * Runde 4, Nebenbefund N3 of the D1 counter-check: the app's own answer about
+ * a model's image capability, read off a model entry. Two sources fill it and
+ * both are facts: the built-in engine reports the vision projector on disk,
+ * and a server model listing reports its input modalities.
+ */
+describe('declaredVision', () => {
+ it('reads a declared true and a declared false', () => {
+ expect(declaredVision({ supportsVision: true })).toBe(true)
+ // The N3 witness: gemma3 by name, no projector next to the GGUF.
+ expect(declaredVision({ supportsVision: false })).toBe(false)
+ })
+
+ // ── Negative controls: nothing declared, so the name heuristics decide. ──
+ it('negative control: an entry without the field declares nothing', () => {
+ expect(declaredVision({ name: 'openai::llama3' })).toBeUndefined()
+ })
+
+ it('negative control: a missing entry or a non-boolean declares nothing', () => {
+ expect(declaredVision(undefined)).toBeUndefined()
+ expect(declaredVision(null)).toBeUndefined()
+ expect(declaredVision('gemma3')).toBeUndefined()
+ expect(declaredVision({ supportsVision: 'yes' })).toBeUndefined()
+ })
+
+ it('negative control: the composer keeps the heuristic when nothing is declared', () => {
+ // ChatInput's precedence in one line: declared wins, absent falls back.
+ const fallback = isVisionCompatible('gemma3:12b')
+ const declared = declaredVision({ name: 'openai::gemma-3-4b-it-abliterated', supportsVision: false })
+ expect(fallback).toBe(true)
+ expect(declared !== undefined ? declared : fallback).toBe(false)
+ expect(declaredVision({ name: 'gemma3:12b' }) ?? fallback).toBe(true)
+ })
+})
diff --git a/src/lib/model-compatibility.ts b/src/lib/model-compatibility.ts
index f6f2f446..cd148f32 100644
--- a/src/lib/model-compatibility.ts
+++ b/src/lib/model-compatibility.ts
@@ -248,6 +248,26 @@ export function isVisionCompatible(modelName: string | null): boolean {
return VISION_COMPATIBLE.some(f => containsFamily(f, baseName))
}
+/**
+ * The app's OWN answer to "can this model read images", or undefined when
+ * nothing declared one and the name heuristics have to decide.
+ *
+ * Two sources feed the `supportsVision` flag on a model entry, and both are
+ * facts rather than guesses: the built-in engine reports whether the vision
+ * projector sits next to the GGUF (the file it turns into `--mmproj`, see
+ * engine.rs model_can_see_images), and a server model listing reports its
+ * input modalities. A declared answer counts in BOTH directions. Before
+ * Nebenbefund N3 of the D1 counter-check (Windows build, 2026-08-29) only
+ * `true` was ever carried, so a text-only conversion of a vision family
+ * (gemma-3-4b-it-abliterated with no projector on disk) read as vision-capable
+ * and got fed the picture the run had just generated.
+ */
+export function declaredVision(meta: unknown): boolean | undefined {
+ if (!meta || typeof meta !== 'object') return undefined
+ const flag = (meta as { supportsVision?: unknown }).supportsVision
+ return typeof flag === 'boolean' ? flag : undefined
+}
+
/**
* STRICT, provider-agnostic vision check: true only when the model NAME matches
* a known vision family. Unlike isVisionCompatible (lenient — returns true for
diff --git a/src/lib/vision-heal.ts b/src/lib/vision-heal.ts
index 90ffd56c..8ee91c08 100644
--- a/src/lib/vision-heal.ts
+++ b/src/lib/vision-heal.ts
@@ -49,3 +49,20 @@ export function stripVisionFeedbackMessages(messages: HealableMessage[]): boolea
}
return healed
}
+
+/**
+ * Does the multimodal-unsupported error that ended a turn belong on screen?
+ *
+ * Nebenbefund N3 of the D1 counter-check (Windows build, 2026-08-29): every
+ * successful picture was followed by a red "This model can't read images" line
+ * as the last thing in the chat, because the run fed its own render back to a
+ * model that could not look at it. The render worked. Blaming the user for OUR
+ * attachment turns a finished job into what reads as a failure.
+ *
+ * So: the error is reported only when the picture in the request was NOT ours.
+ * A user-attached image keeps the honest error and the actionable advice,
+ * because their question depends on that picture.
+ */
+export function reportMultimodalRefusal(visionFeedbackGiven: boolean): boolean {
+ return !visionFeedbackGiven
+}