Skip to content

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

Fall back immediately when managed Orukeet commit capacity is refused (#2343)

Nathan Roll4568472586e7
diff --git a/docs/orukeet-streaming.md b/docs/orukeet-streaming.md
index d38a3b248..66844e490 100644
--- a/docs/orukeet-streaming.md
+++ b/docs/orukeet-streaming.md
@@ -27,9 +27,9 @@ The response contains `baseUrl`, `websocketUrl`, `clientToken`, `protocol`, `exp
The main process creates the adapter before requesting the session so initial PCM is buffered. The existing AudioWorklet emits mono PCM16 at 16 kHz. On release it sends its final PCM and a flush acknowledgement; only then does the desktop commit. Final acknowledgement replaces fixed settling delays. Successful silence is accepted without a second transcription. A flush failure closes the incomplete stream and preserves the existing recording fallback.
-Successful recordings can reuse the established Orukeet socket. Each final resets audio and language state. An unused Orukeet connection closes after 60 seconds; recording startup cancels that timer. Cancellation closes without commit. Pending audio is bounded to 2 MiB; setup and final waits are bounded. Application heartbeats run every 15 seconds. The server allows at most 600 seconds of audio and uses overlapped windows above 60 seconds; an individual socket has a 20-minute lifetime.
+The server can accept another recording on a surviving socket after a final resets its audio and language state. The desktop currently closes the used adapter after each recording and creates a new warm connection; it only reuses a socket that has carried no audio. An unused Orukeet connection closes after 60 seconds; recording startup cancels that timer. Cancellation closes without commit. Pending audio is bounded to 2 MiB; setup and final waits are bounded. Application heartbeats run every 15 seconds. The server allows at most 600 seconds of audio and uses overlapped windows above 60 seconds; an individual socket has a 20-minute lifetime.
-A `capacity` response means the server retained the audio: retry only the commit after `retry_after_ms`, within the original final deadline. Connection loss closes the adapter and uses the existing retained-audio fallback. Duplicate final responses are ignored. The fallback remains the existing authorized OpenWhispr Cloud path; this PR does not replace its model configuration.
+A `capacity` response means the server retained the audio. Managed Cloud closes that attempt immediately and uploads the complete retained capture through the existing authorized batch fallback, including recordings under two seconds; it does not keep the active socket retrying until the final deadline. A self-hosted BYOK connection still retries only the commit after `retry_after_ms`, within the original final deadline. Connection loss closes the adapter and uses the existing retained-audio fallback. Duplicate final responses are ignored. The fallback does not replace the configured batch model or bypass its account checks.
The rollout applies to dictation. Local Orukeet, meetings and existing BYOK providers retain their behavior. For an operator's custom endpoint, selecting `orukeet-v0.1.0` with a custom URL and key opts into the same PCM transport; other custom models retain their existing route.
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index cdd6cf64c..3321cecd1 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -8393,8 +8393,12 @@ class IPCHandlers {
// default lives here, at the boundary, so the token allowlist stays
// fail-closed for genuinely unknown providers (#1624).
const provider = options.provider ?? "openai-realtime";
+ // Managed Cloud retains the capture for batch fallback. A refused
+ // commit must close this attempt instead of retrying for 30 seconds.
const streaming =
- provider === "orukeet" ? new OrukeetStreaming() : new OpenAIRealtimeStreaming();
+ provider === "orukeet"
+ ? new OrukeetStreaming({ retryCapacity: !isCloud })
+ : new OpenAIRealtimeStreaming();
setupDictationCallbacks(streaming, event);
// Assign before the token fetch (a real network round trip) so
// dictation-realtime-send has a live instance to buffer into instead
diff --git a/src/helpers/orukeetStreaming.js b/src/helpers/orukeetStreaming.js
index a5761c5af..259fad87b 100644
--- a/src/helpers/orukeetStreaming.js
+++ b/src/helpers/orukeetStreaming.js
@@ -58,9 +58,11 @@ class OrukeetStreaming {
constructor({
createSocket = (url, options, protocols) => new WebSocket(url, protocols, options),
timeoutMs = 30000,
+ retryCapacity = true,
} = {}) {
this.createSocket = createSocket;
this.timeoutMs = timeoutMs;
+ this.retryCapacity = retryCapacity;
this.ws = null;
this.isConnected = false;
this.pendingAudio = [];
@@ -178,7 +180,7 @@ class OrukeetStreaming {
this.finalResolve?.(this.result);
this.clearFinal();
} else if (message.type === "error") {
- if (message.code === "capacity" && this.finalResolve) {
+ if (message.code === "capacity" && this.finalResolve && this.retryCapacity) {
clearTimeout(this.retryTimer);
this.retryTimer = setTimeout(() => {
if (this.finalResolve) this.sendControl({ type: "commit" });
diff --git a/test/helpers/audioManagerStreamingFinalization.test.js b/test/helpers/audioManagerStreamingFinalization.test.js
index 06152720b..1c42accd0 100644
--- a/test/helpers/audioManagerStreamingFinalization.test.js
+++ b/test/helpers/audioManagerStreamingFinalization.test.js
@@ -1,5 +1,8 @@
const test = require("node:test");
const assert = require("node:assert/strict");
+const { once } = require("node:events");
+const { WebSocketServer } = require("ws");
+const { OrukeetStreaming } = require("../../src/helpers/orukeetStreaming");
const { loadAudioManager } = require("./harness/audioManager");
async function loadManagerClass(t) {
@@ -913,6 +916,82 @@ test("opening words streamed before a mid-recording drop still count as speech",
assert.deepEqual(uploads, [{ audio: "opening words", reason: "stream_no_final" }]);
});
+test("a capacity-refused managed commit closes and uploads the whole short capture once", async (t) => {
+ const AudioManager = await loadManagerClass(t);
+ useManagedOrukeetSettings();
+ installCapture(t);
+ const server = new WebSocketServer({ host: "127.0.0.1", port: 0 });
+ await once(server, "listening");
+ let commits = 0;
+ server.on("connection", (socket) => {
+ socket.send(
+ JSON.stringify({
+ type: "ready",
+ channels: 1,
+ sample_rate: 16000,
+ encoding: "pcm_s16le",
+ max_seconds: 600,
+ })
+ );
+ socket.on("message", (data, binary) => {
+ if (!binary && JSON.parse(data).type === "commit") {
+ commits++;
+ // A busy gateway keeps the PCM and socket until the client retries or closes.
+ socket.send(JSON.stringify({ type: "error", code: "capacity", retry_after_ms: 100 }));
+ }
+ });
+ });
+ const adapter = new OrukeetStreaming({ timeoutMs: 500, retryCapacity: false });
+ t.after(async () => {
+ await adapter.disconnect();
+ for (const socket of server.clients) socket.terminate();
+ await new Promise((resolve) => server.close(resolve));
+ });
+ const provider = startingOrukeetProvider({
+ start: async () => {
+ await adapter.connect({
+ baseUrl: `http://127.0.0.1:${server.address().port}`,
+ apiKey: "test-key",
+ });
+ return { success: true };
+ },
+ send: (pcm) => adapter.sendAudio(pcm),
+ onError: (listener) => {
+ adapter.onError = (error) => listener(error.message);
+ return () => {
+ adapter.onError = null;
+ };
+ },
+ finalize: async () => {
+ try {
+ return { success: true, ...(await adapter.finalize()) };
+ } catch (error) {
+ return { success: false, error: error.message };
+ }
+ },
+ stop: async () => ({ success: true, ...(await adapter.disconnect()) }),
+ });
+ const { manager, errors, uploads } = createStartingManager(AudioManager, {
+ providerName: "orukeet",
+ provider,
+ });
+ const upload = manager.processWithOpenWhisprCloud;
+ manager.processWithOpenWhisprCloud = async (...args) => {
+ assert.equal(adapter.intentionalClose, true);
+ assert.equal(adapter.retryTimer, undefined);
+ assert.match(adapter.failure.message, /capacity/);
+ return upload(...args);
+ };
+
+ await manager.startStreamingRecording();
+ manager.streamingProcessor.port.onmessage({ data: speechPcm() });
+ await Promise.all([manager.stopStreamingRecording(), manager.stopStreamingRecording()]);
+
+ assert.equal(commits, 1);
+ assert.deepEqual(uploads, [{ audio: "opening words", reason: "stream_no_final" }]);
+ assert.deepEqual(errors, []);
+});
+
test("other streaming providers still surface a dropped stream and auto-stop", async (t) => {
const AudioManager = await loadManagerClass(t);
useManagedOrukeetSettings();
diff --git a/test/helpers/orukeetDictationIpc.test.js b/test/helpers/orukeetDictationIpc.test.js
index c798439f1..9997b3c22 100644
--- a/test/helpers/orukeetDictationIpc.test.js
+++ b/test/helpers/orukeetDictationIpc.test.js
@@ -31,6 +31,8 @@ const { OrukeetStreaming } = require("../../src/helpers/orukeetStreaming");
let server,
target,
opened = 0;
+let refuseCommit = false;
+let commitCount = 0;
const messages = [];
const event = { sender: new EventEmitter() };
event.sender.send = (channel, text) => messages.push([channel, text]);
@@ -93,11 +95,15 @@ Module._load = function loadWithMocks(request, parent, isMain) {
if (request === "./orukeetStreaming")
return {
OrukeetStreaming: class extends OrukeetStreaming {
- constructor() {
+ constructor(options) {
super({
+ ...options,
createSocket: (url, options, protocols) => {
assert.equal(url, cloudSession.websocketUrl);
- assert.equal(options.headers.Authorization, undefined);
+ assert.equal(
+ options.headers.Authorization,
+ protocols ? undefined : "Bearer test-key"
+ );
opened++;
return new WebSocket(`ws://127.0.0.1:${server.address().port}`, protocols, options);
},
@@ -163,6 +169,12 @@ test.before(async () => {
socket.on("message", (data, binary) => {
if (binary) bytes += data.length;
else if (JSON.parse(data).type === "commit") {
+ commitCount++;
+ if (refuseCommit) {
+ if (refuseCommit === "once") refuseCommit = false;
+ socket.send(JSON.stringify({ type: "error", code: "capacity", retry_after_ms: 100 }));
+ return;
+ }
socket.send(
JSON.stringify({ type: "language", language: "en", language_confidence: 0.99 })
);
@@ -214,6 +226,63 @@ test("registered managed IPC streams startup audio and returns exactly one compl
assert.equal(tokenListeners.size, 0);
});
+test(
+ "managed IPC closes a capacity-refused commit without retrying",
+ { timeout: 1000 },
+ async (t) => {
+ refuseCommit = true;
+ const before = commitCount;
+ const messagesBefore = messages.length;
+ t.after(async () => {
+ refuseCommit = false;
+ await handlers.get("dictation-realtime-stop")();
+ });
+
+ assert.equal(
+ (await handlers.get("dictation-realtime-start")(event, managedOptions)).success,
+ true
+ );
+ const streaming = target._dictationStreaming;
+ const closed = once(streaming.ws, "close");
+ handlers.get("dictation-realtime-send")(event, Buffer.alloc(640));
+ const final = await handlers.get("dictation-realtime-finalize")();
+
+ assert.deepEqual(final, { success: false, error: "Orukeet transcription failed: capacity" });
+ assert.equal(streaming.intentionalClose, true, "the refused attempt is closed before fallback");
+ assert.equal(streaming.retryTimer, undefined, "no delayed commit can outlive fallback");
+ assert.equal(streaming.finalResolve, null);
+ assert.deepEqual(messages.slice(messagesBefore), [
+ ["dictation-realtime-error", "Orukeet transcription failed: capacity"],
+ ]);
+ await closed;
+ assert.equal(commitCount - before, 1);
+ }
+);
+
+test("self-hosted IPC still retries a capacity-refused commit without re-uploading", async (t) => {
+ refuseCommit = "once";
+ const before = commitCount;
+ target.environmentManager = { getCustomTranscriptionKey: () => "test-key" };
+ t.after(async () => {
+ refuseCommit = false;
+ delete target.environmentManager;
+ await handlers.get("dictation-realtime-stop")();
+ });
+
+ const start = await handlers.get("dictation-realtime-start")(event, {
+ ...managedOptions,
+ mode: "byok",
+ baseUrl: cloudSession.baseUrl,
+ });
+ assert.equal(start.success, true);
+ handlers.get("dictation-realtime-send")(event, Buffer.alloc(640));
+ const final = await handlers.get("dictation-realtime-finalize")();
+
+ assert.equal(final.success, true);
+ assert.equal(final.text, "Recorded 640 bytes");
+ assert.equal(commitCount - before, 2);
+});
+
test("stop during token fetch cancels the real main-process connection", async () => {
let resolve;
backendResponse = () =>