Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(reasoning): floor GLM-5.3 thinking suppression at low effort (#2019)

Idris Gadi2516e6e000b8
diff --git a/src/services/ai/chatRequestBody.ts b/src/services/ai/chatRequestBody.ts
index 39abe3072..7fd3bc6c2 100644
--- a/src/services/ai/chatRequestBody.ts
+++ b/src/services/ai/chatRequestBody.ts
@@ -2,7 +2,7 @@ import type { ReasoningConfig } from "../BaseReasoningService";
import { getOpenAiApiConfig } from "../../models/ModelRegistry";
import { detectEndpointDialect } from "./thinkingSuppressionDialects";
import { getModelFamilyConstraints } from "./modelFamilyConstraints";
-import { applyThinkingSuppression } from "./thinkingSuppression";
+import { applyThinkingSuppression, isThinkingSuppressed } from "./thinkingSuppression";
/**
* Providers whose OpenAI-compat chat endpoints speak the legacy shape: always
@@ -19,7 +19,8 @@ const LEGACY_CHAT_COMPLETIONS_PROVIDERS = new Set(["local", "lan", "groq", "tinf
* param, temperature, family reasoning effort, and thinking suppression.
* Callers own `model`/`messages`/`stream`; this owns every tunable param, so
* a family or provider fact changed in the data tables reaches all transports
- * at once instead of one call site at a time (#1611).
+ * at once instead of one call site at a time (#1611). Responses bodies get the
+ * same family effort from familyResponsesEffort; keep the two in step.
*/
export function applyChatCompletionsParams(
requestBody: Record<string, unknown>,
@@ -58,11 +59,41 @@ export function applyChatCompletionsParams(
// preferred effort — see modelFamilyConstraints for the gpt-oss rationale.
// applyThinkingSuppression still wins when thinking is disabled by the user.
const familyEffort = getModelFamilyConstraints(model)?.reasoningEffort;
- if (familyEffort?.cleanupValue && (!config.systemPrompt || config.requireCompleteOutput)) {
+ if (familyEffort?.cleanupValue && isDeterministicTransform(config)) {
requestBody.reasoning_effort = familyEffort.cleanupValue;
}
- applyThinkingSuppression(requestBody, model, provider, config, endpoint ?? undefined);
+ const suppressed = applyThinkingSuppression(
+ requestBody,
+ model,
+ provider,
+ config,
+ endpoint ?? undefined
+ );
+ // Some dialects suppress through other fields, so a default effort beside
+ // them would contradict the suppression.
+ if (!suppressed && familyEffort?.defaultValue) {
+ requestBody.reasoning_effort ??= familyEffort.defaultValue;
+ }
+}
+
+/**
+ * The family's effort for a Responses API body (`reasoning: { effort }`), by
+ * the same rules as the chat body above. A model outside the family table
+ * sends no effort, leaving the server's default.
+ */
+export function familyResponsesEffort(model: string, config: ReasoningConfig): string | undefined {
+ const familyEffort = getModelFamilyConstraints(model)?.reasoningEffort;
+ if (!familyEffort) return undefined;
+ if (isThinkingSuppressed(model, config)) return familyEffort.suppressValue;
+ if (familyEffort.cleanupValue && isDeterministicTransform(config)) {
+ return familyEffort.cleanupValue;
+ }
+ return familyEffort.defaultValue;
+}
+
+function isDeterministicTransform(config: ReasoningConfig): boolean {
+ return !config.systemPrompt || !!config.requireCompleteOutput;
}
/** Finish reasons that mean the output hit the token cap, across providers. */
diff --git a/src/services/ai/inferenceProviders/openai.ts b/src/services/ai/inferenceProviders/openai.ts
index a9b8f89f1..f0f79df66 100644
--- a/src/services/ai/inferenceProviders/openai.ts
+++ b/src/services/ai/inferenceProviders/openai.ts
@@ -8,6 +8,7 @@ import { canBorrowCleanupCustomKey, resolveConfiguredOpenAIBase } from "../opena
import {
applyChatCompletionsParams,
emptyResponseError,
+ familyResponsesEffort,
fetchWithParamFallback,
isTruncatedFinishReason,
truncatedOutputError,
@@ -274,6 +275,8 @@ export const openaiProvider: InferenceProvider = {
if (apiConfig.supportsTemperature) {
requestBody.temperature = config.temperature ?? (config.systemPrompt ? 0.3 : 0);
}
+ const effort = familyResponsesEffort(model, config);
+ if (effort) requestBody.reasoning = { effort };
} else {
requestBody.messages = buildMessages(type);
applyChatCompletionsParams(requestBody, {
diff --git a/src/services/ai/modelFamilyConstraints.ts b/src/services/ai/modelFamilyConstraints.ts
index 47102cb1b..924ecafcd 100644
--- a/src/services/ai/modelFamilyConstraints.ts
+++ b/src/services/ai/modelFamilyConstraints.ts
@@ -9,7 +9,7 @@
* like thinkingSuppressionDialects.
*/
export interface ModelFamilyConstraints {
- family: "gpt-oss" | "qwen" | "magistral";
+ family: "gpt-oss" | "qwen" | "magistral" | "glm-5.3";
reasoningEffort?: {
/** Value that best approximates "thinking off" for reasoning_effort. */
suppressValue: string;
@@ -21,6 +21,11 @@ export interface ModelFamilyConstraints {
* return whitespace content, failing selection edits.
*/
cleanupValue?: string;
+ /**
+ * Effort sent while thinking is on, for a family whose server default
+ * reasons past the app's output caps. Without it the server's default applies.
+ */
+ defaultValue?: string;
};
/** Family reasons natively and may reject reasoning params outright. */
omitReasoningParams?: boolean;
@@ -41,6 +46,14 @@ const FAMILIES: Array<ModelFamilyConstraints & { match: RegExp }> = [
// generic dialect sends everywhere, so the fact is provider-agnostic).
reasoningEffort: { suppressValue: "none" },
},
+ {
+ family: "glm-5.3",
+ match: /glm[-_]?5[-.]?3/,
+ // GLM-5.3/Flash always reason: low|high|max only, no off switch.
+ // "low" is the closest to off. At the server default, max, a long meeting
+ // spent the whole 4,096-token notes budget thinking (#2008); at high it fit.
+ reasoningEffort: { suppressValue: "low", defaultValue: "high" },
+ },
{
family: "magistral",
match: /magistral/,
diff --git a/src/services/ai/thinkingSuppression.ts b/src/services/ai/thinkingSuppression.ts
index 21d181ddd..2236df0eb 100644
--- a/src/services/ai/thinkingSuppression.ts
+++ b/src/services/ai/thinkingSuppression.ts
@@ -2,29 +2,31 @@ import type { ReasoningConfig } from "../BaseReasoningService";
import { getCloudModel, getLocalModel } from "../../models/ModelRegistry";
import { detectEndpointDialect, suppressThinking } from "./thinkingSuppressionDialects";
+export function isThinkingSuppressed(model: string, config: ReasoningConfig): boolean {
+ const cloudModel = getCloudModel(model);
+
+ // A registry model flagged disableThinking is force-suppressed on every
+ // provider — scoping this to one provider is the #1611 bug pattern.
+ if (cloudModel?.disableThinking) return true;
+
+ if (config.disableThinking !== true) return false;
+
+ const knownModel = cloudModel || getLocalModel(model);
+ return !knownModel || !!knownModel.supportsThinking;
+}
+
+/** Returns whether it suppressed thinking. */
export function applyThinkingSuppression(
requestBody: Record<string, unknown>,
model: string,
provider: string,
config: ReasoningConfig,
baseUrl?: string
-): void {
+): boolean {
+ if (!isThinkingSuppressed(model, config)) return false;
+
// A known endpoint host wins over the generic provider dialect.
const providerKey = detectEndpointDialect(baseUrl)?.key ?? provider.toLowerCase();
- const cloudModel = getCloudModel(model);
-
- // A registry model flagged disableThinking is force-suppressed on every
- // provider — scoping this to one provider is the #1611 bug pattern.
- if (cloudModel?.disableThinking) {
- suppressThinking(requestBody, providerKey, model);
- return;
- }
-
- if (config.disableThinking !== true) return;
-
- const localModel = getLocalModel(model);
- const knownModel = cloudModel || localModel;
- if (knownModel && !knownModel.supportsThinking) return;
-
suppressThinking(requestBody, providerKey, model);
+ return true;
}
diff --git a/test/helpers/thinkingSuppressionDialects.test.js b/test/helpers/thinkingSuppressionDialects.test.js
index 13f72b640..da8fc5eaf 100644
--- a/test/helpers/thinkingSuppressionDialects.test.js
+++ b/test/helpers/thinkingSuppressionDialects.test.js
@@ -108,6 +108,18 @@ test("lan sends a family's suppress floor inside the reasoning object, not a fla
assert.ok(!("reasoning_effort" in body), "flat reasoning_effort trips vLLM on lan (#1611)");
});
+test("lan glm-5.3 floors at low: the family cannot disable reasoning", async () => {
+ const { suppressThinking } = await load();
+
+ const body = {};
+ suppressThinking(body, "lan", "glm-5.3-flash");
+
+ assert.deepEqual(body, {
+ reasoning: { effort: "low" },
+ chat_template_kwargs: { enable_thinking: false },
+ });
+});
+
test("unlisted providers keep the legacy reasoning_effort none plus chat_template_kwargs", async () => {
const { suppressThinking } = await load();
diff --git a/test/services/llmRequestShapeMatrix.test.js b/test/services/llmRequestShapeMatrix.test.js
index 11ed93fa8..8e7323d38 100644
--- a/test/services/llmRequestShapeMatrix.test.js
+++ b/test/services/llmRequestShapeMatrix.test.js
@@ -36,18 +36,28 @@ const MATRIX = [
{ max_tokens: MAX_TOKENS, temperature: 0.3, reasoning_effort: "low" }],
["tinfoil model outside the registry keeps the legacy shape", "tinfoil", "deepseek-v4-1-flash", null, CLEANUP,
{ max_tokens: MAX_TOKENS, temperature: 0 }],
+ ["tinfoil glm-5.3 notes pin high, below its max default (#2008)", "tinfoil", "glm-5-3", null, AGENT,
+ { max_tokens: MAX_TOKENS, temperature: 0.3, reasoning_effort: "high" }],
+ ["tinfoil glm-5.3 suppression floors at low", "tinfoil", "glm-5-3", null, AGENT_NO_THINK,
+ { max_tokens: MAX_TOKENS, temperature: 0.3, reasoning_effort: "low", chat_template_kwargs: { enable_thinking: false } }],
// --- OpenAI / custom / OpenRouter (registry-driven shape) ---
["openai legacy model keeps max_tokens and temperature", "openai", "gpt-4o", null, CLEANUP,
{ max_tokens: MAX_TOKENS, temperature: 0 }],
["openai gpt-5 family uses max_completion_tokens and omits temperature", "openai", "gpt-5-mini", null, CLEANUP,
{ max_completion_tokens: MAX_TOKENS }],
+ ["custom glm-5.3 (Ollama Cloud) pins high below its max default (#2008)", "custom", "glm-5.3", "https://ollama.com/v1", AGENT,
+ { max_completion_tokens: MAX_TOKENS, reasoning_effort: "high" }],
+ ["custom glm-5.3 suppression floors at low", "custom", "glm-5.3", "https://ollama.com/v1", AGENT_NO_THINK,
+ { max_completion_tokens: MAX_TOKENS, reasoning_effort: "low", chat_template_kwargs: { enable_thinking: false } }],
["openrouter vendor-prefixed id speaks plain chat completions", "openrouter", "openai/gpt-4o", null, AGENT,
{ max_tokens: MAX_TOKENS, temperature: 0.3 }],
["openrouter forwards sampling upstream: temperature-rejecting Claude omits it (#1417)", "openrouter", "anthropic/claude-sonnet-5", null, AGENT,
{ max_tokens: MAX_TOKENS }],
["openrouter suppression uses its native reasoning toggle", "openrouter", "openai/gpt-4o", null, AGENT_NO_THINK,
{ max_tokens: MAX_TOKENS, temperature: 0.3, reasoning: { enabled: false } }],
+ ["openrouter glm-5.3 suppression sends its toggle alone, never the high default beside it", "openrouter", "z-ai/glm-5.3", null, AGENT_NO_THINK,
+ { max_tokens: MAX_TOKENS, temperature: 0.3, reasoning: { enabled: false } }],
// --- Endpoint dialects (host beats provider and model id) ---
["mistral host: max_tokens, temperature, no reasoning params on magistral", "custom", "magistral-small-latest", "https://api.mistral.ai/v1", CLEANUP_NO_THINK,
@@ -68,6 +78,10 @@ const MATRIX = [
{ max_tokens: MAX_TOKENS, temperature: 0, reasoning_effort: "low", reasoning: { effort: "low" }, chat_template_kwargs: { enable_thinking: false } }],
["lan gpt-oss suppression sends the family floor, never the off value the family lacks", "lan", "gpt-oss-20b-mxfp4", null, AGENT_NO_THINK,
{ max_tokens: MAX_TOKENS, temperature: 0.3, reasoning: { effort: "low" }, chat_template_kwargs: { enable_thinking: false } }],
+ ["lan glm-5.3 pins high: its max default thinks past the output cap (#2008)", "lan", "glm-5.3-flash", null, CLEANUP,
+ { max_tokens: MAX_TOKENS, temperature: 0, reasoning_effort: "high" }],
+ ["lan glm-5.3 suppression floors at low, never the unsupported none", "lan", "glm-5.3-flash", null, CLEANUP_NO_THINK,
+ { max_tokens: MAX_TOKENS, temperature: 0, reasoning: { effort: "low" }, chat_template_kwargs: { enable_thinking: false } }],
["local llama.cpp gets think false plus chat_template_kwargs (#783)", "local", "qwen3.5-4b-gguf", null, CLEANUP_NO_THINK,
{ max_tokens: MAX_TOKENS, temperature: 0, think: false, chat_template_kwargs: { enable_thinking: false } }],
diff --git a/test/services/modelFamilyConstraints.test.js b/test/services/modelFamilyConstraints.test.js
index dca9b380a..d05d0163d 100644
--- a/test/services/modelFamilyConstraints.test.js
+++ b/test/services/modelFamilyConstraints.test.js
@@ -23,3 +23,15 @@ test("gpt-oss has no reasoning off switch: suppress and cleanup both floor at lo
const effort = getModelFamilyConstraints("gpt-oss-120b")?.reasoningEffort;
assert.deepEqual(effort, { suppressValue: "low", cleanupValue: "low" });
});
+
+test("glm-5.3 always reasons: suppress floors at low, high stands in for the server's max", async () => {
+ const { getModelFamilyConstraints } = await load();
+ assert.deepEqual(getModelFamilyConstraints("glm-5.3")?.reasoningEffort, {
+ suppressValue: "low",
+ defaultValue: "high",
+ });
+ assert.equal(getModelFamilyConstraints("glm-5.3-flash")?.family, "glm-5.3");
+ assert.equal(getModelFamilyConstraints("glm-5-3")?.family, "glm-5.3");
+ assert.equal(getModelFamilyConstraints("GLM-5.3-Flash:cloud")?.family, "glm-5.3");
+ assert.equal(getModelFamilyConstraints("glm-5-2")?.family, undefined);
+});
diff --git a/test/services/openaiReasoningOutput.test.js b/test/services/openaiReasoningOutput.test.js
index babceea47..526a0730b 100644
--- a/test/services/openaiReasoningOutput.test.js
+++ b/test/services/openaiReasoningOutput.test.js
@@ -133,6 +133,79 @@ test("a custom endpoint keeps the caller's output budget even for a reasoning-sh
assert.equal(bodies[0].max_output_tokens, 4096);
});
+// GLM-5.3 reasons at max unless asked otherwise, and on a long meeting that
+// thinking spent the whole 4,096-token notes budget before any notes (#2008).
+const glmNotesCall = (config = {}) => ({
+ text: TRANSCRIPT,
+ model: "glm-5.3",
+ agentName: null,
+ config: {
+ provider: "custom",
+ baseUrl: "https://glm-host.example/v1",
+ customApiKey: "test-key",
+ systemPrompt: "Summarize",
+ maxTokens: 4096,
+ ...config,
+ },
+ ctx: makeCtx(),
+});
+
+test("a GLM-5.3 notes request on a Responses endpoint pins high effort", async (t) => {
+ const bodies = installFetch(t, () => completeMessage("# Notes"));
+ const { openaiProvider } = await load();
+
+ await openaiProvider.call(glmNotesCall());
+
+ assert.deepEqual(bodies[0].reasoning, { effort: "high" });
+});
+
+test("with thinking disabled, GLM-5.3 on a Responses endpoint gets its low floor", async (t) => {
+ const bodies = installFetch(t, () => completeMessage("# Notes"));
+ const { openaiProvider } = await load();
+
+ await openaiProvider.call(glmNotesCall({ disableThinking: true }));
+
+ assert.deepEqual(bodies[0].reasoning, { effort: "low" });
+});
+
+test("Responses requests carry the other families' effort facts too", async (t) => {
+ const bodies = installFetch(t, () => completeMessage("Cleaned."));
+ const { openaiProvider } = await load();
+ const customConfig = {
+ provider: "custom",
+ baseUrl: "https://custom-host.example/v1",
+ customApiKey: "test-key",
+ };
+
+ // gpt-oss cleanup pins low, as on chat; qwen's off value is none.
+ await openaiProvider.call({
+ text: "raw transcript",
+ model: "gpt-oss:20b",
+ agentName: null,
+ config: customConfig,
+ ctx: makeCtx(),
+ });
+ await openaiProvider.call({
+ text: "raw transcript",
+ model: "qwen3:32b",
+ agentName: null,
+ config: { ...customConfig, disableThinking: true },
+ ctx: makeCtx(),
+ });
+
+ assert.deepEqual(bodies[0].reasoning, { effort: "low" });
+ assert.deepEqual(bodies[1].reasoning, { effort: "none" });
+});
+
+test("a model outside the family table gets no reasoning param on a Responses endpoint", async (t) => {
+ const bodies = installFetch(t, () => completeMessage("# Notes"));
+ const { openaiProvider } = await load();
+
+ await openaiProvider.call({ ...glmNotesCall({ disableThinking: true }), model: "glm-5.2" });
+
+ assert.equal(bodies[0].reasoning, undefined);
+});
+
test("a Responses result that ran out of tokens before any text is an error, not the input echoed back", async (t) => {
installFetch(t, () =>
jsonResponse({