Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
Extend the configurable LLM request timeout to streaming, fix a leak
Sebastian Schmidc5a5b8c502e3
diff --git a/src/helpers/llmRequestTimeout.js b/src/helpers/llmRequestTimeout.jsindex f47a5d750..f4f49b330 100644--- a/src/helpers/llmRequestTimeout.js+++ b/src/helpers/llmRequestTimeout.js@@ -2,12 +2,17 @@// agent tool calls, self-hosted LAN calls) shares one configurable abort timeout.// Self-hosted/local models can legitimately take well past the historical 30s// default; the range below just keeps a bad or hand-edited value from firing-// instantly or hanging forever. Streaming requests have their own inactivity-// timeouts and don't use this.+// instantly or hanging forever. Streaming requests read the same configured+// value too, floored at LLM_STREAMING_TIMEOUT_FLOOR_SECONDS below so raising+// this setting can only extend streaming's wall-clock budget, never shorten it.export const LLM_REQUEST_TIMEOUT_SECONDS_MIN = 10;export const LLM_REQUEST_TIMEOUT_SECONDS_MAX = 600;export const LLM_REQUEST_TIMEOUT_SECONDS_DEFAULT = 30;+// Streaming's abort budget has always been 60s; letting the configurable+// setting drop below that would regress existing users, so this is the floor.+export const LLM_STREAMING_TIMEOUT_FLOOR_SECONDS = 60;+export function resolveLlmRequestTimeoutSeconds(configured) {const seconds = Number.isFinite(configured) ? configured : LLM_REQUEST_TIMEOUT_SECONDS_DEFAULT;return Math.min(diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.tsindex 0fea80bb2..5453e5c7e 100644--- a/src/services/ReasoningService.ts+++ b/src/services/ReasoningService.ts@@ -14,7 +14,10 @@ import logger from "../utils/logger";import { getSettings, isCloudCleanupMode } from "../stores/settingsStore";import { wrapCleanupTranscript } from "../config/prompts";import { stripThinkingTags } from "../helpers/stripThinking.js";-import { resolveLlmRequestTimeoutSeconds } from "../helpers/llmRequestTimeout.js";+import {+ resolveLlmRequestTimeoutSeconds,+ LLM_STREAMING_TIMEOUT_FLOOR_SECONDS,+} from "../helpers/llmRequestTimeout.js";import { streamText, stepCountIs } from "ai";import { getAIModel } from "./ai/providers";import { createEnterpriseChatModel } from "./ai/enterpriseChatModel";@@ -313,8 +316,8 @@ class ReasoningService extends BaseReasoningService {const controller = new AbortController();// Self-hosted/local models can legitimately take well past the 30s default// to format a long note; the setting is clamped to a sane range in case of- // a stray or hand-edited value. Streaming requests have their own- // inactivity timeouts and don't go through here.+ // a stray or hand-edited value. Streaming requests don't go through here+ // (see processTextStreaming), but read the same setting with its own floor.const timeoutSeconds = resolveLlmRequestTimeoutSeconds(getSettings().llmRequestTimeoutSeconds);@@ -595,7 +598,14 @@ class ReasoningService extends BaseReasoningService {this.streamAbortController = new AbortController();const controller = this.streamAbortController;- const timeoutId = setTimeout(() => controller.abort(), 60000);+ // The configured setting raises the ceiling for slow self-hosted models;+ // it must never lower streaming below its historical 60s budget, since+ // that would be a regression for existing users.+ const timeoutSeconds = Math.max(+ resolveLlmRequestTimeoutSeconds(getSettings().llmRequestTimeoutSeconds),+ LLM_STREAMING_TIMEOUT_FLOOR_SECONDS+ );+ const timeoutId = setTimeout(() => controller.abort(), timeoutSeconds * 1000);let response: Response;try {@@ -619,6 +629,7 @@ class ReasoningService extends BaseReasoningService {}if (!response.ok) {+ clearTimeout(timeoutId);const errorText = await response.text();let errorMessage: string;try {@@ -632,7 +643,10 @@ class ReasoningService extends BaseReasoningService {}const reader = response.body?.getReader();- if (!reader) throw new Error("No response body");+ if (!reader) {+ clearTimeout(timeoutId);+ throw new Error("No response body");+ }const decoder = new TextDecoder();let buffer = "";diff --git a/test/helpers/llmRequestTimeout.test.js b/test/helpers/llmRequestTimeout.test.jsindex 05d29261f..579bbcde8 100644--- a/test/helpers/llmRequestTimeout.test.js+++ b/test/helpers/llmRequestTimeout.test.js@@ -23,3 +23,26 @@ test("clamps above the 600s ceiling", async () => {const { resolveLlmRequestTimeoutSeconds } = await load();assert.equal(resolveLlmRequestTimeoutSeconds(9999), 600);});++test("exposes the 60s streaming timeout floor", async () => {+ const { LLM_STREAMING_TIMEOUT_FLOOR_SECONDS } = await load();+ assert.equal(LLM_STREAMING_TIMEOUT_FLOOR_SECONDS, 60);+});++test("streaming's floor keeps a low configured value at 60s", async () => {+ const { resolveLlmRequestTimeoutSeconds, LLM_STREAMING_TIMEOUT_FLOOR_SECONDS } = await load();+ const streamingTimeout = Math.max(+ resolveLlmRequestTimeoutSeconds(30),+ LLM_STREAMING_TIMEOUT_FLOOR_SECONDS+ );+ assert.equal(streamingTimeout, 60);+});++test("streaming's floor lets a high configured value raise it above 60s", async () => {+ const { resolveLlmRequestTimeoutSeconds, LLM_STREAMING_TIMEOUT_FLOOR_SECONDS } = await load();+ const streamingTimeout = Math.max(+ resolveLlmRequestTimeoutSeconds(120),+ LLM_STREAMING_TIMEOUT_FLOOR_SECONDS+ );+ assert.equal(streamingTimeout, 120);+});