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
fix(ai): retain deadlines through OpenAI response bodies (#2840)
Chad Piha7f6621b1cf8a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bab8b064e..5c6bd6b08 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### AI models++- **Cleanup and notes through OpenAI, OpenRouter or your own endpoint no longer wait forever on a stalled reply.** The request deadline stopped as soon as the server sent its response headers, so a reply that stalled before its body finished left dictation cleanup or the AI Summary waiting with no end, and a stalled model list from a custom endpoint kept the request from ever starting. The 30-second cleanup and 10-minute note deadlines now cover the whole reply, and the model list check gives up after 2 seconds. OpenRouter sends its headers before the model starts writing, so its cleanup used to have no time limit at all; a cleanup that takes longer than 30 seconds there, usually with thinking turned on, now pastes your raw transcript and tells you OpenRouter took too long, as it already did through OpenAI directly. (#2799)+## [1.10.3] - 2026-10-12The assistant can now act in other apps: it drafts and sends email, posts to Slack, and works with Linear and GitHub issues, always behind a card you approve. Notes get templates for the AI Summary, actions that answer in a docked chat, and real tables. OpenWhispr also uses far less memory when idle, shows a plain-language error when your API key or provider fails, and fixes a long list of bugs on Linux, Windows and macOS.diff --git a/src/services/ai/inferenceProviders/openai.ts b/src/services/ai/inferenceProviders/openai.tsindex e961f7d64..91e361b66 100644--- a/src/services/ai/inferenceProviders/openai.ts+++ b/src/services/ai/inferenceProviders/openai.ts@@ -109,15 +109,13 @@ async function detectServerType(base: string): Promise<void> {return;}+ const controller = new AbortController();+ const timeoutId = setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS);try {- const controller = new AbortController();- const timeoutId = setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS);const res = await fetch(buildApiUrl(base, "/models"), {method: "GET",signal: controller.signal,});- clearTimeout(timeoutId);-if (!res.ok) {probedBases.add(base);return;@@ -138,6 +136,8 @@ async function detectServerType(base: string): Promise<void> {probedBases.add(base);} catch {probedBases.add(base);+ } finally {+ clearTimeout(timeoutId);}}@@ -245,6 +245,7 @@ export const openaiProvider: InferenceProvider = {const controller = new AbortController();const timeoutSeconds = getLlmRequestTimeoutSeconds({ scope: config.inferenceScope });const timeoutId = setTimeout(() => controller.abort(), timeoutSeconds * 1000);+ let readingBody = false;try {const requestedMaxTokens =config.maxTokens ||@@ -339,11 +340,13 @@ export const openaiProvider: InferenceProvider = {}rememberPreference(openAiBase, type);- return res.json();+ readingBody = true;+ return await res.json();} catch (error) {if ((error as Error).name === "AbortError") {throw llmRequestTimeoutError(timeoutSeconds);}+ if (readingBody) throw error;lastError = error as Error;if (retryStrategy.shouldRetry(lastError)) {lastRetryableError = lastError;diff --git a/test/services/openaiProviderBodyDeadline.test.js b/test/services/openaiProviderBodyDeadline.test.jsnew file mode 100644index 000000000..b361fb65f--- /dev/null+++ b/test/services/openaiProviderBodyDeadline.test.js@@ -0,0 +1,205 @@+const test = require("node:test");+const assert = require("node:assert/strict");++const ctx = {+ getApiKey: async () => "test-key",+ getSystemPrompt: () => "Clean the transcript",+ getCustomDictionary: () => [],+ getPreferredLanguage: () => "en",+ getUiLanguage: () => "en",+ calculateMaxTokens: () => 4096,+};+const settle = () => new Promise((resolve) => setImmediate(resolve));+const json = (body, status = 200) => new Response(JSON.stringify(body), { status });+const reply = {+ output: [{ type: "message", content: [{ type: "output_text", text: "Cleaned" }] }],+};+const chatReply = { choices: [{ message: { role: "assistant", content: "Cleaned" } }] };++function pendingBody(signal) {+ let stream;+ const response = new Response(+ new ReadableStream({+ start(controller) {+ stream = controller;+ },+ })+ );+ signal.addEventListener("abort", () => stream.error(new DOMException("Aborted", "AbortError")), {+ once: true,+ });+ return response;+}++async function setup(t, name, fetchResponse, config = {}) {+ const { openaiProvider } = await import("../../src/services/ai/inferenceProviders/openai.ts");+ const originalFetch = globalThis.fetch;+ t.after(() => {+ globalThis.fetch = originalFetch;+ });+ const requested = [];+ globalThis.fetch = async (url, init = {}) => {+ requested.push(String(url));+ return fetchResponse(String(url), init);+ };+ const call = () =>+ openaiProvider.call({+ text: "raw transcript",+ model: "cleanup-model",+ agentName: null,+ config: {+ provider: "custom",+ customApiKey: "test-key",+ baseUrl: `https://${name}.example/v1`,+ ...config,+ },+ ctx,+ });+ return { request: call(), call, requested };+}++for (const { label, name, config, deadline, urls } of [+ {+ label: "a custom endpoint's 30s cleanup",+ name: "body-cleanup",+ config: {},+ deadline: 30_000,+ urls: ["https://body-cleanup.example/v1/models", "https://body-cleanup.example/v1/responses"],+ },+ {+ label: "a custom endpoint's 600s note",+ name: "body-note",+ config: { inferenceScope: "noteFormatting" },+ deadline: 600_000,+ urls: ["https://body-note.example/v1/models", "https://body-note.example/v1/responses"],+ },+ // OpenRouter sends its 200 headers as soon as a provider accepts the request,+ // before the model generates, so the body read is the whole generation.+ {+ label: "OpenRouter's 30s cleanup",+ name: "body-openrouter",+ config: { provider: "openrouter" },+ deadline: 30_000,+ urls: ["https://openrouter.ai/api/v1/chat/completions"],+ },+]) {+ test(`successful response body retains ${label} deadline`, async (t) => {+ t.mock.timers.enable({ apis: ["setTimeout"] });+ let signal;+ const { request, requested } = await setup(+ t,+ name,+ (url, init) => {+ if (url.endsWith("/models")) return json({}, 404);+ signal = init.signal;+ return pendingBody(signal);+ },+ config+ );+ let error;+ const outcome = request.catch((cause) => {+ error = cause;+ });+ await settle();+ assert.deepEqual(requested, urls);+ t.mock.timers.tick(deadline - 1);+ await settle();+ assert.equal(signal.aborted, false);+ t.mock.timers.tick(1);+ await settle();+ assert.equal(signal.aborted, true, "body consumption must remain covered by the deadline");+ await outcome;+ assert.equal(error?.code, "PROVIDER_TIMEOUT");+ assert.match(+ error?.cause?.message ?? "",+ new RegExp(`Request timed out after ${deadline / 1000}s`)+ );+ assert.deepEqual(requested, urls, "an expired body must not trigger fallback or retry");+ });+}++test("model discovery body times out and permits the inference request", async (t) => {+ t.mock.timers.enable({ apis: ["setTimeout"] });+ let signal;+ const { request, requested } = await setup(t, "probe-body", (url, init) => {+ if (url.endsWith("/models")) {+ signal = init.signal;+ return pendingBody(signal);+ }+ return json(reply);+ });+ await settle();+ assert.equal(requested.length, 1);+ t.mock.timers.tick(2_000);+ await settle();+ assert.equal(signal.aborted, true, "discovery deadline must cover its body");+ assert.equal(await request, "Cleaned");+ assert.equal(requested.length, 2);+});++// A llama.cpp server whose model list outlives the probe deadline is not+// detected, so its first request falls back from /responses once and the+// chat preference it learns keeps later requests off both extra round trips.+test("an undetected llama.cpp server learns chat from its first request", async (t) => {+ t.mock.timers.enable({ apis: ["setTimeout"] });+ const base = "https://slow-llamacpp.example/v1";+ const { request, call, requested } = await setup(t, "slow-llamacpp", (url, init) => {+ if (url.endsWith("/models")) return pendingBody(init.signal);+ if (url.endsWith("/responses")) return json({ error: { message: "not found" } }, 404);+ return json(chatReply);+ });+ await settle();+ t.mock.timers.tick(2_000);+ assert.equal(await request, "Cleaned");+ assert.deepEqual(requested, [`${base}/models`, `${base}/responses`, `${base}/chat/completions`]);++ requested.length = 0;+ assert.equal(await call(), "Cleaned");+ assert.deepEqual(requested, [`${base}/chat/completions`]);+});++// The tests below pass without the fix too: they pin what it must not change.++test("a complete response body resolves and disposes the deadline", async (t) => {+ t.mock.timers.enable({ apis: ["setTimeout"] });+ let signal;+ const { request } = await setup(t, "complete-body", (url, init) => {+ if (url.endsWith("/models")) return json({}, 404);+ signal = init.signal;+ return json(reply);+ });+ assert.equal(await request, "Cleaned");+ t.mock.timers.tick(30_000);+ assert.equal(signal.aborted, false);+});++for (const kind of ["malformed", "dropped"]) {+ test(`${kind} successful body is retried on /responses without falling back to chat`, async (t) => {+ const { RETRY_CONFIG } = await import("../../src/config/constants.ts");+ t.mock.timers.enable({ apis: ["setTimeout"] });+ const base = `https://${kind}-body.example/v1`;+ const { request, requested } = await setup(t, `${kind}-body`, (url) => {+ if (url.endsWith("/models")) return json({}, 404);+ if (kind === "malformed") return new Response("{");+ return new Response(+ new ReadableStream({+ start(controller) {+ controller.error(new Error("body dropped"));+ },+ })+ );+ });+ const rejected = assert.rejects(request);+ let delay = RETRY_CONFIG.INITIAL_DELAY;+ for (let retry = 0; retry < RETRY_CONFIG.MAX_RETRIES; retry++) {+ await settle();+ t.mock.timers.tick(delay);+ delay = Math.min(delay * RETRY_CONFIG.BACKOFF_MULTIPLIER, RETRY_CONFIG.MAX_DELAY);+ }+ await rejected;+ assert.deepEqual(requested, [+ `${base}/models`,+ ...Array(RETRY_CONFIG.MAX_RETRIES + 1).fill(`${base}/responses`),+ ]);+ });+}