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): honest empty-reply handling + stop double thinking steering on cloud reasoners

purplec71fb2881388
diff --git a/src-tauri/src/commands/remote.rs b/src-tauri/src/commands/remote.rs
index e9f735ba..dc2922eb 100644
--- a/src-tauri/src/commands/remote.rs
+++ b/src-tauri/src/commands/remote.rs
@@ -1452,7 +1452,10 @@ button{-webkit-appearance:none;appearance:none}
var CODEX_PROMPT = 'You are the Coding Agent, an autonomous coding agent inside LU. You execute coding tasks end-to-end by reading files, writing code, and running shell commands. You MUST use tools — never guess file contents.\n\n=== HARD RULES ===\n\n1. AFTER EVERY TOOL RESULT, your very next message MUST be EITHER (a) another tool call to continue the work, OR (b) the final user-facing summary. Empty assistant messages are a FAILURE.\n\n2. DO NOT stop after the first tool. Real coding tasks take 3-15 tool calls. Stopping after one file_read or one shell_execute without producing the requested artefact = FAILURE. "I have called one tool, that is enough" is NOT a valid stop reason.\n\n3. NEVER say "Now I will create X" / "Next I\'ll write Y" as plain prose and then stop. Do the next step RIGHT NOW as a concrete tool call.\n\n4. When your plan has N steps, execute ALL N steps in one session — each step as a concrete tool call. Plan in tool-call form, not prose-then-stop.\n\n5. The ONLY reasons to stop calling tools: (a) the user task is FULLY done with concrete artefacts on disk, OR (b) you are stuck and genuinely need user input.\n\n=== WORKFLOW ===\n\n1. Understand the task.\n2. Explore (file_list, file_read, file_search) when you need to know existing layout.\n3. Plan changes (in your head, not as a stop point).\n4. Implement (file_write) — chain ALL writes without stopping.\n5. Verify (shell_execute / code_execute / file_read).\n6. Only THEN write a short summary of what you did.\n\n=== FILE & DIRECTORY RULES ===\n\n- file_write AUTOMATICALLY creates any missing parent directories. Never call shell_execute with `mkdir`, `New-Item -ItemType Directory`, `md`, or `os.makedirs` to set up a folder before writing — just file_write the target path directly.\n- All relative paths resolve to the current chat workspace folder. Always pass relative paths (e.g. `client/public/index.html`) — do not hard-code absolute drive paths.\n- shell_execute runs inside the workspace folder by default. Do not `cd` into a parent or sibling folder; prefer relative commands.\n- On Windows, the shell is PowerShell. Quote arguments with spaces. Use forward slashes in paths inside commands. Avoid `mkdir -p` (PowerShell mkdir does not accept -p) — again, just use file_write.\n\n=== GENERAL ===\n\n- Always read a file before modifying it.\n- Chain tool calls: after each tool result, if there is another step left, IMMEDIATELY call the next tool.\n- If a command fails, diagnose and retry with corrected arguments — do not introduce yourself again.\n- After 2-3 failures of the same approach, switch strategy (e.g. file_write instead of shell mkdir) instead of repeating.\n- Be concise in text. All real work happens in tool calls.\n- Respond in the same language the user used in their message.';
// ── Thinking-compatible prefixes (parity with desktop) ──
- var THINKING_COMPATIBLE = ['qwq','deepseek-r1','qwen3.6','qwen3','qwen3.5','qwen3-coder','gemma3','gemma4'];
+ // Keep in sync with THINKING_COMPATIBLE in src/lib/model-compatibility.ts.
+ // Mobile matches by PREFIX on the plain lowercased tag (no dash-collapse),
+ // so entries here are the literal Ollama tag prefixes.
+ var THINKING_COMPATIBLE = ['qwq','deepseek-r1','qwen3.6','qwen3','qwen3.5','qwen3-coder','gemma3','gemma4','gpt-oss','magistral','deepseek-v3.1','deepseek-v3.2','exaone-deep','phi4-reasoning','phi4-mini-reasoning','glm4.5','glm4.6','glm4.7','kimi-k2-thinking','minimax-m2'];
// ── Plain-text planner models — Gemma 3/4 ──
// Bug fix parity with desktop entry #80: Gemma 3/4 with `think:false`
diff --git a/src/api/__tests__/provider-finish-reason.test.ts b/src/api/__tests__/provider-finish-reason.test.ts
new file mode 100644
index 00000000..506ae23f
--- /dev/null
+++ b/src/api/__tests__/provider-finish-reason.test.ts
@@ -0,0 +1,154 @@
+/**
+ * finishReason + empty-reply plumbing tests (2026-07-12)
+ *
+ * A cloud reasoner (Qwen3.6 via LU Cloud) can burn its whole token budget
+ * inside the reasoning channel and never emit an answer token — the stream
+ * ends with finish_reason:"length" (or is cut by a proxy with no sentinel at
+ * all). The provider must surface WHY generation ended so the chat layer can
+ * explain the empty bubble instead of rendering silent dead air.
+ *
+ * Also covers: server-declared context_length from /models beating the name
+ * heuristic in getContextLength (long-chat max_tokens starvation), Ollama
+ * done_reason pass-through, and the widened THINKING_COMPATIBLE families.
+ *
+ * Run: npx vitest run src/api/__tests__/provider-finish-reason.test.ts
+ */
+import { describe, it, expect, vi, afterEach } from 'vitest'
+import { OpenAIProvider } from '../providers/openai-provider'
+import type { ProviderConfig, ChatStreamChunk } from '../providers/types'
+import { isThinkingCompatible } from '../../lib/model-compatibility'
+
+function makeConfig(overrides: Partial<ProviderConfig> = {}): ProviderConfig {
+ return {
+ id: 'openai',
+ name: 'TestProvider',
+ enabled: true,
+ baseUrl: 'https://api.test.com/v1',
+ apiKey: 'test-key',
+ isLocal: false,
+ ...overrides,
+ }
+}
+
+function sseResponse(events: string[]): Response {
+ return new Response(events.map(e => `data: ${e}\n\n`).join(''), {
+ status: 200,
+ headers: { 'Content-Type': 'text/event-stream' },
+ })
+}
+
+async function collect(gen: AsyncGenerator<ChatStreamChunk>): Promise<ChatStreamChunk[]> {
+ const out: ChatStreamChunk[] = []
+ for await (const c of gen) out.push(c)
+ return out
+}
+
+afterEach(() => {
+ vi.restoreAllMocks()
+})
+
+describe('chatStream finishReason', () => {
+ it("surfaces finish_reason 'length' on the done chunk (reasoning-only turn)", async () => {
+ const provider = new OpenAIProvider(makeConfig())
+ vi.spyOn(globalThis, 'fetch').mockResolvedValue(sseResponse([
+ '{"choices":[{"delta":{"reasoning_content":"thinking hard..."}}]}',
+ '{"choices":[{"delta":{},"finish_reason":"length"}]}',
+ '[DONE]',
+ ]))
+
+ const chunks = await collect(provider.chatStream('some-model', [{ role: 'user', content: 'hi' }]))
+ const thinking = chunks.filter(c => c.thinking)
+ const done = chunks.find(c => c.done)
+
+ expect(thinking.length).toBe(1)
+ expect(thinking[0].thinking).toBe('thinking hard...')
+ expect(done?.finishReason).toBe('length')
+ // No answer tokens ever arrived
+ expect(chunks.some(c => c.content && !c.done)).toBe(false)
+ })
+
+ it("defaults to 'stop' when [DONE] arrives without an explicit finish_reason", async () => {
+ const provider = new OpenAIProvider(makeConfig())
+ vi.spyOn(globalThis, 'fetch').mockResolvedValue(sseResponse([
+ '{"choices":[{"delta":{"content":"42"}}]}',
+ '[DONE]',
+ ]))
+
+ const chunks = await collect(provider.chatStream('some-model', [{ role: 'user', content: 'hi' }]))
+ expect(chunks.find(c => c.done)?.finishReason).toBe('stop')
+ })
+
+ it("tags a cleanly-cut stream (no [DONE], no finish_reason) as 'disconnect'", async () => {
+ const provider = new OpenAIProvider(makeConfig())
+ vi.spyOn(globalThis, 'fetch').mockResolvedValue(sseResponse([
+ '{"choices":[{"delta":{"reasoning_content":"reasoning that never finishe"}}]}',
+ // proxy idle-timeout closes the connection here — no sentinel
+ ]))
+
+ const chunks = await collect(provider.chatStream('some-model', [{ role: 'user', content: 'hi' }]))
+ expect(chunks.find(c => c.done)?.finishReason).toBe('disconnect')
+ })
+
+ it("keeps the server's finish_reason when the stream ends without [DONE]", async () => {
+ const provider = new OpenAIProvider(makeConfig())
+ vi.spyOn(globalThis, 'fetch').mockResolvedValue(sseResponse([
+ '{"choices":[{"delta":{"content":"partial"}}]}',
+ '{"choices":[{"delta":{},"finish_reason":"stop"}]}',
+ // server omits the [DONE] sentinel (some llama.cpp builds do)
+ ]))
+
+ const chunks = await collect(provider.chatStream('some-model', [{ role: 'user', content: 'hi' }]))
+ expect(chunks.find(c => c.done)?.finishReason).toBe('stop')
+ })
+})
+
+describe('getContextLength — server catalogue beats name heuristic', () => {
+ it('uses context_length from /models for cloud models after listModels ran', async () => {
+ const provider = new OpenAIProvider(makeConfig())
+ // Name heuristic alone would say 32768 for a qwen3.x name.
+ expect(await provider.getContextLength('Qwen/Qwen3.6-35B-A3B')).toBe(32768)
+
+ vi.spyOn(globalThis, 'fetch').mockResolvedValue(new Response(JSON.stringify({
+ data: [{
+ id: 'Qwen/Qwen3.6-35B-A3B', object: 'model',
+ context_length: 262144, think: 'toggle',
+ }],
+ }), { status: 200 }))
+ const models = await provider.listModels()
+ expect(models[0].contextLength).toBe(262144)
+
+ // The catalogue value must now win — otherwise applyMaxTokens computes
+ // headroom against 32k and starves long chats down to the 256 floor.
+ expect(await provider.getContextLength('Qwen/Qwen3.6-35B-A3B')).toBe(262144)
+ })
+})
+
+describe('THINKING_COMPATIBLE — post-2025 reasoning families (Ollama)', () => {
+ it.each([
+ 'gpt-oss:20b',
+ 'gpt-oss:120b',
+ 'magistral:24b',
+ 'deepseek-v3.1:671b',
+ 'deepseek-v3.2',
+ 'exaone-deep:7.8b',
+ 'phi4-reasoning',
+ 'phi4-reasoning:plus',
+ 'phi4-mini-reasoning',
+ 'glm4.6',
+ 'glm4.7:cloud',
+ 'kimi-k2-thinking',
+ 'minimax-m2',
+ 'huihui_ai/gpt-oss-abliterated:20b',
+ ])('enables the Think toggle for %s', (name) => {
+ expect(isThinkingCompatible(name)).toBe(true)
+ })
+
+ it.each([
+ 'deepseek-v3', // pre-3.1 — no think param
+ 'glm4:9b', // plain GLM4 is not a hybrid reasoner
+ 'llama3.1:8b',
+ 'mistral:7b',
+ ])('keeps the Think toggle off for %s', (name) => {
+ expect(isThinkingCompatible(name)).toBe(false)
+ })
+})
diff --git a/src/api/providers/anthropic-provider.ts b/src/api/providers/anthropic-provider.ts
index fe732588..53362cd9 100644
--- a/src/api/providers/anthropic-provider.ts
+++ b/src/api/providers/anthropic-provider.ts
@@ -164,23 +164,33 @@ export class AnthropicProvider implements ProviderClient {
}
case 'message_delta': {
- // End of message — flush tool calls
+ // End of message — flush tool calls. Map Anthropic's stop_reason
+ // onto the unified finishReason ('max_tokens' → 'length', the key
+ // the chat layer uses to explain thought-only/truncated turns).
+ const stopReason = (data.delta as any)?.stop_reason as string | undefined
const toolCalls = this.flushToolUseBlocks(toolUseBlocks)
- yield { content: '', toolCalls: toolCalls.length ? toolCalls : undefined, done: true }
+ yield {
+ content: '',
+ toolCalls: toolCalls.length ? toolCalls : undefined,
+ done: true,
+ finishReason: stopReason === 'max_tokens' ? 'length' : (stopReason || 'stop'),
+ }
return
}
case 'message_stop': {
const toolCalls2 = this.flushToolUseBlocks(toolUseBlocks)
- yield { content: '', toolCalls: toolCalls2.length ? toolCalls2 : undefined, done: true }
+ yield { content: '', toolCalls: toolCalls2.length ? toolCalls2 : undefined, done: true, finishReason: 'stop' }
return
}
}
}
- // If stream ended without explicit message_stop
+ // Stream ended without an explicit message_delta/message_stop — the
+ // connection was cut mid-generation (same semantics as the OpenAI
+ // provider's missing-[DONE] path).
const toolCalls = this.flushToolUseBlocks(toolUseBlocks)
- yield { content: '', toolCalls: toolCalls.length ? toolCalls : undefined, done: true }
+ yield { content: '', toolCalls: toolCalls.length ? toolCalls : undefined, done: true, finishReason: 'disconnect' }
}
async chatWithTools(
diff --git a/src/api/providers/ollama-provider.ts b/src/api/providers/ollama-provider.ts
index 8048b5f6..8be30644 100644
--- a/src/api/providers/ollama-provider.ts
+++ b/src/api/providers/ollama-provider.ts
@@ -19,6 +19,8 @@ import { repairToolCallArgs, extractToolCallsFromContent } from '../../lib/tool-
interface OllamaChatChunk {
message?: { content: string; thinking?: string; tool_calls?: { function: { name: string; arguments: Record<string, any> } }[] }
done?: boolean
+ // Why generation ended ('stop' | 'length' | 'load' | …), final chunk only.
+ done_reason?: string
// Server-reported timing in the final done:true chunk (Bug M v2.4.7).
// Ollama returns nanoseconds; we convert to ms before yielding upstream.
eval_count?: number // tokens the model produced
@@ -159,6 +161,7 @@ export class OllamaProvider implements ProviderClient {
thinking: chunk.message?.thinking || undefined,
toolCalls: toolCalls?.length ? toolCalls : undefined,
done: chunk.done || false,
+ finishReason: chunk.done_reason || undefined,
// Bug M v2.4.7 — pass through server-side generation metrics so the
// benchmark can report Ollama's own measurement instead of trusting
// client-side TTFT, which WebView2 release-mode buffers into
diff --git a/src/api/providers/openai-provider.ts b/src/api/providers/openai-provider.ts
index 69745799..e1aec159 100644
--- a/src/api/providers/openai-provider.ts
+++ b/src/api/providers/openai-provider.ts
@@ -138,6 +138,14 @@ function guessContextFromName(model: string): number {
export class OpenAIProvider implements ProviderClient {
readonly id = 'openai' as const
+ // Real context windows from the provider's /models catalogue (LU Cloud
+ // sends context_length per model). The name heuristic underestimates new
+ // cloud models badly (Qwen3.6-35B-A3B → 32k guess vs 262k real), which
+ // shrinks the applyMaxTokens headroom toward the 256 floor on long chats
+ // and truncates answers. Filled by listModels; instances are cached in the
+ // registry, so the catalogue survives across requests.
+ private catalogContext = new Map<string, number>()
+
constructor(private config: ProviderConfig) {}
private get baseUrl(): string {
@@ -257,12 +265,14 @@ export class OpenAIProvider implements ProviderClient {
const toolCallAccum: Map<number, { id: string; name: string; args: string }> = new Map()
let promptTokens = 0
let completionTokens = 0
- const doneChunk = (): ChatStreamChunk => {
+ let finishReason: string | undefined
+ const doneChunk = (fallbackReason: string): ChatStreamChunk => {
const toolCalls = this.flushToolCalls(toolCallAccum)
return {
content: '',
toolCalls: toolCalls.length ? toolCalls : undefined,
done: true,
+ finishReason: finishReason ?? fallbackReason,
promptEvalCount: promptTokens || undefined,
evalCount: completionTokens || undefined,
}
@@ -270,7 +280,7 @@ export class OpenAIProvider implements ProviderClient {
for await (const event of parseSSEStream(res)) {
if (event.data === '[DONE]') {
- yield doneChunk()
+ yield doneChunk('stop')
return
}
@@ -305,6 +315,13 @@ export class OpenAIProvider implements ProviderClient {
const choice = chunk.choices?.[0]
if (!choice) continue
+ // Capture WHY the model stopped ('stop', 'length', 'content_filter').
+ // 'length' with zero content is the reasoning-loop failure mode: the
+ // whole token budget went into thinking and no answer was ever written
+ // (David, cloud Qwen3.6, 2026-07-12) — the chat layer needs the reason
+ // to explain the empty bubble.
+ if (choice.finish_reason) finishReason = choice.finish_reason
+
const content = choice.delta?.content || ''
// Yield native reasoning as `thinking` so the panel fills live —
@@ -342,8 +359,13 @@ export class OpenAIProvider implements ProviderClient {
// chunk, which now carries the captured usage.
}
- // Stream ended without an explicit [DONE] sentinel.
- yield doneChunk()
+ // Stream ended without an explicit [DONE] sentinel. If the server also
+ // never sent a finish_reason, the connection was cut mid-generation
+ // (proxy idle-timeout, upstream drop) — a clean FIN ends parseSSEStream
+ // without any error, which used to masquerade as a normal completion and
+ // leave the user a silent empty bubble. Tag it 'disconnect' so the chat
+ // layer can say so.
+ yield doneChunk('disconnect')
}
async chatWithTools(
@@ -448,16 +470,24 @@ export class OpenAIProvider implements ProviderClient {
})))
}
- return models.map(m => ({
- id: m.id,
- name: m.name ?? m.id,
- provider: 'openai' as const,
- providerName: this.config.name,
- contextLength: m.context_length ?? KNOWN_CONTEXT[m.id] ?? guessContextFromName(m.id),
- supportsTools: true,
- supportsVision: m.input_modalities?.includes('image') || undefined,
- thinkMode: m.think,
- }))
+ return models.map(m => {
+ // Remember the server-declared window for applyMaxTokens (see
+ // catalogContext). Server value beats every heuristic — it reflects
+ // what THIS deployment actually serves.
+ if (m.context_length && m.context_length > 0) {
+ this.catalogContext.set(m.id, m.context_length)
+ }
+ return {
+ id: m.id,
+ name: m.name ?? m.id,
+ provider: 'openai' as const,
+ providerName: this.config.name,
+ contextLength: m.context_length ?? KNOWN_CONTEXT[m.id] ?? guessContextFromName(m.id),
+ supportsTools: true,
+ supportsVision: m.input_modalities?.includes('image') || undefined,
+ thinkMode: m.think,
+ }
+ })
}
async checkConnection(): Promise<boolean> {
@@ -531,10 +561,14 @@ export class OpenAIProvider implements ProviderClient {
async getContextLength(model: string): Promise<number> {
// Cascade:
- // 1. KNOWN_CONTEXT lookup (kein Network, instant)
- // 2. probeContextFromServer (LM Studio enhanced + generic /v1/models/<id>)
- // 3. Heuristik aus dem Modell-Namen
- // 4. Konservativer 8192er-Fallback (in guessContextFromName)
+ // 1. Server-declared context_length from the /models catalogue (LU
+ // Cloud) — authoritative for the deployment, beats every heuristic
+ // 2. KNOWN_CONTEXT lookup (kein Network, instant)
+ // 3. probeContextFromServer (LM Studio enhanced + generic /v1/models/<id>)
+ // 4. Heuristik aus dem Modell-Namen
+ // 5. Konservativer 8192er-Fallback (in guessContextFromName)
+ const catalog = this.catalogContext.get(model)
+ if (catalog && catalog > 0) return catalog
if (KNOWN_CONTEXT[model]) return KNOWN_CONTEXT[model]
const probed = await this.probeContextFromServer(model)
if (probed) return probed
diff --git a/src/api/providers/types.ts b/src/api/providers/types.ts
index bfdddc0d..4e7f9532 100644
--- a/src/api/providers/types.ts
+++ b/src/api/providers/types.ts
@@ -130,6 +130,12 @@ export interface ChatStreamChunk {
thinking?: string // Model reasoning (Ollama thinking field, <think> tags)
toolCalls?: ToolCall[]
done: boolean
+ // Why generation ended, on the final done:true chunk. 'stop' | 'length'
+ // (token budget exhausted — e.g. the whole budget went into reasoning) |
+ // 'disconnect' (the stream closed without any completion signal: proxy
+ // timeout, upstream cut). Lets the chat layer explain an empty reply
+ // instead of rendering silent dead air.
+ finishReason?: string
// Server-reported generation metrics (Bug M v2.4.7 — Ollama only). Released
// in the final done:true chunk. Authoritative tok/s = evalCount /
// (evalDurationMs / 1000). Prefer these over client-side JS timing whenever
diff --git a/src/hooks/useChat.ts b/src/hooks/useChat.ts
index d2b05c3f..703db14b 100644
--- a/src/hooks/useChat.ts
+++ b/src/hooks/useChat.ts
@@ -195,17 +195,24 @@ export function useChat() {
// Memory injection is non-critical
}
- // For non-Ollama providers, inject thinking via system prompt — but only
- // for models where the Think toggle actually applies. Server-declared
- // think capability (LU Cloud models carry thinkMode from /models) wins
- // over the local name-heuristic: 'always' reasoners use their native
- // channel untouched, 'never' instruct models get nothing (the blanket
- // injection made them burn billed tokens on reasoning we then discard).
+ // For non-Ollama providers, inject thinking via system prompt — but ONLY
+ // for endpoints that declared nothing about think capability (generic
+ // OpenAI-compat: LM Studio, vLLM, …). Models with a server-declared
+ // thinkMode (LU Cloud /models carries `think`) must NOT get the tag
+ // injection on top of reasoning_effort: the upstream already runs its
+ // native reasoning template/parser (reasoning_content channel), and a
+ // second, conflicting "write <think> tags, answer outside them"
+ // instruction can trap the model in a reasoning loop until the budget is
+ // gone — David's cloud Qwen3.6 burned 40k chars of thinking on "6×9" and
+ // never answered (2026-07-12). 'always' reasoners use their native
+ // channel untouched; 'never' instruct models get nothing (the blanket
+ // injection made them burn billed tokens on reasoning we then discard);
+ // 'toggle' models get reasoning_effort only.
const providerId = getProviderIdFromModel(activeModel)
const activeMeta = useModelStore.getState().models.find((m) => m.name === activeModel)
const thinkMode = activeMeta && 'thinkMode' in activeMeta ? activeMeta.thinkMode : undefined
const canThink = thinkMode ? thinkMode === 'toggle' : isThinkingCompatible(activeModel)
- if (settings.thinkingEnabled && providerId !== 'ollama' && canThink) {
+ if (settings.thinkingEnabled && providerId !== 'ollama' && canThink && thinkMode === undefined) {
systemPrompt = (systemPrompt || '') + '\n\nBefore answering, reason through your thinking inside <think></think> tags. Your thinking will be hidden from the user. After thinking, provide your answer outside the tags.'
}
@@ -338,6 +345,9 @@ export function useChat() {
// can still explain itself instead of rendering as a silent empty
// bubble (live find 2026-06-11: gemma4 + remembered tool results).
let hiddenThinking = ""
+ // Why the backend said generation ended ('length', 'disconnect', …) —
+ // drives the honest empty-reply explanation below.
+ let finishReason: string | undefined
for await (const chunk of stream) {
// Abort fast-path: if the user hit Stop while a thinking-heavy model
@@ -419,6 +429,7 @@ export function useChat() {
}
if (chunk.done) {
+ if (chunk.finishReason) finishReason = chunk.finishReason
// Final safety pass — catches any orphan tags that leaked through
// mid-stream (partial chunks, provider restarts, etc.).
contentRef.current = finalStripThinkingTags(contentRef.current, keepThinking)
@@ -456,12 +467,30 @@ export function useChat() {
// leaving the user staring at silent dead air forever.
if (!abort.signal.aborted && contentRef.current.trim() === "") {
const captured = (thinkingRef.current || finalStripThinkingTags(hiddenThinking, false)).trim()
+ // Honest, reason-specific note for the empty bubble. Before this, a
+ // thought-only turn with Thinking ON stored the reasoning but left
+ // content EMPTY — the user saw a collapsed Thinking pill and nothing
+ // else, which reads as a hang/crash (David, cloud Qwen3.6 2026-07-12:
+ // 40k chars of looped reasoning, token budget gone, zero answer).
+ const explanation =
+ finishReason === 'length'
+ ? (captured
+ ? 'The model spent its entire token budget thinking and never wrote the answer. Try again — reasoning is not deterministic — or turn Thinking off for this question.'
+ : 'The model hit its token limit before writing an answer. Try again, or raise Max Tokens in Settings.')
+ : finishReason === 'disconnect'
+ ? 'The connection dropped before the model finished its answer. Check your network and try again.'
+ : captured && keepThinking
+ ? 'The model finished thinking but never wrote an answer. Try again — or turn Thinking off for this question.'
+ : "I didn't return a visible answer that time — please try again."
if (captured && keepThinking) {
- // Thinking ON: surface the reasoning so the empty bubble explains
- // itself (MessageBubble renders it + a nudge) instead of dead air.
+ // Thinking ON: surface the reasoning AND say why there's no answer
+ // (the collapsed thinking pill alone reads as dead air).
useChatStore
.getState()
.updateMessageThinking(convId!, assistantMessage.id, captured)
+ useChatStore
+ .getState()
+ .updateMessageContent(convId!, assistantMessage.id, explanation)
} else if (captured) {
// Thinking OFF but the model still reasoned (Gemma keeps reasoning when
// we pass `think:undefined`) and produced no visible answer. David
@@ -471,11 +500,14 @@ export function useChat() {
// won't reach here; this covers a plain Q&A that thought itself out.)
useChatStore
.getState()
- .updateMessageContent(
- convId!,
- assistantMessage.id,
- "I didn't return a visible answer that time — please try again.",
- )
+ .updateMessageContent(convId!, assistantMessage.id, explanation)
+ } else if (finishReason === 'length' || finishReason === 'disconnect') {
+ // No reasoning captured either — the turn produced literally
+ // nothing because the budget ran out / the stream was cut. Still
+ // explain instead of leaving dead air.
+ useChatStore
+ .getState()
+ .updateMessageContent(convId!, assistantMessage.id, explanation)
}
}
} catch (err) {
diff --git a/src/lib/model-compatibility.ts b/src/lib/model-compatibility.ts
index 1ca06942..477e58aa 100644
--- a/src/lib/model-compatibility.ts
+++ b/src/lib/model-compatibility.ts
@@ -144,6 +144,21 @@ const THINKING_COMPATIBLE = [
'qwen3-coder',
'gemma3', // Gemma 3+ supports thinking via Ollama
'gemma4',
+ // Families below all take Ollama's `think` param (they shipped after the
+ // list above was written and the Think toggle stayed wrongly grayed out —
+ // David 2026-07-12: "guck, dass jedes Schema von den Models gedeckt ist").
+ // A false positive is caught by the retry-without-think fallback in
+ // useChat, so listing errs on the side of enabling the toggle.
+ 'gpt-oss', // OpenAI gpt-oss 20b/120b — thinking levels
+ 'magistral', // Mistral's reasoning line
+ 'deepseek-v3.1', // hybrid think/non-think
+ 'deepseek-v3.2',
+ 'exaone-deep',
+ 'phi4-reasoning', // covers phi-4-reasoning(+plus) after dash-collapse
+ 'phi4-mini-reasoning',
+ 'glm4.5', 'glm4.6', 'glm4.7', // GLM hybrid reasoning (NOT plain glm4:9b)
+ 'kimi-k2-thinking',
+ 'minimax-m2',
]
/**