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(effort): der Stufen-Abstieg im Client faellt weg

purplee5d88c16c28e
diff --git a/src/api/__tests__/provider-effort-ladder.test.ts b/src/api/__tests__/provider-effort-ladder.test.ts
index cb918874..375be3f4 100644
--- a/src/api/__tests__/provider-effort-ladder.test.ts
+++ b/src/api/__tests__/provider-effort-ladder.test.ts
@@ -11,9 +11,12 @@
* (ops/wissen/deepinfra-modellmatrix-2026-09-02.md):
*
* - Qwen/Qwen3.8-27B answers 400 to 'high' and to 'max', naming 'low' and
- * 'medium'. Dropping the parameter on that 400 hands the turn to the
- * upstream default, which is the most expensive setting there is. Stepping
- * one rung down keeps the reasoning AND the price the user asked for.
+ * 'medium'. That is why the ladder is per model and why the wish is clamped
+ * onto it BEFORE the request leaves. The clamping happens on the server too,
+ * so a rung off the ladder never reaches the upstream and never comes back
+ * as a 4xx; the client therefore does not walk the rungs on a 4xx, because
+ * the everyday 4xx is an overlong context and has nothing to do with the
+ * knob.
* - On GLM 5.3, 'none' does not stop the thinking. It only stops the upstream
* from separating it, so the monologue lands in the customer's chat window
* and costs more tokens than sending nothing at all. GLM 5.3 is a
@@ -119,129 +122,120 @@ describe('a model that always reasons never gets none', () => {
})
})
-describe('a refused rung steps down the ladder instead of vanishing', () => {
- it('THE MEASUREMENT: a 400 on high lands on medium, not on no knob', async () => {
+describe('a 4xx is NEVER blamed on the rung', () => {
+ // The server clamps every rung it knows onto the model's own ladder before
+ // the request leaves the proxy, so a rung off this ladder does not come back
+ // as a 400. What DOES come back as a 400 every day is an overlong context.
+ // A client-side walk down the rungs would spend a post per rung on it, blame
+ // the knob, and then remember a downgrade that nothing ever clears.
+ it('THE RULE: a foreign 400 leaves the chosen rung exactly as it was', async () => {
const spy = vi.spyOn(globalThis, 'fetch')
.mockResolvedValueOnce(refuse())
.mockResolvedValueOnce(ok())
await new OpenAIProvider(makeConfig()).chatWithTools(
- 'e-step', [{ role: 'user', content: 'hi' }], [],
- { thinking: true, reasoningEffort: 'high', effortLevels: ['low', 'medium', 'high'] },
+ 'e-foreign-400', [{ role: 'user', content: 'war and peace' }], [],
+ { thinking: true, reasoningEffort: 'max', effortLevels: GLM53 },
)
+ // Two posts: the request, then the one rung that has always existed, which
+ // is dropping the knob. No 'high', no 'medium', no 'low' in between.
expect(spy).toHaveBeenCalledTimes(2)
- expect(bodyOf(spy, 1).reasoning_effort).toBe('medium')
+ expect(bodyOf(spy, 0).reasoning_effort).toBe('max')
+ expect('reasoning_effort' in bodyOf(spy, 1)).toBe(false)
})
- it('walks further down while the upstream keeps refusing', async () => {
- const spy = vi.spyOn(globalThis, 'fetch')
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(ok())
- await new OpenAIProvider(makeConfig()).chatWithTools(
- 'e-step-twice', [{ role: 'user', content: 'hi' }], [],
- { thinking: true, reasoningEffort: 'max', effortLevels: GLM53 },
- )
- expect(spy).toHaveBeenCalledTimes(3)
- expect(bodyOf(spy, 2).reasoning_effort).toBe('medium')
- })
+ it('and one bad message does not cost the rung for the rest of the session', async () => {
+ const provider = new OpenAIProvider(makeConfig())
+ vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(refuse()).mockResolvedValueOnce(refuse())
+ await expect(
+ provider.chatWithTools(
+ 'e-context-blown', [{ role: 'user', content: 'war and peace' }], [],
+ { thinking: true, reasoningEffort: 'high', effortLevels: GLM53 },
+ ),
+ ).rejects.toBeTruthy()
+ vi.restoreAllMocks()
- it('an accepted rung is never thrown away for the next one', async () => {
- const spy = vi.spyOn(globalThis, 'fetch')
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(ok())
- .mockResolvedValueOnce(ok())
- await new OpenAIProvider(makeConfig()).chatWithTools(
- 'e-stop-at-yes', [{ role: 'user', content: 'hi' }], [],
- { thinking: true, reasoningEffort: 'max', effortLevels: GLM53 },
+ const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())
+ await provider.chatWithTools(
+ 'e-context-blown', [{ role: 'user', content: 'short' }], [],
+ { thinking: true, reasoningEffort: 'high', effortLevels: GLM53 },
)
- expect(spy).toHaveBeenCalledTimes(2)
- expect(bodyOf(spy, 1).reasoning_effort).toBe('high')
+ expect(bodyOf(spy, 0).reasoning_effort).toBe('high')
})
- it('and the knob is only dropped once the whole ladder is exhausted', async () => {
+ it('the walk never invents a cheaper rung, it only ever drops the field', async () => {
const spy = vi.spyOn(globalThis, 'fetch')
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(refuse())
.mockResolvedValueOnce(refuse())
.mockResolvedValueOnce(ok())
await new OpenAIProvider(makeConfig()).chatWithTools(
- 'e-exhausted', [{ role: 'user', content: 'hi' }], [],
- { thinking: true, reasoningEffort: 'high', effortLevels: ['low', 'medium', 'high'] },
+ 'e-no-invention', [{ role: 'user', content: 'hi' }], [],
+ { reasoningEffort: 'max', effortLevels: GLM53 },
)
- expect(spy).toHaveBeenCalledTimes(4)
- expect('reasoning_effort' in bodyOf(spy, 3)).toBe(false)
+ const sent = spy.mock.calls.map((_c, i) => bodyOf(spy, i).reasoning_effort)
+ expect(sent).toEqual(['max', undefined])
+ expect(sent).not.toContain('high')
+ expect(sent).not.toContain('none')
+ expect(sent).not.toContain('minimal')
})
- it('the step down NEVER lands on none, not even at the bottom of the ladder', async () => {
+ it('and on the streaming path stream_options keeps its own rung ahead of the knob', async () => {
+ // The rung that has always been there: a 400 that stream_options caused is
+ // never blamed on thinking, so the chosen rung survives that step untouched.
const spy = vi.spyOn(globalThis, 'fetch')
.mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(ok())
- await new OpenAIProvider(makeConfig()).chatWithTools(
- 'e-never-none', [{ role: 'user', content: 'hi' }], [],
- { reasoningEffort: 'max', effortLevels: ['low', 'high', 'max'] },
- )
- const sent = spy.mock.calls.map((_c, i) => bodyOf(spy, i).reasoning_effort)
- expect(sent).toEqual(['max', 'high', 'low', undefined])
- expect(sent).not.toContain('none')
- expect(sent).not.toContain('minimal')
+ .mockResolvedValueOnce(okStream())
+ await drain(new OpenAIProvider(makeConfig()).chatStream(
+ 'e-stream-rung', [{ role: 'user', content: 'hi' }],
+ { reasoningEffort: 'max', effortLevels: GLM53 },
+ ))
+ expect(spy).toHaveBeenCalledTimes(2)
+ expect(bodyOf(spy, 1).reasoning_effort).toBe('max')
+ expect('stream_options' in bodyOf(spy, 1)).toBe(false)
})
})
describe('the memory belongs to one rung, not to the whole switch', () => {
- it('what a refused max taught is not charged to low', async () => {
+ it('a max that had to give the knob up does not take low down with it', async () => {
const provider = new OpenAIProvider(makeConfig())
- vi.spyOn(globalThis, 'fetch')
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(ok())
+ vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(refuse()).mockResolvedValueOnce(ok())
await provider.chatWithTools(
'e-rungs', [{ role: 'user', content: 'hi' }], [],
- { thinking: true, reasoningEffort: 'max', effortLevels: ['low', 'medium', 'max'] },
+ { thinking: true, reasoningEffort: 'max', effortLevels: GLM53 },
)
vi.restoreAllMocks()
const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())
await provider.chatWithTools(
'e-rungs', [{ role: 'user', content: 'hi' }], [],
- { thinking: true, reasoningEffort: 'low', effortLevels: ['low', 'medium', 'max'] },
+ { thinking: true, reasoningEffort: 'low', effortLevels: GLM53 },
)
expect(spy).toHaveBeenCalledTimes(1)
expect(bodyOf(spy, 0).reasoning_effort).toBe('low')
})
- it('a rung that had to step down starts at the rung that worked next time', async () => {
+ it('but the same rung remembers, so the detour is paid once', async () => {
const provider = new OpenAIProvider(makeConfig())
- vi.spyOn(globalThis, 'fetch')
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(ok())
+ vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(refuse()).mockResolvedValueOnce(ok())
await provider.chatWithTools(
'e-learned', [{ role: 'user', content: 'one' }], [],
- { thinking: true, reasoningEffort: 'high', effortLevels: ['low', 'medium', 'high'] },
+ { thinking: true, reasoningEffort: 'high', effortLevels: GLM53 },
)
vi.restoreAllMocks()
const spy = vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(ok())
await provider.chatWithTools(
'e-learned', [{ role: 'user', content: 'two' }], [],
- { thinking: true, reasoningEffort: 'high', effortLevels: ['low', 'medium', 'high'] },
+ { thinking: true, reasoningEffort: 'high', effortLevels: GLM53 },
)
expect(spy).toHaveBeenCalledTimes(1)
- expect(bodyOf(spy, 0).reasoning_effort).toBe('medium')
+ expect('reasoning_effort' in bodyOf(spy, 0)).toBe(false)
})
it('and the off switch keeps its own memory, untouched by any of it', async () => {
const provider = new OpenAIProvider(makeConfig())
- vi.spyOn(globalThis, 'fetch')
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(refuse())
- .mockResolvedValueOnce(ok())
+ vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(refuse()).mockResolvedValueOnce(ok())
await provider.chatWithTools(
'e-lanes', [{ role: 'user', content: 'hi' }], [],
- { thinking: true, reasoningEffort: 'high', effortLevels: ['low', 'medium', 'high'] },
+ { thinking: true, reasoningEffort: 'high', effortLevels: GLM53 },
)
vi.restoreAllMocks()
diff --git a/src/api/providers/openai-provider.ts b/src/api/providers/openai-provider.ts
index 7dfb90e1..4d5fc7a5 100644
--- a/src/api/providers/openai-provider.ts
+++ b/src/api/providers/openai-provider.ts
@@ -21,7 +21,7 @@ import { parseRetryAfter } from '../../lib/http-status'
import { localFetch, localFetchStream, isPrivateOrLanHost, isDirectFetchAllowed, hostnameOf, ensureProxyAllowsHost, backendCall } from '../backend'
import { ensureBuiltinEngineAlive, explainDeadEngine, explainEngineTransportMessage, isManagedBuiltinSlot } from '../builtin-ensure'
import { applyTemplateContract } from './normalize-system'
-import { clampEffort, hasEffortLadder, lowerEffort, DEFAULT_EFFORT } from '../../lib/effort'
+import { clampEffort, hasEffortLadder, DEFAULT_EFFORT } from '../../lib/effort'
// Transport routing lives in the `useLocalProxy` getter (below) plus the shared
// host helpers in backend.ts. A direct webview fetch only works for hosts the
@@ -309,12 +309,18 @@ export class OpenAIProvider implements ProviderClient {
// ON: the wish, clamped onto the rungs this model really has. Without a
// ladder that is DEFAULT_EFFORT, which is the 'high' this client has always
// sent.
+ //
+ // There is no client-side walk down the rungs. The server clamps every rung
+ // it knows onto the model's own ladder before the request leaves the proxy,
+ // so a rung off this ladder does not come back as a 4xx. Walking it here
+ // would only blame the everyday 400 (an overlong context) on the knob, cost
+ // up to seven posts for one message, and leave a downgrade in the memory
+ // that nothing ever clears.
const wanted = ladder
? clampEffort(levels, options?.reasoningEffort ?? DEFAULT_EFFORT)
: DEFAULT_EFFORT
const walked = OpenAIProvider.effortMemory.get(this.effortKey(model, 'on', wanted))
- if (walked?.on === 'omit') return undefined
- return walked?.on ?? wanted
+ return walked?.on === 'omit' ? undefined : wanted
}
/**
@@ -323,8 +329,9 @@ export class OpenAIProvider implements ProviderClient {
* The OFF lane is a single switch position, so one key per model does. The ON
* lane has as many positions as the model has rungs and they are NOT
* interchangeable: Qwen/Qwen3.8-27B answers 400 to 'high' and serves
- * 'medium' without complaint (live measurement 2026-09-02). Keyed by rung,
- * what a refused 'max' teaches can never be charged to 'low'.
+ * 'medium' without complaint (live measurement 2026-09-02). Keyed by rung, a
+ * 'max' that had to give the knob up cannot take 'low' down with it, the same
+ * way the ON lane has never been allowed to take the OFF lane down with it.
*/
private effortKey(model: string, lane: 'on' | 'off', rung?: string): string {
const base = this.catalogKey(model)
@@ -366,11 +373,11 @@ export class OpenAIProvider implements ProviderClient {
}
/** Remember a walk, for one lane and one rung only. */
- private rememberEffort(key: string, lane: 'on' | 'off', value: string): void {
+ private rememberEffort(key: string, lane: 'on' | 'off', value: 'minimal' | 'omit'): void {
const prev = OpenAIProvider.effortMemory.get(key) ?? {}
const next = { ...prev }
- if (lane === 'on') next.on = value
- else next.off = value === 'omit' ? 'omit' : 'minimal'
+ if (lane === 'on') next.on = 'omit'
+ else next.off = value
OpenAIProvider.effortMemory.set(key, next)
}
@@ -396,7 +403,6 @@ export class OpenAIProvider implements ProviderClient {
body: Record<string, any>,
signal: AbortSignal | undefined,
fetcher: (url: string, init: any) => Promise<Response>,
- levels?: string[],
): Promise<Response> {
const post = () => fetcher(`${this.baseUrl}/chat/completions`, {
method: 'POST',
@@ -427,22 +433,6 @@ export class OpenAIProvider implements ProviderClient {
res = await post()
}
- // ON lane: step DOWN the model's own ladder before giving the knob up.
- // Qwen/Qwen3.8-27B refuses 'high' and 'max' with a 400 and reasons happily
- // at 'medium' (live measurement 2026-09-02); dropping the field instead
- // hands the turn to the upstream default, which is the most expensive
- // setting there is. The walk stops at the first rung that is accepted, so
- // an accepted rung is never thrown away for the sake of the next one.
- if (lane === 'on' && levels?.length) {
- for (let step = levels.length; step > 0; step--) {
- if (stopped() || !refused(res)) break
- const lower = lowerEffort(levels, body.reasoning_effort as string)
- if (!lower) break
- body.reasoning_effort = lower
- res = await post()
- }
- }
-
// Its own rung, ahead of both the knob and stream_options: a server that
// refuses the template kwargs must not be remembered as one that cannot
// think. Dropped for the whole endpoint once it succeeds without it, so
@@ -466,7 +456,7 @@ export class OpenAIProvider implements ProviderClient {
if (res.ok && lane) {
const survived = body.reasoning_effort as string | undefined
if (survived === undefined) this.rememberEffort(memoryKey, lane, 'omit')
- else if (survived !== asked) this.rememberEffort(memoryKey, lane, survived)
+ else if (survived !== asked) this.rememberEffort(memoryKey, lane, 'minimal')
}
return res
@@ -572,7 +562,7 @@ export class OpenAIProvider implements ProviderClient {
if (this.useLocalProxy) await ensureProxyAllowsHost(this.baseUrl)
const fetcher = this.useLocalProxy ? localFetchStream : fetch
- const res = await this.sendChat(model, body, options?.signal, fetcher as any, options?.effortLevels)
+ const res = await this.sendChat(model, body, options?.signal, fetcher as any)
if (!res.ok) {
throw await this.parseError(res)
@@ -729,7 +719,7 @@ export class OpenAIProvider implements ProviderClient {
if (this.useLocalProxy) await ensureProxyAllowsHost(this.baseUrl)
const fetcher = this.useLocalProxy ? localFetch : fetch
- const res = await this.sendChat(model, body, options?.signal, fetcher as any, options?.effortLevels)
+ const res = await this.sendChat(model, body, options?.signal, fetcher as any)
if (!res.ok) {
throw await this.parseError(res, tools.length > 0)
@@ -974,9 +964,9 @@ export class OpenAIProvider implements ProviderClient {
* user's thinking switch for the rest of the session.
*/
// Keyed by effortKey(): one entry per model for the OFF lane, one per model
- // AND rung for the ON lane. `on` holds either 'omit' or the rung the upstream
- // actually accepted after a walk down the ladder.
- private static effortMemory = new Map<string, { on?: string; off?: 'minimal' | 'omit' }>()
+ // AND rung for the ON lane. The only thing either lane can learn is 'omit',
+ // plus 'minimal' as the OFF lane's one intermediate step.
+ private static effortMemory = new Map<string, { on?: 'omit'; off?: 'minimal' | 'omit' }>()
/**
* Endpoints that refused `chat_template_kwargs`. Keyed by base URL, not by
diff --git a/src/lib/__tests__/effort.test.ts b/src/lib/__tests__/effort.test.ts
index 0eb6af44..d4b73689 100644
--- a/src/lib/__tests__/effort.test.ts
+++ b/src/lib/__tests__/effort.test.ts
@@ -27,7 +27,6 @@ import {
effortChoices,
effortLabel,
hasEffortLadder,
- lowerEffort,
nextEffort,
isEffortLevel,
DEFAULT_EFFORT,
@@ -98,7 +97,6 @@ describe("'none' is the off switch and never a rung", () => {
for (const wish of ['none', 'minimal', 'low', 'medium', 'high', 'max', 'ludicrous']) {
expect(clampEffort(GLM53, wish)).not.toBe('none')
expect(nextEffort(GLM53, wish)).not.toBe('none')
- expect(lowerEffort(GLM53, wish)).not.toBe('none')
}
})
@@ -108,20 +106,6 @@ describe("'none' is the off switch and never a rung", () => {
})
})
-describe('walking one rung down for the retry ladder', () => {
- it('finds the next rung below', () => {
- expect(lowerEffort(GLM53, 'max')).toBe('high')
- expect(lowerEffort(GLM53, 'high')).toBe('medium')
- expect(lowerEffort(QWEN38_27B, 'high')).toBe('medium')
- })
-
- it('runs out at the cheapest rung instead of inventing one', () => {
- expect(lowerEffort(GLM53, 'low')).toBeUndefined()
- expect(lowerEffort(undefined, 'high')).toBeUndefined()
- expect(lowerEffort(GLM53, 'ludicrous')).toBeUndefined()
- })
-})
-
describe('the cycling button', () => {
it('walks the rungs the model has and wraps at the top', () => {
expect(nextEffort(GLM53, 'low')).toBe('medium')
diff --git a/src/lib/effort.ts b/src/lib/effort.ts
index b20aa3a5..187ff967 100644
--- a/src/lib/effort.ts
+++ b/src/lib/effort.ts
@@ -81,20 +81,6 @@ export function clampEffort(levels: readonly string[] | undefined, wanted: strin
return below ?? ladder[0]
}
-/**
- * The next rung DOWN, for the retry ladder. A model that refuses 'high' still
- * reasons at 'medium'; dropping the field instead hands the turn to the
- * upstream default, which is the most expensive setting there is.
- */
-export function lowerEffort(
- levels: readonly string[] | undefined,
- current: string,
-): string | undefined {
- const rank = RANK[current]
- if (rank === undefined) return undefined
- return known(levels).filter((l) => RANK[l] < rank).pop()
-}
-
/** The next rung for the cycling button, wrapping at the top of the ladder. */
export function nextEffort(
levels: readonly string[] | undefined,