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): disable thinking via reasoning object on self-hosted endpoints (#1103)

Alcahest Malus Dienheim0ac619961c8a
diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.ts
index cc6d6d96a..e0efbd789 100644
--- a/src/services/ReasoningService.ts
+++ b/src/services/ReasoningService.ts
@@ -34,6 +34,22 @@ export type AgentStreamChunk =
}
| { type: "done"; finishReason?: string };
+// Old Ollama/strict proxies reject the `reasoning` object; drop it and retry once.
+async function fetchWithReasoningFieldFallback(
+ doFetch: () => Promise<Response>,
+ requestBody: Record<string, unknown>,
+ logEvent: string
+): Promise<Response> {
+ let res = await doFetch();
+ if (!res.ok && (res.status === 400 || res.status === 422) && requestBody.reasoning) {
+ logger.logReasoning(logEvent, { status: res.status });
+ delete requestBody.reasoning;
+ void res.body?.cancel();
+ res = await doFetch();
+ }
+ return res;
+}
+
class ReasoningService extends BaseReasoningService {
private apiKeyCache: SecureCache<string>;
private static readonly MAX_TOOL_STEPS = 20;
@@ -212,12 +228,17 @@ class ReasoningService extends BaseReasoningService {
headers["Authorization"] = `Bearer ${apiKey}`;
}
- const res = await fetch(endpoint, {
- method: "POST",
- headers,
- body: JSON.stringify(requestBody),
- signal: controller.signal,
- });
+ const res = await fetchWithReasoningFieldFallback(
+ () =>
+ fetch(endpoint, {
+ method: "POST",
+ headers,
+ body: JSON.stringify(requestBody),
+ signal: controller.signal,
+ }),
+ requestBody,
+ `${providerName.toUpperCase()}_REASONING_FIELD_RETRY`
+ );
if (!res.ok) {
const errorText = await res.text();
@@ -451,7 +472,7 @@ class ReasoningService extends BaseReasoningService {
}
}
- applyThinkingSuppression(requestBody, model, provider, config);
+ applyThinkingSuppression(requestBody, model, isLanCleanup ? "lan" : provider, config);
logger.logReasoning("AGENT_STREAM_REQUEST", {
endpoint,
@@ -475,12 +496,17 @@ class ReasoningService extends BaseReasoningService {
let response: Response;
try {
- response = await fetch(endpoint, {
- method: "POST",
- headers,
- body: JSON.stringify(requestBody),
- signal: controller.signal,
- });
+ response = await fetchWithReasoningFieldFallback(
+ () =>
+ fetch(endpoint, {
+ method: "POST",
+ headers,
+ body: JSON.stringify(requestBody),
+ signal: controller.signal,
+ }),
+ requestBody,
+ "AGENT_STREAM_REASONING_FIELD_RETRY"
+ );
} catch (error) {
clearTimeout(timeoutId);
if ((error as Error).name === "AbortError") {
diff --git a/src/services/ai/thinkingSuppression.ts b/src/services/ai/thinkingSuppression.ts
index 7d826b934..a5b1317ce 100644
--- a/src/services/ai/thinkingSuppression.ts
+++ b/src/services/ai/thinkingSuppression.ts
@@ -1,19 +1,8 @@
import type { ReasoningConfig } from "../BaseReasoningService";
import { getCloudModel, getLocalModel } from "../../models/ModelRegistry";
-// Strict OpenAI-compatible servers (Groq, LM Studio, vLLM, LocalAI) reject
-// unknown fields like `think` with "property 'think' is unsupported". Only
-// Ollama-native servers accept `think`; everyone else uses `reasoning_effort`.
-// The `lan` provider defaults to Ollama dialect, but legacy users who
-// configured Self-Hosted as "openai-compatible" still route through `lan`
-// — honor that flag so their backend doesn't reject the request.
-function usesOllamaDialect(providerKey: string): boolean {
- if (providerKey === "local") return true;
- if (providerKey !== "lan") return false;
- if (typeof window === "undefined") return true;
- return window.localStorage?.getItem("remoteReasoningType") !== "openai-compatible";
-}
-
+// `lan` always talks to an OpenAI-compat /v1 endpoint: the `reasoning` object
+// disables Ollama thinking; other backends drop it (flat reasoning_effort trips vLLM).
function suppressThinking(requestBody: Record<string, unknown>, providerKey: string): void {
if (providerKey === "gemini") {
requestBody.reasoning_effort = "minimal";
@@ -27,8 +16,10 @@ function suppressThinking(requestBody: Record<string, unknown>, providerKey: str
return;
}
- if (usesOllamaDialect(providerKey)) {
+ if (providerKey === "local") {
requestBody.think = false;
+ } else if (providerKey === "lan") {
+ requestBody.reasoning = { effort: "none" };
} else {
requestBody.reasoning_effort = "none";
}