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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(cloud): the off switch cannot silence the on switch
David84457d313bca
diff --git a/src/api/__tests__/provider-think-off.test.ts b/src/api/__tests__/provider-think-off.test.tsindex 718f2985..98074291 100644--- a/src/api/__tests__/provider-think-off.test.ts+++ b/src/api/__tests__/provider-think-off.test.ts@@ -100,17 +100,33 @@ describe('an endpoint that does not know none gets minimal, not nothing', () =>expect(bodyOf(spy, 1).reasoning_effort).toBe('minimal')})- it('an endpoint that knows neither ends up with no knob and no stream_options', async () => {+ it('stream_options is dropped on its own rung, before the knob', async () => {+ // The two fields get separate rungs so a 400 that stream_options caused is+ // never blamed on thinking. Dropping both at once and then crediting the+ // knob is how an endpoint that merely dislikes stream_options ended up+ // remembered as one that cannot think at all.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 }))+ await drain(new OpenAIProvider(makeConfig()).chatStream('m-no-stream-opts', [{ role: 'user', content: 'hi' }], { thinking: false }))expect(spy).toHaveBeenCalledTimes(3)- expect('reasoning_effort' in bodyOf(spy, 2)).toBe(false)+ expect(bodyOf(spy, 2).reasoning_effort).toBe('minimal')expect('stream_options' in bodyOf(spy, 2)).toBe(false)})+ 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(refuse())+ .mockResolvedValueOnce(okStream())+ await drain(new OpenAIProvider(makeConfig()).chatStream('m-ancient', [{ role: 'user', content: 'hi' }], { thinking: false }))+ expect(spy).toHaveBeenCalledTimes(4)+ expect('reasoning_effort' in bodyOf(spy, 3)).toBe(false)+ expect('stream_options' in bodyOf(spy, 3)).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())@@ -146,7 +162,7 @@ describe('the detour is paid once, not on every message', () => {expect(bodyOf(spy, 0).reasoning_effort).toBe('none')})- it('a refused high is remembered as no knob at all', async () => {+ it('a refused high is remembered, and the next ON message skips the knob', async () => {const provider = new OpenAIProvider(makeConfig())vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(refuse())@@ -154,12 +170,64 @@ describe('the detour is paid once, not on every message', () => {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 })+ await provider.chatWithTools('m-no-knob', [{ role: 'user', content: 'hi' }], [], { thinking: true })expect(spy).toHaveBeenCalledTimes(1)expect('reasoning_effort' in bodyOf(spy, 0)).toBe(false)})})+describe('what one direction of the switch learns never binds the other', () => {+ // The review of this very fix found the hole (2026-08-14). Endpoints with+ // the o1-era vocabulary accept low, medium and high while refusing both+ // 'none' and 'minimal'. With a single shared entry, one message sent with+ // thinking OFF walked all the way to "no knob" and that memory then+ // swallowed the user's 'high' forever after, with no note and no way back+ // short of restarting the app. The switch looked alive and did nothing.++ it('a walk to no knob with thinking OFF still leaves thinking ON at high', async () => {+ const provider = new OpenAIProvider(makeConfig())+ vi.spyOn(globalThis, 'fetch')+ .mockResolvedValueOnce(refuse())+ .mockResolvedValueOnce(refuse())+ .mockResolvedValueOnce(ok())+ await provider.chatWithTools('m-o1-era', [{ role: 'user', content: 'hi' }], [], { thinking: false })+ vi.restoreAllMocks()++ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())+ await provider.chatWithTools('m-o1-era', [{ role: 'user', content: 'hi' }], [], { thinking: true })+ expect(bodyOf(spy, 0).reasoning_effort).toBe('high')+ })++ it('a refused high does not cost the user the off switch', async () => {+ const provider = new OpenAIProvider(makeConfig())+ vi.spyOn(globalThis, 'fetch')+ .mockResolvedValueOnce(refuse())+ .mockResolvedValueOnce(ok())+ await provider.chatWithTools('m-on-only', [{ role: 'user', content: 'hi' }], [], { thinking: true })+ vi.restoreAllMocks()++ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())+ await provider.chatWithTools('m-on-only', [{ role: 'user', content: 'hi' }], [], { thinking: false })+ expect(bodyOf(spy, 0).reasoning_effort).toBe('none')+ })++ it('a 400 that stream_options caused is not remembered as a dead knob', async () => {+ const provider = new OpenAIProvider(makeConfig())+ // none refused, minimal refused, stream_options dropped and it goes through:+ // the endpoint understands minimal fine, it just never knew stream_options.+ vi.spyOn(globalThis, 'fetch')+ .mockResolvedValueOnce(refuse())+ .mockResolvedValueOnce(refuse())+ .mockResolvedValueOnce(okStream())+ await drain(provider.chatStream('m-blame', [{ role: 'user', content: 'hi' }], { thinking: false }))+ vi.restoreAllMocks()++ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())+ await provider.chatWithTools('m-blame', [{ role: 'user', content: 'hi' }], [], { thinking: false })+ expect(bodyOf(spy, 0).reasoning_effort).toBe('minimal')+ })+})+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, onediff --git a/src/api/providers/openai-provider.ts b/src/api/providers/openai-provider.tsindex 1dce7fa8..33c0c318 100644--- a/src/api/providers/openai-provider.ts+++ b/src/api/providers/openai-provider.ts@@ -246,10 +246,17 @@ export class OpenAIProvider implements ProviderClient {*/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'+ const walked = OpenAIProvider.effortMemory.get(this.catalogKey(model))+ if (thinking === true) return walked?.on === 'omit' ? undefined : 'high'+ if (walked?.off === 'omit') return undefined+ return walked?.off === 'minimal' ? 'minimal' : 'none'+ }++ /** Remember a walk, for one direction of the switch only. */+ private rememberEffort(model: string, lane: 'on' | 'off', value: 'minimal' | 'omit'): void {+ const key = this.catalogKey(model)+ const prev = OpenAIProvider.effortMemory.get(key) ?? {}+ OpenAIProvider.effortMemory.set(key, { ...prev, [lane]: value })}/**@@ -263,6 +270,11 @@ export class OpenAIProvider implements ProviderClient {* 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.+ *+ * stream_options gets its own rung ahead of dropping the knob, so a 400 that+ * field caused is never blamed on thinking. Dropping both at once and then+ * crediting the knob is how an endpoint that only dislikes stream_options+ * ended up remembered as one that cannot think at all.*/private async sendChat(model: string,@@ -278,20 +290,31 @@ export class OpenAIProvider implements ProviderClient {})const refused = (res: Response) => !res.ok && (res.status === 400 || res.status === 422)+ const asked = body.reasoning_effort as string | undefined+ const lane: 'on' | 'off' | undefined =+ asked === undefined ? undefined : asked === 'high' ? 'on' : 'off'+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+ if (refused(res) && 'stream_options' in body) {delete body.stream_optionsres = await post()- if (res.ok && hadEffort) OpenAIProvider.effortMemory.set(this.catalogKey(model), 'omit')+ }++ if (refused(res) && 'reasoning_effort' in body) {+ delete body.reasoning_effort+ res = await post()+ }++ if (res.ok && lane) {+ const survived = body.reasoning_effort as string | undefined+ if (survived === undefined) this.rememberEffort(model, lane, 'omit')+ else if (survived !== asked) this.rememberEffort(model, lane, 'minimal')}return res@@ -770,11 +793,17 @@ export class OpenAIProvider implements ProviderClient {/*** 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+ * keyed like probeCache. Absent means nothing has been refused here yet, so* a new endpoint always gets the value that actually disables thinking.* Only a successful request writes to this (see sendChat).+ *+ * Split by direction on purpose. An endpoint with the o1-era vocabulary+ * (low, medium, high) refuses both 'none' and 'minimal' while accepting+ * 'high' happily, so what we learn with the switch OFF says nothing about+ * the switch ON. One shared entry made a single OFF message silence the+ * user's thinking switch for the rest of the session.*/- private static effortMemory = new Map<string, 'minimal' | 'omit'>()+ private static effortMemory = new Map<string, { on?: 'omit'; off?: '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