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): thinking off means off on a third-party server too

purple75615654e159
diff --git a/src/api/__tests__/provider-think-off.test.ts b/src/api/__tests__/provider-think-off.test.ts
new file mode 100644
index 00000000..718f2985
--- /dev/null
+++ b/src/api/__tests__/provider-think-off.test.ts
@@ -0,0 +1,191 @@
+/**
+ * Thinking OFF has to mean off, on somebody else's server too.
+ *
+ * kevinmlynch, issue #112 on 2026-08-13, arrived with a trace and a working
+ * local patch: he points LU at DwarfStar, turns thinking off for his tool
+ * workflows, and gets reasoning anyway. We sent `reasoning_effort: 'minimal'`,
+ * the least the OpenAI API itself allows, and DwarfStar reads 'minimal' as
+ * `think_mode: high`. Our switch did the opposite of what it says. Only 'none'
+ * really disables it there.
+ *
+ * LU Cloud was never affected, the proxy already translates minimal to none.
+ * This is exactly the endpoints a user configures themselves.
+ *
+ * Swapping the literal is not enough, and useChat.ts:524 says why: 'none' is
+ * younger than 'minimal', an older API answers 400, and forcing a value on an
+ * always-thinker can 4xx as well. So the knob walks down over the retry path
+ * that already exists: none, then minimal, then gone.
+ *
+ * Test isolation: the walk is remembered per endpoint and model in a static
+ * map, so every test below uses its own model name.
+ *
+ * Run: npx vitest run src/api/__tests__/provider-think-off.test.ts
+ */
+import { describe, it, expect, vi, afterEach } from 'vitest'
+import { OpenAIProvider } from '../providers/openai-provider'
+import type { ProviderConfig } from '../providers/types'
+
+function makeConfig(overrides: Partial<ProviderConfig> = {}): ProviderConfig {
+ return {
+ id: 'openai',
+ name: 'TestProvider',
+ enabled: true,
+ baseUrl: 'https://third-party.test/v1',
+ apiKey: 'test-key',
+ isLocal: false,
+ ...overrides,
+ }
+}
+
+const ok = () => new Response(JSON.stringify({ choices: [{ message: { content: 'ok' } }] }), { status: 200 })
+const refuse = (status = 400) =>
+ new Response(JSON.stringify({ error: { message: 'unknown value for reasoning_effort' } }), { status })
+const okStream = () => new Response('data: {"choices":[{"delta":{"content":"hi"}}]}\n\ndata: [DONE]\n\n', { status: 200 })
+
+const bodyOf = (spy: any, call: number) => JSON.parse(spy.mock.calls[call][1]?.body as string)
+
+async function drain(gen: AsyncGenerator<any>) {
+ for await (const _ of gen) { /* consume, the fetch only happens on first next() */ }
+}
+
+afterEach(() => vi.restoreAllMocks())
+
+describe('the off switch sends the value that actually turns thinking off', () => {
+ it('chatWithTools sends none, not minimal', async () => {
+ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())
+ await new OpenAIProvider(makeConfig()).chatWithTools('m-off-tools', [{ role: 'user', content: 'hi' }], [], { thinking: false })
+ expect(bodyOf(spy, 0).reasoning_effort).toBe('none')
+ })
+
+ it('chatStream sends none too, it is the path a chat actually takes', async () => {
+ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(okStream())
+ await drain(new OpenAIProvider(makeConfig()).chatStream('m-off-stream', [{ role: 'user', content: 'hi' }], { thinking: false }))
+ expect(bodyOf(spy, 0).reasoning_effort).toBe('none')
+ })
+
+ it('thinking on is untouched at high', async () => {
+ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())
+ await new OpenAIProvider(makeConfig()).chatWithTools('m-on', [{ role: 'user', content: 'hi' }], [], { thinking: true })
+ expect(bodyOf(spy, 0).reasoning_effort).toBe('high')
+ })
+
+ it('a model with no declared think capability still sends no knob at all', async () => {
+ // useChat leaves `thinking` undefined for 'always' and 'never' models, so
+ // the upstream keeps deciding for itself. That must survive this change.
+ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())
+ await new OpenAIProvider(makeConfig()).chatWithTools('m-undef', [{ role: 'user', content: 'hi' }], [])
+ expect('reasoning_effort' in bodyOf(spy, 0)).toBe(false)
+ })
+})
+
+describe('an endpoint that does not know none gets minimal, not nothing', () => {
+ it('the second attempt carries minimal and keeps stream_options', async () => {
+ // The old code dropped both fields at the first complaint. Dropping the
+ // knob entirely is the one outcome that gives the user thinking back, so
+ // it stays the last resort and not the first answer.
+ const spy = vi.spyOn(globalThis, 'fetch')
+ .mockResolvedValueOnce(refuse())
+ .mockResolvedValueOnce(okStream())
+ await drain(new OpenAIProvider(makeConfig()).chatStream('m-old-api', [{ role: 'user', content: 'hi' }], { thinking: false }))
+ expect(spy).toHaveBeenCalledTimes(2)
+ expect(bodyOf(spy, 1).reasoning_effort).toBe('minimal')
+ expect(bodyOf(spy, 1).stream_options).toEqual({ include_usage: true })
+ })
+
+ it('422 walks the same ladder, that is DeepInfra bad-parameter status', async () => {
+ const spy = vi.spyOn(globalThis, 'fetch')
+ .mockResolvedValueOnce(refuse(422))
+ .mockResolvedValueOnce(ok())
+ await new OpenAIProvider(makeConfig()).chatWithTools('m-422', [{ role: 'user', content: 'hi' }], [], { thinking: false })
+ expect(bodyOf(spy, 1).reasoning_effort).toBe('minimal')
+ })
+
+ it('an endpoint that knows neither ends up with no knob and no stream_options', async () => {
+ const spy = vi.spyOn(globalThis, 'fetch')
+ .mockResolvedValueOnce(refuse())
+ .mockResolvedValueOnce(refuse())
+ .mockResolvedValueOnce(okStream())
+ await drain(new OpenAIProvider(makeConfig()).chatStream('m-ancient', [{ role: 'user', content: 'hi' }], { thinking: false }))
+ expect(spy).toHaveBeenCalledTimes(3)
+ expect('reasoning_effort' in bodyOf(spy, 2)).toBe(false)
+ expect('stream_options' in bodyOf(spy, 2)).toBe(false)
+ })
+
+ it('a refused high goes straight to no knob, it is not a step on the ladder', async () => {
+ const spy = vi.spyOn(globalThis, 'fetch')
+ .mockResolvedValueOnce(refuse())
+ .mockResolvedValueOnce(ok())
+ await new OpenAIProvider(makeConfig()).chatWithTools('m-high-refused', [{ role: 'user', content: 'hi' }], [], { thinking: true })
+ expect(spy).toHaveBeenCalledTimes(2)
+ expect('reasoning_effort' in bodyOf(spy, 1)).toBe(false)
+ })
+})
+
+describe('the detour is paid once, not on every message', () => {
+ it('after a successful step down, the next message starts at minimal', async () => {
+ const provider = new OpenAIProvider(makeConfig())
+ const spy = vi.spyOn(globalThis, 'fetch')
+ .mockResolvedValueOnce(refuse())
+ .mockResolvedValueOnce(ok())
+ .mockResolvedValueOnce(ok())
+ await provider.chatWithTools('m-memory', [{ role: 'user', content: 'one' }], [], { thinking: false })
+ await provider.chatWithTools('m-memory', [{ role: 'user', content: 'two' }], [], { thinking: false })
+ expect(spy).toHaveBeenCalledTimes(3)
+ expect(bodyOf(spy, 2).reasoning_effort).toBe('minimal')
+ })
+
+ it('the memory is per model, a sibling model still gets none', async () => {
+ const provider = new OpenAIProvider(makeConfig())
+ vi.spyOn(globalThis, 'fetch')
+ .mockResolvedValueOnce(refuse())
+ .mockResolvedValueOnce(ok())
+ await provider.chatWithTools('m-sibling-a', [{ role: 'user', content: 'hi' }], [], { thinking: false })
+ vi.restoreAllMocks()
+ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())
+ await provider.chatWithTools('m-sibling-b', [{ role: 'user', content: 'hi' }], [], { thinking: false })
+ expect(bodyOf(spy, 0).reasoning_effort).toBe('none')
+ })
+
+ it('a refused high is remembered as no knob at all', async () => {
+ const provider = new OpenAIProvider(makeConfig())
+ vi.spyOn(globalThis, 'fetch')
+ .mockResolvedValueOnce(refuse())
+ .mockResolvedValueOnce(ok())
+ await provider.chatWithTools('m-no-knob', [{ role: 'user', content: 'hi' }], [], { thinking: true })
+ vi.restoreAllMocks()
+ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())
+ await provider.chatWithTools('m-no-knob', [{ role: 'user', content: 'hi' }], [], { thinking: false })
+ expect(spy).toHaveBeenCalledTimes(1)
+ expect('reasoning_effort' in bodyOf(spy, 0)).toBe(false)
+ })
+})
+
+describe('a 400 for an unrelated reason teaches nothing', () => {
+ // The load-bearing one. An overlong context is the everyday 400, and it
+ // walks this exact ladder. If a failed walk wrote to the memory, one
+ // oversized message would cost the user their off switch for the whole
+ // session, on an endpoint that supports it perfectly well.
+ it('when every attempt fails, the next message starts at none again', async () => {
+ const provider = new OpenAIProvider(makeConfig())
+ vi.spyOn(globalThis, 'fetch')
+ .mockResolvedValueOnce(refuse())
+ .mockResolvedValueOnce(refuse())
+ .mockResolvedValueOnce(refuse())
+ await expect(
+ provider.chatWithTools('m-context-blown', [{ role: 'user', content: 'war and peace' }], [], { thinking: false }),
+ ).rejects.toBeTruthy()
+ vi.restoreAllMocks()
+
+ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())
+ await provider.chatWithTools('m-context-blown', [{ role: 'user', content: 'short' }], [], { thinking: false })
+ expect(bodyOf(spy, 0).reasoning_effort).toBe('none')
+ })
+
+ it('a 500 is not a refusal and is not retried at all', async () => {
+ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(new Response('boom', { status: 500 }))
+ await expect(
+ new OpenAIProvider(makeConfig()).chatWithTools('m-500', [{ role: 'user', content: 'hi' }], [], { thinking: false }),
+ ).rejects.toBeTruthy()
+ expect(spy).toHaveBeenCalledTimes(1)
+ })
+})
diff --git a/src/api/providers/openai-provider.ts b/src/api/providers/openai-provider.ts
index 888ad300..1dce7fa8 100644
--- a/src/api/providers/openai-provider.ts
+++ b/src/api/providers/openai-provider.ts
@@ -229,6 +229,74 @@ export class OpenAIProvider implements ProviderClient {
}
}
+ /**
+ * The thinking knob for this request, or undefined to leave it out.
+ *
+ * Toggle OFF used to send 'minimal', the least the OpenAI API itself allows.
+ * kevinmlynch traced what that means elsewhere (#112, 2026-08-13): DwarfStar
+ * reads 'minimal' as think_mode high, so our OFF switch turned thinking ON
+ * and his tool workflows paid the latency he had just disabled. Only 'none'
+ * really disables it. Our own cloud proxy already translates minimal to
+ * none, so this never showed up on LU Cloud, only on servers users point us
+ * at themselves.
+ *
+ * 'none' is younger than 'minimal' though, and an endpoint that predates it
+ * answers 400. So sendChat walks the knob down instead of swapping it, and
+ * remembers how far it had to walk, per endpoint and model.
+ */
+ private thinkingEffort(model: string, thinking: boolean | undefined): string | undefined {
+ if (thinking === undefined) return undefined
+ const floor = OpenAIProvider.effortMemory.get(this.catalogKey(model))
+ if (floor === 'omit') return undefined
+ if (thinking === true) return 'high'
+ return floor === 'minimal' ? 'minimal' : 'none'
+ }
+
+ /**
+ * POST a chat body, stepping the thinking knob down rather than dropping it
+ * at the first complaint: 'none', then 'minimal', then gone. The last step
+ * also drops stream_options, the other field an endpoint that predates both
+ * rejects. The LU Cloud proxy deliberately passes upstream 400 AND 422
+ * (DeepInfra's bad-parameter status) through so this path can engage.
+ *
+ * Only a request that then SUCCEEDS teaches us anything. A 400 for an
+ * unrelated reason (an overlong context is the common one) walks the same
+ * ladder and must not leave a memory behind, or one oversized message would
+ * cost the user their thinking switch for the rest of the session.
+ */
+ private async sendChat(
+ model: string,
+ body: Record<string, any>,
+ signal: AbortSignal | undefined,
+ fetcher: (url: string, init: any) => Promise<Response>,
+ ): Promise<Response> {
+ const post = () => fetcher(`${this.baseUrl}/chat/completions`, {
+ method: 'POST',
+ headers: this.headers,
+ body: JSON.stringify(body),
+ signal,
+ })
+ const refused = (res: Response) => !res.ok && (res.status === 400 || res.status === 422)
+
+ let res = await this.sendOrExplain(post)
+
+ if (refused(res) && body.reasoning_effort === 'none') {
+ body.reasoning_effort = 'minimal'
+ res = await post()
+ if (res.ok) OpenAIProvider.effortMemory.set(this.catalogKey(model), 'minimal')
+ }
+
+ if (refused(res) && ('reasoning_effort' in body || 'stream_options' in body)) {
+ const hadEffort = 'reasoning_effort' in body
+ delete body.reasoning_effort
+ delete body.stream_options
+ res = await post()
+ if (res.ok && hadEffort) OpenAIProvider.effortMemory.set(this.catalogKey(model), 'omit')
+ }
+
+ return res
+ }
+
private get headers(): Record<string, string> {
const h: Record<string, string> = {
'Content-Type': 'application/json',
@@ -300,12 +368,11 @@ export class OpenAIProvider implements ProviderClient {
body.tool_choice = 'auto'
}
await this.applyMaxTokens(model, body, options)
- // Reasoning-model knob (o1, o3, gpt-5-thinking, etc.). Toggle OFF →
- // "minimal" (least reasoning the API allows). Toggle ON → "high".
- // Non-reasoning models simply ignore this field; older APIs may 400 on
- // it — we handle that with a retry below.
- if (options?.thinking === true) body.reasoning_effort = 'high'
- else if (options?.thinking === false) body.reasoning_effort = 'minimal'
+ // Reasoning-model knob (o1, o3, gpt-5-thinking, etc.). Toggle ON → "high",
+ // toggle OFF → "none". Non-reasoning models simply ignore the field; an
+ // endpoint that rejects it is handled by the ladder in sendChat.
+ const effort = this.thinkingEffort(model, options?.thinking)
+ if (effort) body.reasoning_effort = effort
// Ask the server for REAL token usage in a final stream chunk
// (choices:[] + usage:{...}). OpenAI, DeepInfra (LU Cloud), Groq, vLLM and
// LM Studio all honor stream_options; an endpoint that rejects unknown
@@ -321,26 +388,7 @@ export class OpenAIProvider implements ProviderClient {
if (this.useLocalProxy) await ensureProxyAllowsHost(this.baseUrl)
const fetcher = this.useLocalProxy ? localFetchStream : fetch
- let res = await this.sendOrExplain(() => fetcher(`${this.baseUrl}/chat/completions`, {
- method: 'POST',
- headers: this.headers,
- body: JSON.stringify(body),
- signal: options?.signal,
- } as any))
-
- // Retry without reasoning_effort if the model/endpoint rejects it. The LU
- // Cloud proxy deliberately passes upstream 400 AND 422 (DeepInfra's
- // bad-parameter status) through so this path can engage.
- if (!res.ok && (res.status === 400 || res.status === 422) && ('reasoning_effort' in body || 'stream_options' in body)) {
- delete body.reasoning_effort
- delete body.stream_options
- res = await fetcher(`${this.baseUrl}/chat/completions`, {
- method: 'POST',
- headers: this.headers,
- body: JSON.stringify(body),
- signal: options?.signal,
- } as any)
- }
+ const res = await this.sendChat(model, body, options?.signal, fetcher as any)
if (!res.ok) {
throw await this.parseError(res)
@@ -484,8 +532,8 @@ export class OpenAIProvider implements ProviderClient {
if (options?.topP !== undefined) body.top_p = options.topP
await this.applyMaxTokens(model, body, options)
// Same reasoning_effort gate as chatStream.
- if (options?.thinking === true) body.reasoning_effort = 'high'
- else if (options?.thinking === false) body.reasoning_effort = 'minimal'
+ const effort = this.thinkingEffort(model, options?.thinking)
+ if (effort) body.reasoning_effort = effort
// Same self-heal as chatStream: agent/tool turns after a Create render
// must revive the offloaded built-in engine before hitting its port.
@@ -493,23 +541,7 @@ export class OpenAIProvider implements ProviderClient {
if (this.useLocalProxy) await ensureProxyAllowsHost(this.baseUrl)
const fetcher = this.useLocalProxy ? localFetch : fetch
- let res = await this.sendOrExplain(() => fetcher(`${this.baseUrl}/chat/completions`, {
- method: 'POST',
- headers: this.headers,
- body: JSON.stringify(body),
- signal: options?.signal,
- } as any))
-
- if (!res.ok && (res.status === 400 || res.status === 422) && ('reasoning_effort' in body || 'stream_options' in body)) {
- delete body.reasoning_effort
- delete body.stream_options
- res = await fetcher(`${this.baseUrl}/chat/completions`, {
- method: 'POST',
- headers: this.headers,
- body: JSON.stringify(body),
- signal: options?.signal,
- } as any)
- }
+ const res = await this.sendChat(model, body, options?.signal, fetcher as any)
if (!res.ok) {
throw await this.parseError(res, tools.length > 0)
@@ -736,6 +768,14 @@ export class OpenAIProvider implements ProviderClient {
* field: the lu-cloud provider builds a fresh delegate per call. */
private static probeCache = new Map<string, { at: number; ctx: number | null }>()
+ /**
+ * How far the thinking knob had to be walked down for an endpoint and model,
+ * keyed like probeCache. Absent means 'none' has never been refused here, so
+ * a new endpoint always gets the value that actually disables thinking.
+ * Only a successful request writes to this (see sendChat).
+ */
+ private static effortMemory = new Map<string, 'minimal' | 'omit'>()
+
/** Live tool-capability answers per endpoint (G37b). Static for the same
* reason as probeCache, and TTL-bound like it: an LM Studio reload or an
* engine swap with a different template lands within 5 minutes. */