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: Think-Mode guard prevents HTTP 400 crash on non-thinking models

PurpleDoubleD8114c0ca8827
diff --git a/CLAUDE.md b/CLAUDE.md
index ccfc5054..c931c807 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -67,8 +67,10 @@ src-tauri/src/commands/ — Rust commands: install, process, download, prox
35. **E2E Image+Video Gen fixes (6 bugs)** — Error handling shows real ComfyUI errors (not generic HTTP 500). Direct fetch fallback when Tauri proxy fails. Legacy builder uses correct FLUX 2 nodes (EmptyFlux2LatentImage + separate negative prompt). Stale localStorage model names auto-reset against current ComfyUI list. Polling heartbeat catches missed WebSocket completion events. ComfyUI critical functions (submit/history/cancel/free) use direct fetch bypassing broken Tauri proxy.
36. **tqdm crash fix confirmed** — TQDM_DISABLE=1 env var in start_comfyui/auto_start_comfyui prevents KSampler [Errno 22] crash. Both image and video KSampler confirmed working in .exe.
+37. **Think-Mode guard for non-thinking models** — isThinkingCompatible() in model-compatibility.ts checks if model supports Ollama's `think` parameter. ChatView shows amber hint toast instead of crashing with HTTP 400. useChat.ts double-guards by not sending `think=true` to incompatible models. Supports: QwQ, DeepSeek-R1, Qwen3/3.5, Qwen3-Coder, Gemma3/4. Cloud providers always pass through.
+
### What's LEFT to finish v2.3.0:
-1. **Tauri proxy_localhost investigation** — reqwest in Tauri subprocess can't reach localhost. Direct fetch workaround in place but root cause unknown. Low priority since workaround works.
+1. **Tauri proxy_localhost investigation** — reqwest in Tauri subprocess can't reach localhost. Direct fetch workaround in place but root cause unknown. Low priority since workaround works. Deferred to next release.
2. **LTX VAEDecode reference** — dynamic-workflow.ts line 263: vaeSourceId incorrectly points to UNETLoader output for LTX strategy. Fix when LTX model is installed for testing.
### Files modified in this branch (30+ files):
@@ -98,6 +100,9 @@ src-tauri/src/commands/ — Rust commands: install, process, download, prox
- `src/stores/createStore.ts` — i2vImage state
- `src/stores/downloadStore.ts` — NEW: unified ComfyUI download tracking (polling, bundle grouping)
- `src/stores/uiStore.ts` — default view changed to 'chat'
+- `src/lib/model-compatibility.ts` — added isThinkingCompatible() + THINKING_COMPATIBLE list
+- `src/components/chat/ChatView.tsx` — Think button: amber hint for non-thinking models, opacity dim
+- `src/hooks/useChat.ts` — double-guard: don't send think=true to incompatible models
### Test files (4 new):
- `src/api/__tests__/comfyui-models.test.ts` — classifyModel, MODEL_TYPE_DEFAULTS, COMPONENT_REGISTRY, determineStrategy (79 tests)
diff --git a/src/components/chat/ChatView.tsx b/src/components/chat/ChatView.tsx
index e084942f..bc2b3a30 100644
--- a/src/components/chat/ChatView.tsx
+++ b/src/components/chat/ChatView.tsx
@@ -12,7 +12,7 @@ import { AgentModeToggle } from './AgentModeToggle'
import { ErrorBoundary } from '../ui/ErrorBoundary'
import { useSettingsStore } from '../../stores/settingsStore'
import { FEATURE_FLAGS } from '../../lib/constants'
-import { isAgentCompatible } from '../../lib/model-compatibility'
+import { isAgentCompatible, isThinkingCompatible } from '../../lib/model-compatibility'
import { FileText, Bot, User, ChevronDown, Download, Brain, Wrench } from 'lucide-react'
import { TokenCounter } from './TokenCounter'
import { MemoryDebugToggle } from './MemoryDebugPanel'
@@ -34,10 +34,12 @@ export function ChatView() {
const [personaOpen, setPersonaOpen] = useState(false)
const [exportOpen, setExportOpen] = useState(false)
const [toolsDropdownOpen, setToolsDropdownOpen] = useState(false)
+ const [thinkHint, setThinkHint] = useState('')
const { getActivePersona, setActivePersona } = useSettingsStore()
const activePersona = getActivePersona()
const allPersonas = useSettingsStore((s) => s.personas)
const thinkingEnabled = useSettingsStore((s) => s.settings.thinkingEnabled)
+ const canThink = isThinkingCompatible(activeModel)
const updateSettings = useSettingsStore((s) => s.updateSettings)
const chatMode = useCodexStore((s) => s.chatMode)
@@ -121,18 +123,34 @@ export function ChatView() {
)}
{/* Thinking toggle */}
- <button
- onClick={() => updateSettings({ thinkingEnabled: !thinkingEnabled })}
- className={`flex items-center gap-1 px-2 py-0.5 rounded border transition-colors text-[0.55rem] ${
- thinkingEnabled
- ? 'border-blue-500/30 text-blue-400'
- : 'border-gray-200 dark:border-white/[0.06] text-gray-600'
- }`}
- title="Toggle thinking mode — model reasons before answering"
- >
- <Brain size={9} />
- <span>Think</span>
- </button>
+ <div className="relative">
+ <button
+ onClick={() => {
+ if (!canThink) {
+ setThinkHint(`${activeModel} doesn't support Think mode. Try QwQ, DeepSeek-R1, or Qwen3.`)
+ setTimeout(() => setThinkHint(''), 4000)
+ return
+ }
+ updateSettings({ thinkingEnabled: !thinkingEnabled })
+ }}
+ className={`flex items-center gap-1 px-2 py-0.5 rounded border transition-colors text-[0.55rem] ${
+ thinkingEnabled && canThink
+ ? 'border-blue-500/30 text-blue-400'
+ : !canThink
+ ? 'border-gray-200 dark:border-white/[0.06] text-gray-500 opacity-60'
+ : 'border-gray-200 dark:border-white/[0.06] text-gray-600'
+ }`}
+ title={canThink ? 'Toggle thinking mode — model reasons before answering' : `${activeModel} does not support thinking mode`}
+ >
+ <Brain size={9} />
+ <span>Think</span>
+ </button>
+ {thinkHint && (
+ <div className="absolute left-0 top-full mt-1 z-50 w-56 px-2 py-1.5 rounded-md bg-amber-900/90 text-amber-200 text-[0.6rem] leading-tight shadow-lg border border-amber-700/50">
+ {thinkHint}
+ </div>
+ )}
+ </div>
{/* Spacer */}
<div className="flex-1" />
diff --git a/src/hooks/useChat.ts b/src/hooks/useChat.ts
index e1d09905..87271bed 100644
--- a/src/hooks/useChat.ts
+++ b/src/hooks/useChat.ts
@@ -13,6 +13,7 @@ import { useAgentChat } from "./useAgentChat"
import { useMemory } from "./useMemory"
import { useAgentModeStore } from "../stores/agentModeStore"
import { getProviderForModel, getProviderIdFromModel } from "../api/providers"
+import { isThinkingCompatible } from "../lib/model-compatibility"
import type { ChatStreamChunk } from "../api/providers/types"
import type { ImageAttachment } from "../types/chat"
@@ -150,7 +151,7 @@ export function useChat() {
topP: settings.topP,
topK: settings.topK,
maxTokens: settings.maxTokens || undefined,
- thinking: settings.thinkingEnabled === true ? true : false,
+ thinking: settings.thinkingEnabled === true && isThinkingCompatible(activeModel),
signal: abort.signal,
},
)
diff --git a/src/lib/model-compatibility.ts b/src/lib/model-compatibility.ts
index 1c2e1a7e..99582a2a 100644
--- a/src/lib/model-compatibility.ts
+++ b/src/lib/model-compatibility.ts
@@ -50,6 +50,33 @@ export function isAgentCompatible(modelName: string): boolean {
export const isToolCallingModel = isAgentCompatible
export const hasNativeToolCalling = isAgentCompatible
+/**
+ * Models that support Ollama's native `think` parameter.
+ * When think=true is sent to a non-thinking model, Ollama returns HTTP 400.
+ */
+const THINKING_COMPATIBLE = [
+ 'qwq',
+ 'deepseek-r1',
+ 'qwen3', // Qwen 3.x has native thinking
+ 'qwen3.5',
+ 'qwen3-coder',
+ 'gemma3', // Gemma 3+ supports thinking via Ollama
+ 'gemma4',
+]
+
+/**
+ * Check if a model supports thinking/chain-of-thought mode.
+ * Cloud providers handle it gracefully. Ollama needs explicit support.
+ */
+export function isThinkingCompatible(modelName: string): boolean {
+ const providerId = getProviderIdFromModel(modelName)
+ if (providerId === 'openai' || providerId === 'anthropic') return true
+
+ const name = modelName.toLowerCase()
+ const baseName = name.replace(/^[^/]+\//, '').replace(/:.*$/, '').replace(/-abliterated/g, '').replace(/-uncensored/g, '')
+ return THINKING_COMPATIBLE.some(f => baseName.startsWith(f))
+}
+
export type ToolCallingStrategy = 'native' | 'template_fix' | 'hermes_xml'
/**