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(upload): survive poisoned TLS connections; cap upload diarization speaker clusters (#1496)
Joshua6d2d30340a06
diff --git a/src/components/notes/UploadAudioView.tsx b/src/components/notes/UploadAudioView.tsxindex 733aba9c7..4ed04dc43 100644--- a/src/components/notes/UploadAudioView.tsx+++ b/src/components/notes/UploadAudioView.tsx@@ -29,6 +29,7 @@ import {findDefaultFolder,findVideosFolder,DOWNLOAD_ERROR_KEYS,+ transcriptionErrorKey,MEETINGS_FOLDER_NAME,} from "./shared";import { useAuth } from "../../hooks/useAuth";@@ -135,7 +136,9 @@ export default function UploadAudioView({ onNoteCreated, onOpenSettings }: UploadurationSeconds?: number | null;} | null>(null);const [result, setResult] = useState<string | null>(null);- const [partialWarning, setPartialWarning] = useState(false);+ const [partialWarning, setPartialWarning] = useState<{ failed: number; total: number } | null>(+ null+ );const [noteId, setNoteId] = useState<number | null>(null);const [error, setError] = useState<string | null>(null);const [isDragOver, setIsDragOver] = useState(false);@@ -584,7 +587,7 @@ export default function UploadAudioView({ onNoteCreated, onOpenSettings }: UploasetState("idle");setFile(null);setResult(null);- setPartialWarning(false);+ setPartialWarning(null);setNoteId(null);setError(null);setProgress(0);@@ -671,7 +674,11 @@ export default function UploadAudioView({ onNoteCreated, onOpenSettings }: Uploaif (res.success && res.text) {setProgress(100);setResult(res.text);- setPartialWarning(!!res.warning);+ setPartialWarning(+ res.failedChunks && res.totalChunks+ ? { failed: res.failedChunks, total: res.totalChunks }+ : null+ );let title: string;if (currentFile.fromUrl) {@@ -705,9 +712,10 @@ export default function UploadAudioView({ onNoteCreated, onOpenSettings }: UploasetState("complete");} else {setProgress(0);+ const errorKey = transcriptionErrorKey(res);setError(- res.code === "NO_SPEECH_DETECTED"- ? t("notes.upload.noSpeechDetected")+ errorKey+ ? t(`notes.upload.${errorKey}`): res.error || t("notes.upload.transcriptionFailed"));setState("error");@@ -718,7 +726,12 @@ export default function UploadAudioView({ onNoteCreated, onOpenSettings }: Uploaif (progressCleanupRef.current) progressCleanupRef.current();progressCleanupRef.current = null;setProgress(0);- setError(err instanceof Error ? err.message : t("notes.upload.errorOccurred"));+ const errorKey = transcriptionErrorKey(err);+ if (errorKey) {+ setError(t(`notes.upload.${errorKey}`));+ } else {+ setError(err instanceof Error ? err.message : t("notes.upload.errorOccurred"));+ }setState("error");}};@@ -1289,7 +1302,14 @@ export default function UploadAudioView({ onNoteCreated, onOpenSettings }: Uploa{diarizationEnabled && diarizationModelsReady && (<div className="mt-2">+ <label+ htmlFor="upload-num-speakers"+ className="block text-xs font-medium text-foreground/50"+ >+ {t("notes.upload.numSpeakersLabel")}+ </label><input+ id="upload-num-speakers"type="number"min="2"max={MAX_SPEAKER_COUNT}@@ -1304,12 +1324,14 @@ export default function UploadAudioView({ onNoteCreated, onOpenSettings }: UploasetDiarizationNumSpeakers(String(isNaN(n) ? "" : n));}}placeholder={t("notes.upload.numSpeakersPlaceholder")}- aria-label={t("notes.upload.numSpeakersPlaceholder")}className={cn(uploadFieldClass,- "w-full h-8 px-2.5 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"+ "mt-1 w-full h-8 px-2.5 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none")}/>+ <p className="text-[10px] text-foreground/25 mt-1.5">+ {t("notes.upload.numSpeakersHint")}+ </p></div>)}</div>@@ -1807,9 +1829,9 @@ function FolderSelect({}interface CompleteViewProps {- t: (key: string) => string;+ t: (key: string, options?: Record<string, unknown>) => string;result: string;- partialWarning: boolean;+ partialWarning: { failed: number; total: number } | null;folders: FolderItem[];selectedFolderId: string;handleFolderChange: (val: string) => void;@@ -1878,7 +1900,10 @@ function CompleteView({{partialWarning && (<p className="text-xs text-destructive/50 max-w-[240px] text-center mb-4 -mt-2">- {t("notes.upload.partialWarning")}+ {t("notes.upload.partialWarningCount", {+ failed: partialWarning.failed,+ total: partialWarning.total,+ })}</p>)}diff --git a/src/components/notes/overview/OverviewNoteList.tsx b/src/components/notes/overview/OverviewNoteList.tsxindex cba8d4155..4cc8f313b 100644--- a/src/components/notes/overview/OverviewNoteList.tsx+++ b/src/components/notes/overview/OverviewNoteList.tsx@@ -77,7 +77,10 @@ export function OverviewNoteList({onClick={() => onOpenNote(note.id)}className="w-full flex items-center gap-3 px-2 py-2 -mx-2 rounded-md text-left hover:bg-foreground/4 dark:hover:bg-white/4 transition-colors duration-150 focus:outline-none focus-visible:ring-1 focus-visible:ring-ring/30">- <FileText size={14} className="text-foreground/30 dark:text-foreground/20 shrink-0" />+ <FileText+ size={14}+ className="text-foreground/30 dark:text-foreground/20 shrink-0"+ /><span className="text-[13px] text-foreground/85 truncate flex-1">{note.title || t("notes.list.untitled")}</span>diff --git a/src/components/notes/shared.ts b/src/components/notes/shared.tsindex de0760dd6..edfb0cb67 100644--- a/src/components/notes/shared.ts+++ b/src/components/notes/shared.ts@@ -27,6 +27,21 @@ export const DOWNLOAD_ERROR_KEYS: Record<string, string> = {SSRF_BLOCKED: "urlDownloadFailed",};+// Transcription error codes → notes.upload.* i18n keys. Codes absent here fall+// back to the raw main-process message.+const TRANSCRIPTION_ERROR_KEYS: Record<string, string> = {+ NO_SPEECH_DETECTED: "noSpeechDetected",+ CHUNK_LOSS_EXCEEDED: "chunkLossExceeded",+};++// A coded failure arrives either as a returned result (BYOK, local) or as a+// thrown error — OpenWhispr Cloud rethrows it through withSessionRefresh — so+// every call site resolves the key from whichever shape it is holding.+export function transcriptionErrorKey(failure: unknown): string | undefined {+ const code = (failure as { code?: string } | null | undefined)?.code;+ return code ? TRANSCRIPTION_ERROR_KEYS[code] : undefined;+}+export const notesInputClass = cn("w-full h-8 px-3 rounded-md text-xs","bg-foreground/3 dark:bg-white/4 border border-border/30 dark:border-white/6",diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex 543ff2496..47adc3e32 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -2715,6 +2715,11 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);if (!res.success) {const err = new Error(res.error || "Cloud transcription failed");err.code = res.code;+ // The recording is kept by saveFailedTranscription, so point the user+ // at History rather than leaving them with a raw main-process string.+ if (res.code === "CHUNK_LOSS_EXCEEDED") {+ err.messageKey = "hooks.audioRecording.errorDescriptions.chunkLoss";+ }throw err;}return res;diff --git a/src/helpers/cloudChunkPolicy.js b/src/helpers/cloudChunkPolicy.jsindex 47156736f..34e8e177f 100644--- a/src/helpers/cloudChunkPolicy.js+++ b/src/helpers/cloudChunkPolicy.js@@ -1,4 +1,6 @@const { createAbortError } = require("./abortError");+const { formatTimestamp } = require("./speakerMerge");+const { i18nMain } = require("./i18nMain");// Retry/backoff/concurrency policy for the chunked cloud upload path (#1326).// Kept free of electron imports so the rules stay unit-testable.@@ -29,6 +31,21 @@ const CLOUD_CHUNK_BACKOFF_JITTER_MS = 1_000;// sacrifice its peers — and its peers' retries in turn.const CLOUD_POOL_TEARDOWN_COOLDOWN_MS = 30_000;+// A teardown aborts every sibling still on the wire; those failures are+// self-inflicted, so the sibling's attempt is refunded rather than charged.+// Bounded per chunk so repeated teardowns can't retry forever.+const CLOUD_CHUNK_MAX_TEARDOWN_REFUNDS = 3;++// Above this failed/total ratio the "transcript" is more hole than content;+// returning success would silently persist a fragment (15/19 chunks lost once+// shipped a 16-minute transcript of a 73-minute file as a normal note).+const CLOUD_CHUNK_MAX_LOSS_RATIO = 0.5;++// A 422 NO_SPEECH response is a valid empty segment, not an upload failure.+// Keep it distinct from null (failed) and response objects (transcribed) so+// silence neither consumes the loss budget nor creates a missing-audio marker.+const SILENT_CHUNK = Symbol("silent-cloud-chunk");+// Codes that doom the whole job, not just one chunk: retrying the siblings can// only burn time and quota.const FATAL_CHUNK_CODES = new Set(["AUTH_EXPIRED", "LIMIT_REACHED"]);@@ -48,16 +65,84 @@ function isNetworkLevelFailure(err, { timedOut = false } = {}) {return timedOut || (!err.statusCode && !err.code);}+// Fatal TLS alerts and HTTP/2/QUIC protocol errors poison every stream on the+// connection, so these force the teardown through the cooldown — which exists+// to absorb bursts of ordinary failures, not to keep a provably sick pool+// alive. Chromium's fetch rejections carry the net::ERR_* name only in the+// message, never a structured code.+const POISONED_CONNECTION_RE = /net::ERR_(SSL|HTTP2|QUIC)_/;++function isConnectionPoisoningFailure(err) {+ return POISONED_CONNECTION_RE.test(err?.message ?? "");+}++// True when the failure was (very likely) our own pool teardown aborting this+// chunk's in-flight body: a teardown happened during the attempt and the+// request died at the transport level. An HTTP answer or business code proves+// the request outlived the teardown, and a timeout is the chunk's own failure.+function isTeardownCollateral(err, { timedOut = false, teardownsDuringAttempt = 0 } = {}) {+ return teardownsDuringAttempt > 0 && !timedOut && isNetworkLevelFailure(err, { timedOut });+}+function createTeardownGate(cooldownMs = CLOUD_POOL_TEARDOWN_COOLDOWN_MS, now = Date.now) {let lastAt = -Infinity;- return () => {+ return (force = false) => {const at = now();- if (at - lastAt < cooldownMs) return false;+ if (!force && at - lastAt < cooldownMs) return false;lastAt = at;return true;};}+function summarizeChunkResults(results) {+ const responses = [];+ let failedChunks = 0;+ let silentChunks = 0;++ for (const result of results) {+ if (result == null) {+ failedChunks++;+ } else if (result === SILENT_CHUNK) {+ silentChunks++;+ } else {+ responses.push(result);+ }+ }++ return { responses, failedChunks, silentChunks };+}++// Joins surviving chunk texts in order and marks every failed span with an+// explicit gap (consecutive failures collapse into one marker), so a partial+// transcript reads as partial instead of seamlessly wrong. Silent segments are+// omitted, and a known input duration clamps the final gap to its real end. The+// marker is read by users and pasted by dictation, so it is localized like the+// [Speaker N] labels in transcriptFormatter.+function assembleChunkTranscript(results, segmentDurationSeconds, totalDurationSeconds) {+ const pieces = [];+ for (let i = 0; i < results.length; i++) {+ if (results[i] === SILENT_CHUNK) continue;+ if (results[i] != null) {+ pieces.push(results[i].text);+ continue;+ }+ const gapStart = i;+ while (i + 1 < results.length && results[i + 1] == null) i++;+ const gapEnd = (i + 1) * segmentDurationSeconds;+ pieces.push(+ i18nMain.t("transcript.missingAudio", {+ from: formatTimestamp(gapStart * segmentDurationSeconds),+ to: formatTimestamp(+ Number.isFinite(totalDurationSeconds) && totalDurationSeconds > 0+ ? Math.min(gapEnd, totalDurationSeconds)+ : gapEnd+ ),+ })+ );+ }+ return pieces.join(" ").replace(/\s+/g, " ").trim();+}+function chunkRetryDelayMs(attempt, random = Math.random) {const base = Math.min(CLOUD_CHUNK_BACKOFF_BASE_MS * CLOUD_CHUNK_BACKOFF_FACTOR ** (attempt - 1),@@ -146,9 +231,16 @@ module.exports = {CLOUD_CHUNK_MAX_ATTEMPTS,CLOUD_CHUNK_GLOBAL_CONCURRENCY,CLOUD_POOL_TEARDOWN_COOLDOWN_MS,+ CLOUD_CHUNK_MAX_TEARDOWN_REFUNDS,+ CLOUD_CHUNK_MAX_LOSS_RATIO,+ SILENT_CHUNK,FATAL_CHUNK_CODES,isTransientChunkError,isNetworkLevelFailure,+ isConnectionPoisoningFailure,+ isTeardownCollateral,+ summarizeChunkResults,+ assembleChunkTranscript,chunkRetryDelayMs,abortableSleep,createTeardownGate,diff --git a/src/helpers/diarizationPolicy.js b/src/helpers/diarizationPolicy.jsnew file mode 100644index 000000000..39c47c2c1--- /dev/null+++ b/src/helpers/diarizationPolicy.js@@ -0,0 +1,63 @@+// Clustering policy for the upload/batch diarization path. Kept free of+// electron imports so the rules stay unit-testable (pattern: cloudChunkPolicy).++// sherpa-onnx's cluster threshold is a cosine distance: higher merges more.+// 0.55 suits short clean audio, but over a long single-mic recording one+// speaker's embeddings drift wider than that and agglomerative clustering+// stops merging early — a 73-minute voice memo produced 46 "speakers". Ramp+// the threshold with duration instead of pretending one constant fits both.+const DEFAULT_CLUSTER_THRESHOLD = 0.55;+const LONG_AUDIO_CLUSTER_THRESHOLD = 0.8;+const THRESHOLD_RAMP_START_SECONDS = 15 * 60;+const THRESHOLD_RAMP_END_SECONDS = 60 * 60;++// A cluster with under a second of total speech is embedding noise, not a+// person — and the character-proportional merge hands every surviving cluster+// at least one sentence, so each blip becomes a phantom [Speaker N].+const MIN_CLUSTER_TOTAL_SECONDS = 1;++function clusterThresholdForDuration(durationSeconds) {+ if (!Number.isFinite(durationSeconds) || durationSeconds <= THRESHOLD_RAMP_START_SECONDS) {+ return DEFAULT_CLUSTER_THRESHOLD;+ }+ if (durationSeconds >= THRESHOLD_RAMP_END_SECONDS) return LONG_AUDIO_CLUSTER_THRESHOLD;+ const progress =+ (durationSeconds - THRESHOLD_RAMP_START_SECONDS) /+ (THRESHOLD_RAMP_END_SECONDS - THRESHOLD_RAMP_START_SECONDS);+ return (+ DEFAULT_CLUSTER_THRESHOLD ++ (LONG_AUDIO_CLUSTER_THRESHOLD - DEFAULT_CLUSTER_THRESHOLD) * progress+ );+}++function resolveClusterThreshold(durationSeconds, requestedThreshold) {+ const automaticThreshold = clusterThresholdForDuration(durationSeconds);+ if (requestedThreshold == null || requestedThreshold === "") return automaticThreshold;+ const parsedThreshold = Number(requestedThreshold);+ if (!Number.isFinite(parsedThreshold)) return automaticThreshold;+ return Math.min(1, Math.max(0, parsedThreshold));+}++function dropNegligibleClusters(segments, minTotalSeconds = MIN_CLUSTER_TOTAL_SECONDS) {+ if (!segments?.length) return segments;+ const totals = new Map();+ for (const s of segments) {+ totals.set(s.speaker, (totals.get(s.speaker) || 0) + (s.end - s.start));+ }+ const keep = new Set(+ [...totals].filter(([, total]) => total >= minTotalSeconds).map(([speaker]) => speaker)+ );+ if (keep.size === 0 || keep.size === totals.size) return segments;+ return segments.filter((s) => keep.has(s.speaker));+}++module.exports = {+ DEFAULT_CLUSTER_THRESHOLD,+ LONG_AUDIO_CLUSTER_THRESHOLD,+ THRESHOLD_RAMP_START_SECONDS,+ THRESHOLD_RAMP_END_SECONDS,+ MIN_CLUSTER_TOTAL_SECONDS,+ clusterThresholdForDuration,+ resolveClusterThreshold,+ dropNegligibleClusters,+};diff --git a/src/helpers/ffmpegUtils.js b/src/helpers/ffmpegUtils.jsindex d051013be..643069b10 100644--- a/src/helpers/ffmpegUtils.js+++ b/src/helpers/ffmpegUtils.js@@ -266,6 +266,12 @@ function computeFloat32RMS(float32Buffer) {return Math.sqrt(sumSquares / numSamples);}+function parseFfmpegDuration(stderr) {+ const match = stderr?.match(/Duration:\s*(\d+):([0-5]\d):([0-5]\d(?:\.\d+)?)/);+ if (!match) return null;+ return Number(match[1]) * 3600 + Number(match[2]) * 60 + Number(match[3]);+}+function splitAudioFile(inputPath, outputDir, options = {}) {const { segmentDuration = 600, audioBitrate = "128k", signal } = options;@@ -363,8 +369,9 @@ function splitAudioFile(inputPath, outputDir, options = {}) {return;}- debugLogger.debug("FFmpeg split complete", { chunkCount: chunks.length });- resolve(chunks);+ const durationSeconds = parseFfmpegDuration(stderr);+ debugLogger.debug("FFmpeg split complete", { chunkCount: chunks.length, durationSeconds });+ resolve({ chunkPaths: chunks, durationSeconds });});});}@@ -452,6 +459,7 @@ module.exports = {parseWavFormat,convertToWav,splitAudioFile,+ parseFfmpegDuration,wavToFloat32Samples,computeFloat32RMS,mergeAudioSegments,diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex 4ba741bd1..d1305d53d 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -133,36 +133,56 @@ const {CLOUD_UPLOAD_TIMEOUT_MS,CLOUD_CHUNK_MAX_ATTEMPTS,CLOUD_CHUNK_GLOBAL_CONCURRENCY,+ CLOUD_CHUNK_MAX_TEARDOWN_REFUNDS,+ CLOUD_CHUNK_MAX_LOSS_RATIO,+ SILENT_CHUNK,FATAL_CHUNK_CODES,isTransientChunkError,isNetworkLevelFailure,+ isConnectionPoisoningFailure,+ isTeardownCollateral,+ summarizeChunkResults,+ assembleChunkTranscript,chunkRetryDelayMs,abortableSleep,createTeardownGate,createUploadSlots,} = require("./cloudChunkPolicy");-// Every cloud upload rides a dedicated in-memory session so stalled large-// bodies can't wedge the HTTP/2 connection the rest of the app multiplexes-// over, and a failed attempt can drop the pool without collateral damage-// outside the upload path (#1326).-const CLOUD_UPLOAD_SESSION_PARTITION = "ow-cloud-uploads";+// Chunk retries need their own connection pool: recovering a wedged chunk pool+// must not abort an unrelated inline upload that has no collateral retry path.+const CLOUD_CHUNK_UPLOAD_SESSION_PARTITION = "ow-cloud-chunk-uploads";+const CLOUD_INLINE_UPLOAD_SESSION_PARTITION = "ow-cloud-uploads";const cloudUploadSlots = createUploadSlots(CLOUD_CHUNK_GLOBAL_CONCURRENCY);const shouldDropUploadPool = createTeardownGate();-let cloudUploadSession = null;+const cloudUploadSessions = new Map();-function getCloudUploadSession() {- if (!cloudUploadSession) {- cloudUploadSession = session.fromPartition(CLOUD_UPLOAD_SESSION_PARTITION);- applyOpenWhisprOriginHeader(cloudUploadSession);+function getCloudUploadSession(partition) {+ if (!cloudUploadSessions.has(partition)) {+ const uploadSession = session.fromPartition(partition);+ applyOpenWhisprOriginHeader(uploadSession);+ cloudUploadSessions.set(partition, uploadSession);}- return cloudUploadSession;+ return cloudUploadSessions.get(partition);}-async function dropUploadConnections() {- if (!shouldDropUploadPool()) return;+function getChunkCloudUploadSession() {+ return getCloudUploadSession(CLOUD_CHUNK_UPLOAD_SESSION_PARTITION);+}++function getInlineCloudUploadSession() {+ return getCloudUploadSession(CLOUD_INLINE_UPLOAD_SESSION_PARTITION);+}++// Counts initiated pool drops so a chunk can tell whether its failure was+// collateral from a teardown that happened while its body was on the wire.+let uploadPoolTeardowns = 0;++async function dropUploadConnections(force = false) {+ if (!shouldDropUploadPool(force)) return;+ uploadPoolTeardowns++;try {- await getCloudUploadSession().closeAllConnections();+ await getChunkCloudUploadSession().closeAllConnections();} catch {// pool teardown is best-effort}@@ -333,7 +353,7 @@ async function chunkedCloudTranscribe({try {onProgress?.({ stage: "splitting", chunksTotal: 0, chunksCompleted: 0 });- const chunkPaths = await splitAudioFile(inputPath, chunkDir, {+ const { chunkPaths, durationSeconds } = await splitAudioFile(inputPath, chunkDir, {segmentDuration,signal: jobSignal,});@@ -343,51 +363,83 @@ async function chunkedCloudTranscribe({const url = new URL(`${apiUrl}/api/transcribe`);const results = new Array(totalChunks).fill(null);- const failureCodes = new Set();let fatalError = null;let completedCount = 0;const transcribeChunk = async (index) => {- for (let attempt = 1; ; attempt++) {+ let attempt = 1;+ let teardownRefunds = CLOUD_CHUNK_MAX_TEARDOWN_REFUNDS;+ while (true) {if (jobSignal.aborted) throw createAbortError();// Held only while a body is on the wire, so the backoff below never// occupies a slot and queue time never eats the upload timeout.const releaseSlot = await cloudUploadSlots.acquire(jobSignal);const timeoutSignal = AbortSignal.timeout(CLOUD_UPLOAD_TIMEOUT_MS);+ const teardownsAtStart = uploadPoolTeardowns;let failure = null;+ let timedOut = false;+ let collateral = false;try {- const { body, boundary } = buildMultipartBody(- fs.readFileSync(chunkPaths[index]),- path.basename(chunkPaths[index]),- "audio/mpeg",- multipartFields- );- const data = await postMultipart(url, body, boundary, policyHeaders, {- signal: AbortSignal.any([jobSignal, timeoutSignal]),- session: getCloudUploadSession(),- });- results[index] = interpretTranscribeResponse(data);- } catch (err) {- failure = err;+ try {+ const { body, boundary } = buildMultipartBody(+ fs.readFileSync(chunkPaths[index]),+ path.basename(chunkPaths[index]),+ "audio/mpeg",+ multipartFields+ );+ const data = await postMultipart(url, body, boundary, policyHeaders, {+ signal: AbortSignal.any([jobSignal, timeoutSignal]),+ session: getChunkCloudUploadSession(),+ });+ results[index] = interpretTranscribeResponse(data);+ } catch (err) {+ failure = err;+ timedOut = timeoutSignal.aborted;+ collateral = isTeardownCollateral(err, {+ timedOut,+ teardownsDuringAttempt: uploadPoolTeardowns - teardownsAtStart,+ });+ // Drop the pool while still holding the slot — released first, a+ // queued sibling is admitted onto the pool microseconds before+ // closeAllConnections() kills it and burns an attempt it never+ // owned. A fatal TLS/protocol alert proves the pool is poisoned,+ // so that drop is forced through the cooldown gate.+ if (!jobSignal.aborted && !collateral) {+ const poisoned = isConnectionPoisoningFailure(err);+ if (poisoned || isNetworkLevelFailure(err, { timedOut })) {+ await dropUploadConnections(poisoned);+ }+ }+ }} finally {releaseSlot();}if (!failure) break;+ if (failure.code === "NO_SPEECH_DETECTED") {+ results[index] = SILENT_CHUNK;+ break;+ }+if (jobSignal.aborted) throw createAbortError();- const timedOut = timeoutSignal.aborted;+ if (collateral && teardownRefunds > 0) {+ teardownRefunds--;+ debugLogger.warn(`Chunk ${index} attempt ${attempt} killed by pool teardown, refunded`, {+ error: failure.message,+ });+ await abortableSleep(chunkRetryDelayMs(1), jobSignal);+ continue;+ }if (attempt >= CLOUD_CHUNK_MAX_ATTEMPTS || !(timedOut || isTransientChunkError(failure))) {throw failure;}- // No HTTP answer ever arrived — treat the pool as wedged and drop it so- // the retry dials a fresh connection instead of re-entering the dying one.- if (isNetworkLevelFailure(failure, { timedOut })) await dropUploadConnections();debugLogger.warn(`Chunk ${index} attempt ${attempt} failed, retrying`, {error: failure.message,timedOut,});await abortableSleep(chunkRetryDelayMs(attempt), jobSignal);+ attempt++;}completedCount++;@@ -409,7 +461,6 @@ async function chunkedCloudTranscribe({abortJob();return;}- if (err.code) failureCodes.add(err.code);debugLogger.warn(`Chunk ${index} failed`, { error: err.message, code: err.code });}))@@ -420,9 +471,9 @@ async function chunkedCloudTranscribe({}if (fatalError) throw fatalError;- const succeeded = results.filter((r) => r !== null);- if (succeeded.length === 0) {- if (failureCodes.size === 1 && failureCodes.has("NO_SPEECH_DETECTED")) {+ const { responses, failedChunks: failed, silentChunks } = summarizeChunkResults(results);+ if (responses.length === 0) {+ if (silentChunks === totalChunks) {throw Object.assign(new Error("No speech detected in audio"), {code: "NO_SPEECH_DETECTED",});@@ -430,19 +481,24 @@ async function chunkedCloudTranscribe({throw new Error("All chunks failed to transcribe");}- const text = results- .filter((r) => r !== null)- .map((r) => r.text)- .join(" ")- .replace(/\s+/g, " ")- .trim();+ if (failed / totalChunks > CLOUD_CHUNK_MAX_LOSS_RATIO) {+ throw Object.assign(new Error(`${failed} of ${totalChunks} audio segments were lost`), {+ code: "CHUNK_LOSS_EXCEEDED",+ });+ }- const failed = totalChunks - succeeded.length;+ const text = assembleChunkTranscript(results, segmentDuration, durationSeconds);return {text,- responses: succeeded,- lastResponse: succeeded[succeeded.length - 1],- ...(failed > 0 ? { warning: `${failed} of ${totalChunks} chunks failed` } : {}),+ responses,+ lastResponse: responses[responses.length - 1],+ ...(failed > 0+ ? {+ warning: `${failed} of ${totalChunks} chunks failed`,+ failedChunks: failed,+ totalChunks,+ }+ : {}),};} finally {signal?.removeEventListener("abort", abortJob);@@ -2933,21 +2989,33 @@ class IPCHandlers {if (!realPath) return { success: false, error: "File path not allowed" };filePath = realPath;- const diarOpts = {- numSpeakers: Math.min(- MAX_SPEAKER_COUNT,- Math.max(-1, Math.round(Number(options.numSpeakers) || -1))- ),- threshold: Math.min(1, Math.max(0, Number(options.threshold) || 0.55)),- };+ const numSpeakers = Math.min(+ MAX_SPEAKER_COUNT,+ Math.max(-1, Math.round(Number(options.numSpeakers) || -1))+ );const { convertToWav } = require("./ffmpegUtils");const { getSafeTempDir } = require("./safeTempDir");+ const { resolveClusterThreshold, dropNegligibleClusters } = require("./diarizationPolicy");+ const { PCM16_MONO_16K_BYTES_PER_SECOND } = require("./transcriptionTimeout");const wavPath = path.join(getSafeTempDir(), `ow-diarize-${Date.now()}.wav`);try {await convertToWav(filePath, wavPath, { sampleRate: 16000, channels: 1 });- const segments = await this.diarizationManager.diarize(wavPath, diarOpts);+ // Auto-clustering over-splits long single-mic audio at the 0.55+ // default, so the threshold ramps with duration unless pinned.+ const durationSeconds = fs.statSync(wavPath).size / PCM16_MONO_16K_BYTES_PER_SECOND;+ const threshold = resolveClusterThreshold(durationSeconds, options.threshold);++ let segments = await this.diarizationManager.diarize(wavPath, { numSpeakers, threshold });+ // The meeting path caps clusters via its expectation resolver; this+ // path fed raw sherpa output to the merge, which is how a 2-person+ // voice memo surfaced 46 speakers.+ segments = dropNegligibleClusters(segments);+ segments = this.diarizationManager.capSpeakerClusters(+ segments,+ numSpeakers > 0 ? numSpeakers : MAX_SPEAKER_COUNT+ );return { success: true, segments };} finally {try {@@ -4830,7 +4898,7 @@ class IPCHandlers {const url = new URL(`${apiUrl}/api/transcribe`);const data = await postMultipart(url, body, boundary, withPolicyHeaders(authHeader), {signal: AbortSignal.timeout(CLOUD_UPLOAD_TIMEOUT_MS),- session: getCloudUploadSession(),+ session: getInlineCloudUploadSession(),});debugLogger.debug(@@ -4983,7 +5051,7 @@ class IPCHandlers {withPolicyHeaders(authHeader),{signal: AbortSignal.timeout(CLOUD_UPLOAD_TIMEOUT_MS),- session: getCloudUploadSession(),+ session: getInlineCloudUploadSession(),});const responseData = interpretTranscribeResponse(data);@@ -7935,7 +8003,7 @@ class IPCHandlers {fileSize,filePath: path.basename(realCloud),});- const { text, warning } = await chunkedCloudTranscribe({+ const { text, warning, failedChunks, totalChunks } = await chunkedCloudTranscribe({filePath: realCloud,apiUrl,policyHeaders: withPolicyHeaders(authHeader),@@ -7943,7 +8011,11 @@ class IPCHandlers {onProgress: (payload) => event.sender.send("upload-transcription-progress", payload),signal: controller.signal,});- return { success: true, text, ...(warning ? { warning } : {}) };+ return {+ success: true,+ text,+ ...(warning ? { warning, failedChunks, totalChunks } : {}),+ };}const audioBuffer = fs.readFileSync(realCloud);@@ -7963,7 +8035,7 @@ class IPCHandlers {controller.signal,AbortSignal.timeout(CLOUD_UPLOAD_TIMEOUT_MS),]),- session: getCloudUploadSession(),+ session: getInlineCloudUploadSession(),});const result = interpretTranscribeResponse(data);diff --git a/src/hooks/useNoteDragAndDrop.ts b/src/hooks/useNoteDragAndDrop.tsindex 3830c14c3..80b04a259 100644--- a/src/hooks/useNoteDragAndDrop.ts+++ b/src/hooks/useNoteDragAndDrop.ts@@ -231,7 +231,14 @@ export function useNoteDragAndDrop({},};},- [onCrossSpaceDrop, canCrossSpaceDrop, onCrossSpaceVeto, onHoverTarget, commitDrop, clearHoverTimeout]+ [+ onCrossSpaceDrop,+ canCrossSpaceDrop,+ onCrossSpaceVeto,+ onHoverTarget,+ commitDrop,+ clearHoverTimeout,+ ]);return { dragState, noteDragHandlers, dropTargetHandlers };diff --git a/src/locales/de/translation.json b/src/locales/de/translation.jsonindex 261497325..6e4f5fb06 100644--- a/src/locales/de/translation.json+++ b/src/locales/de/translation.json@@ -601,6 +601,7 @@"offline": "Du bist offline. Die Cloud-Transkription benötigt eine Internetverbindung.","dailyLimitReached": "Du hast dein heutiges Transkriptionslimit erreicht. Versuch es morgen erneut oder upgrade deinen Plan.","providerRateLimited": "Dein Transkriptionsanbieter hat die Anfrage begrenzt. Warte kurz und versuch es erneut.",+ "chunkLoss": "Ein Netzwerkproblem hat zu viel von der Aufnahme verloren. Transkribieren Sie sie über den Verlauf erneut.","agentReasoningFailed": "Ihr Sprachagent konnte den Befehl nicht verarbeiten – stattdessen wurde das unbearbeitete Transkript eingefügt.","screenContextSkipped": "Der Screenshot konnte nicht gesendet werden, daher lief Ihr Befehl ohne Bildschirmkontext."},@@ -2716,6 +2717,8 @@"cancelTranscription": "Transkription abbrechen","transcriptionComplete": "Transkription abgeschlossen","partialWarning": "Ein Teil der Audiodatei konnte nicht transkribiert werden.",+ "partialWarningCount": "{{failed}} von {{total}} Audioabschnitten konnten nicht transkribiert werden.",+ "chunkLossExceeded": "Wegen eines Netzwerkproblems ging zu viel Audio verloren. Prüfen Sie Ihre Verbindung und versuchen Sie es erneut.","openNote": "Notiz öffnen","uploadAnother": "Weitere hochladen","retry": "Erneut versuchen",@@ -2762,6 +2765,8 @@"speakerDetection": "Sprechererkennung","speakerDetectionDescription": "Verschiedene Sprecher im Audio identifizieren","numSpeakersPlaceholder": "Automatisch erkennen",+ "numSpeakersLabel": "Anzahl der Sprecher",+ "numSpeakersHint": "Die genaue Anzahl verbessert die Genauigkeit, besonders bei langen Aufnahmen.","downloadingModels": "Modelle werden heruntergeladen...","openaiDiarizeNote": "Überschreibt Ihr Transkriptionsmodell mit gpt-4o-transcribe-diarize, dem einzigen OpenAI-Modell mit Sprechererkennung. Die Kosten können von Ihrem gewählten Modell abweichen.","mistralDiarizeNote": "Sprechererkennung ohne Zusatzkosten mit Voxtral enthalten.",@@ -3412,7 +3417,8 @@"speaker": {"you": "Du","others": "Andere"- }+ },+ "missingAudio": "[fehlendes Audio {{from}}-{{to}}]"},"dictationTranslation": {"title": "Diktat-Übersetzung",diff --git a/src/locales/en/translation.json b/src/locales/en/translation.jsonindex 989c39c9e..c6198b4d8 100644--- a/src/locales/en/translation.json+++ b/src/locales/en/translation.json@@ -601,6 +601,7 @@"offline": "You're offline. Cloud transcription requires an internet connection.","dailyLimitReached": "You've reached today's transcription limit. Try again tomorrow or upgrade your plan.","providerRateLimited": "Your transcription provider rate-limited the request. Wait a moment and try again.",+ "chunkLoss": "A network problem lost too much of the recording. Re-transcribe it from History.","agentReasoningFailed": "Your voice agent couldn't process the command — the raw transcript was inserted instead.","screenContextSkipped": "The screenshot couldn't be sent, so your command ran without screen context."},@@ -2716,6 +2717,8 @@"cancelTranscription": "Cancel transcription","transcriptionComplete": "Transcription complete","partialWarning": "Part of the audio couldn't be transcribed.",+ "partialWarningCount": "{{failed}} of {{total}} audio sections couldn't be transcribed.",+ "chunkLossExceeded": "Too much of the audio was lost to a network problem. Check your connection and try again.","openNote": "Open Note","uploadAnother": "Upload Another","retry": "Retry",@@ -2762,6 +2765,8 @@"speakerDetection": "Speaker detection","speakerDetectionDescription": "Identify different speakers in the audio","numSpeakersPlaceholder": "Auto-detect",+ "numSpeakersLabel": "Number of speakers",+ "numSpeakersHint": "Setting the exact count improves accuracy, especially on long recordings.","downloadingModels": "Downloading models...","openaiDiarizeNote": "Overrides your transcription model with gpt-4o-transcribe-diarize, the only OpenAI model with speaker detection. Costs may differ from your selected model.","mistralDiarizeNote": "Speaker detection included at no extra cost with Voxtral.",@@ -3412,7 +3417,8 @@"speaker": {"you": "You","others": "Others"- }+ },+ "missingAudio": "[missing audio {{from}}-{{to}}]"},"dictationTranslation": {"title": "Dictation Translation",diff --git a/src/locales/es/translation.json b/src/locales/es/translation.jsonindex 26861bb4b..5db2d9320 100644--- a/src/locales/es/translation.json+++ b/src/locales/es/translation.json@@ -601,6 +601,7 @@"offline": "Estás sin conexión. La transcripción en la nube requiere conexión a Internet.","dailyLimitReached": "Has alcanzado el límite de transcripción de hoy. Inténtalo mañana o mejora tu plan.","providerRateLimited": "Tu proveedor de transcripción limitó la solicitud. Espera un momento e inténtalo de nuevo.",+ "chunkLoss": "Un problema de red hizo que se perdiera demasiada parte de la grabación. Vuelve a transcribirla desde el historial.","agentReasoningFailed": "Tu agente de voz no pudo procesar el comando; se insertó la transcripción sin procesar.","screenContextSkipped": "No se pudo enviar la captura, así que tu comando se ejecutó sin contexto de pantalla."},@@ -2573,6 +2574,8 @@"cancelTranscription": "Cancelar transcripción","transcriptionComplete": "Transcripción completada","partialWarning": "No se pudo transcribir una parte del audio.",+ "partialWarningCount": "No se pudieron transcribir {{failed}} de {{total}} secciones del audio.",+ "chunkLossExceeded": "Se perdió demasiado audio por un problema de red. Comprueba tu conexión e inténtalo de nuevo.","openNote": "Abrir nota","uploadAnother": "Subir otro","retry": "Reintentar",@@ -2619,6 +2622,8 @@"speakerDetection": "Detección de hablantes","speakerDetectionDescription": "Identificar diferentes hablantes en el audio","numSpeakersPlaceholder": "Detección automática",+ "numSpeakersLabel": "Número de hablantes",+ "numSpeakersHint": "Indicar el número exacto mejora la precisión, sobre todo en grabaciones largas.","downloadingModels": "Descargando modelos...","openaiDiarizeNote": "Reemplaza tu modelo de transcripción con gpt-4o-transcribe-diarize, el único modelo de OpenAI con detección de hablantes. Los costos pueden diferir de tu modelo seleccionado.","mistralDiarizeNote": "Detección de hablantes incluida sin costo adicional con Voxtral.",@@ -3352,7 +3357,8 @@"speaker": {"you": "Tú","others": "Otros"- }+ },+ "missingAudio": "[audio faltante {{from}}-{{to}}]"},"workspaces": {"switcher": {diff --git a/src/locales/fr/translation.json b/src/locales/fr/translation.jsonindex 498fc53ae..87287370e 100644--- a/src/locales/fr/translation.json+++ b/src/locales/fr/translation.json@@ -601,6 +601,7 @@"offline": "Vous êtes hors ligne. La transcription cloud nécessite une connexion Internet.","dailyLimitReached": "Vous avez atteint votre limite de transcription du jour. Réessayez demain ou améliorez votre forfait.","providerRateLimited": "Votre fournisseur de transcription a limité la requête. Patientez un instant et réessayez.",+ "chunkLoss": "Un problème réseau a fait perdre une trop grande partie de l'enregistrement. Retranscrivez-le depuis l'historique.","agentReasoningFailed": "Votre agent vocal n'a pas pu traiter la commande ; la transcription brute a été insérée à la place.","screenContextSkipped": "La capture n'a pas pu être envoyée ; votre commande a été exécutée sans contexte d'écran."},@@ -2716,6 +2717,8 @@"cancelTranscription": "Annuler la transcription","transcriptionComplete": "Transcription terminée","partialWarning": "Une partie de l'audio n'a pas pu être transcrite.",+ "partialWarningCount": "{{failed}} sections audio sur {{total}} n'ont pas pu être transcrites.",+ "chunkLossExceeded": "Une trop grande partie de l'audio a été perdue à cause d'un problème réseau. Vérifiez votre connexion et réessayez.","openNote": "Ouvrir la note","uploadAnother": "Téléverser un autre fichier","retry": "Réessayer",@@ -2762,6 +2765,8 @@"speakerDetection": "Détection des intervenants","speakerDetectionDescription": "Identifier les différents intervenants dans l'audio","numSpeakersPlaceholder": "Détection automatique",+ "numSpeakersLabel": "Nombre d'intervenants",+ "numSpeakersHint": "Indiquer le nombre exact améliore la précision, surtout pour les enregistrements longs.","downloadingModels": "Téléchargement des modèles...","openaiDiarizeNote": "Remplace votre modèle de transcription par gpt-4o-transcribe-diarize, le seul modèle OpenAI avec détection des locuteurs. Les coûts peuvent différer de votre modèle sélectionné.","mistralDiarizeNote": "Détection des locuteurs incluse sans frais supplémentaires avec Voxtral.",@@ -3412,7 +3417,8 @@"speaker": {"you": "Vous","others": "Autres"- }+ },+ "missingAudio": "[audio manquant {{from}}-{{to}}]"},"dictationTranslation": {"title": "Traduction de Dictée",diff --git a/src/locales/it/translation.json b/src/locales/it/translation.jsonindex e35283feb..3b1086773 100644--- a/src/locales/it/translation.json+++ b/src/locales/it/translation.json@@ -601,6 +601,7 @@"offline": "Sei offline. La trascrizione cloud richiede una connessione Internet.","dailyLimitReached": "Hai raggiunto il limite di trascrizioni di oggi. Riprova domani o aggiorna il tuo piano.","providerRateLimited": "Il tuo provider di trascrizione ha limitato la richiesta. Attendi un momento e riprova.",+ "chunkLoss": "Un problema di rete ha fatto perdere troppa parte della registrazione. Ritrascrivila dalla cronologia.","agentReasoningFailed": "L'agente vocale non è riuscito a elaborare il comando; è stata inserita la trascrizione grezza.","screenContextSkipped": "Non è stato possibile inviare lo screenshot, quindi il comando è stato eseguito senza contesto dello schermo."},@@ -2525,6 +2526,8 @@"cancelTranscription": "Annulla trascrizione","transcriptionComplete": "Trascrizione completata","partialWarning": "Non è stato possibile trascrivere una parte dell'audio.",+ "partialWarningCount": "Non è stato possibile trascrivere {{failed}} sezioni audio su {{total}}.",+ "chunkLossExceeded": "Troppo audio è andato perso a causa di un problema di rete. Controlla la connessione e riprova.","openNote": "Apri nota","uploadAnother": "Carica un altro","retry": "Riprova",@@ -2571,6 +2574,8 @@"speakerDetection": "Rilevamento parlanti","speakerDetectionDescription": "Identifica i diversi parlanti nell'audio","numSpeakersPlaceholder": "Rilevamento automatico",+ "numSpeakersLabel": "Numero di parlanti",+ "numSpeakersHint": "Indicare il numero esatto migliora la precisione, soprattutto nelle registrazioni lunghe.","downloadingModels": "Download modelli in corso...","openaiDiarizeNote": "Sostituisce il tuo modello di trascrizione con gpt-4o-transcribe-diarize, l’unico modello OpenAI con rilevamento dei parlanti. I costi potrebbero differire dal modello selezionato.","mistralDiarizeNote": "Rilevamento dei parlanti incluso senza costi aggiuntivi con Voxtral.",@@ -3352,7 +3357,8 @@"speaker": {"you": "Tu","others": "Altri"- }+ },+ "missingAudio": "[audio mancante {{from}}-{{to}}]"},"workspaces": {"switcher": {diff --git a/src/locales/ja/translation.json b/src/locales/ja/translation.jsonindex be2d39ced..7afc611ea 100644--- a/src/locales/ja/translation.json+++ b/src/locales/ja/translation.json@@ -601,6 +601,7 @@"offline": "オフラインです。クラウド文字起こしにはインターネット接続が必要です。","dailyLimitReached": "本日の文字起こし上限に達しました。明日もう一度お試しいただくか、プランをアップグレードしてください。","providerRateLimited": "文字起こしプロバイダーがリクエストを制限しました。しばらく待ってからもう一度お試しください。",+ "chunkLoss": "ネットワークの問題で録音の大部分が失われました。履歴から再文字起こししてください。","agentReasoningFailed": "ボイスエージェントがコマンドを処理できなかったため、未処理の文字起こしを挿入しました。","screenContextSkipped": "スクリーンショットを送信できなかったため、画面コンテキストなしでコマンドを実行しました。"},@@ -2509,6 +2510,8 @@"cancelTranscription": "文字起こしをキャンセル","transcriptionComplete": "文字起こし完了","partialWarning": "音声の一部を文字起こしできませんでした。",+ "partialWarningCount": "{{total}}個の音声セクションのうち{{failed}}個を文字起こしできませんでした。",+ "chunkLossExceeded": "ネットワークの問題で音声の大部分が失われました。接続を確認してもう一度お試しください。","openNote": "ノートを開く","uploadAnother": "別のファイルをアップロード","retry": "再試行",@@ -2555,6 +2558,8 @@"speakerDetection": "話者検出","speakerDetectionDescription": "音声内の異なる話者を識別","numSpeakersPlaceholder": "自動検出",+ "numSpeakersLabel": "話者の人数",+ "numSpeakersHint": "正確な人数を設定すると、特に長い録音で精度が向上します。","downloadingModels": "モデルをダウンロード中...","openaiDiarizeNote": "話者検出をサポートする唯一のOpenAIモデルであるgpt-4o-transcribe-diarizeに切り替わります。選択したモデルとコストが異なる場合があります。","mistralDiarizeNote": "Voxtralでの話者検出は追加料金なしで利用できます。",@@ -3352,7 +3357,8 @@"speaker": {"you": "あなた","others": "他の人"- }+ },+ "missingAudio": "[音声欠落 {{from}}-{{to}}]"},"workspaces": {"switcher": {diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.jsonindex 345e65fe4..993a28801 100644--- a/src/locales/pt/translation.json+++ b/src/locales/pt/translation.json@@ -580,6 +580,7 @@"offline": "Você está offline. A transcrição na nuvem exige conexão com a internet.","dailyLimitReached": "Você atingiu o limite de transcrições de hoje. Tente novamente amanhã ou faça upgrade do seu plano.","providerRateLimited": "Seu provedor de transcrição limitou a solicitação. Aguarde um momento e tente novamente.",+ "chunkLoss": "Um problema de rede fez perder grande parte da gravação. Retranscreva-a a partir do histórico.","agentReasoningFailed": "Seu agente de voz não conseguiu processar o comando; a transcrição bruta foi inserida no lugar.","screenContextSkipped": "Não foi possível enviar a captura, então seu comando foi executado sem contexto de tela."},@@ -2525,6 +2526,8 @@"cancelTranscription": "Cancelar transcrição","transcriptionComplete": "Transcrição concluída","partialWarning": "Não foi possível transcrever parte do áudio.",+ "partialWarningCount": "Não foi possível transcrever {{failed}} de {{total}} seções do áudio.",+ "chunkLossExceeded": "Muito áudio foi perdido devido a um problema de rede. Verifique sua conexão e tente novamente.","openNote": "Abrir nota","uploadAnother": "Enviar outro","retry": "Tentar novamente",@@ -2571,6 +2574,8 @@"speakerDetection": "Detecção de locutores","speakerDetectionDescription": "Identificar diferentes locutores no áudio","numSpeakersPlaceholder": "Detecção automática",+ "numSpeakersLabel": "Número de falantes",+ "numSpeakersHint": "Definir o número exato melhora a precisão, principalmente em gravações longas.","downloadingModels": "Baixando modelos...","openaiDiarizeNote": "Substitui seu modelo de transcrição por gpt-4o-transcribe-diarize, o único modelo OpenAI com detecção de falantes. Os custos podem diferir do modelo selecionado.","mistralDiarizeNote": "Detecção de falantes incluída sem custo adicional com Voxtral.",@@ -3352,7 +3357,8 @@"speaker": {"you": "Você","others": "Outros"- }+ },+ "missingAudio": "[áudio ausente {{from}}-{{to}}]"},"workspaces": {"switcher": {diff --git a/src/locales/ru/translation.json b/src/locales/ru/translation.jsonindex db0d8579a..a301b2a95 100644--- a/src/locales/ru/translation.json+++ b/src/locales/ru/translation.json@@ -601,6 +601,7 @@"offline": "Вы офлайн. Облачная транскрипция требует подключения к интернету.","dailyLimitReached": "Достигнут дневной лимит транскрипций. Попробуйте завтра или обновите тариф.","providerRateLimited": "Ваш провайдер транскрипции ограничил запрос. Подождите немного и попробуйте снова.",+ "chunkLoss": "Из-за проблемы с сетью потеряна значительная часть записи. Повторите расшифровку из истории.","agentReasoningFailed": "Голосовой агент не смог обработать команду — вместо этого вставлена необработанная расшифровка.","screenContextSkipped": "Снимок экрана не удалось отправить, поэтому команда выполнена без контекста экрана."},@@ -2547,6 +2548,8 @@"cancelTranscription": "Отменить транскрибирование","transcriptionComplete": "Транскрибирование завершено","partialWarning": "Не удалось транскрибировать часть аудио.",+ "partialWarningCount": "Не удалось транскрибировать {{failed}} из {{total}} фрагментов аудио.",+ "chunkLossExceeded": "Из-за проблемы с сетью потеряно слишком много аудио. Проверьте подключение и попробуйте снова.","openNote": "Открыть заметку","uploadAnother": "Загрузить ещё","retry": "Повторить",@@ -2593,6 +2596,8 @@"speakerDetection": "Определение говорящих","speakerDetectionDescription": "Определить разных говорящих в аудио","numSpeakersPlaceholder": "Автоопределение",+ "numSpeakersLabel": "Количество говорящих",+ "numSpeakersHint": "Точное число повышает точность, особенно для длинных записей.","downloadingModels": "Загрузка моделей...","openaiDiarizeNote": "Заменяет вашу модель транскрипции на gpt-4o-transcribe-diarize — единственную модель OpenAI с определением говорящих. Стоимость может отличаться от выбранной модели.","mistralDiarizeNote": "Определение говорящих включено без дополнительной оплаты с Voxtral.",@@ -3382,7 +3387,8 @@"speaker": {"you": "Вы","others": "Другие"- }+ },+ "missingAudio": "[аудио отсутствует {{from}}-{{to}}]"},"workspaces": {"switcher": {diff --git a/src/locales/zh-CN/translation.json b/src/locales/zh-CN/translation.jsonindex 0f01c5d7c..981ca3140 100644--- a/src/locales/zh-CN/translation.json+++ b/src/locales/zh-CN/translation.json@@ -601,6 +601,7 @@"offline": "你目前离线。云端转录需要互联网连接。","dailyLimitReached": "已达今日转录上限。请明天再试或升级你的套餐。","providerRateLimited": "你的转录服务商限制了请求频率。请稍候再试。",+ "chunkLoss": "网络问题导致录音大部分丢失。请从历史记录中重新转录。","agentReasoningFailed": "语音助手无法处理该命令,已改为插入原始转录文本。","screenContextSkipped": "截图无法发送,因此已在没有屏幕上下文的情况下执行你的命令。"},@@ -2525,6 +2526,8 @@"cancelTranscription": "取消转录","transcriptionComplete": "转录完成","partialWarning": "部分音频内容无法转录。",+ "partialWarningCount": "{{total}}个音频片段中有{{failed}}个无法转写。",+ "chunkLossExceeded": "由于网络问题丢失了过多音频。请检查网络连接后重试。","openNote": "打开笔记","uploadAnother": "上传另一个","retry": "重试",@@ -2571,6 +2574,8 @@"speakerDetection": "说话人检测","speakerDetectionDescription": "识别音频中的不同说话人","numSpeakersPlaceholder": "自动检测",+ "numSpeakersLabel": "说话人数",+ "numSpeakersHint": "设置准确的人数可以提高准确性,尤其是长录音。","downloadingModels": "正在下载模型...","openaiDiarizeNote": "将替换您的转录模型为 gpt-4o-transcribe-diarize,这是唯一支持说话人检测的 OpenAI 模型。费用可能与您选择的模型不同。","mistralDiarizeNote": "使用 Voxtral 时说话人检测无需额外费用。",@@ -3352,7 +3357,8 @@"speaker": {"you": "你","others": "其他人"- }+ },+ "missingAudio": "[音频缺失 {{from}}-{{to}}]"},"workspaces": {"switcher": {diff --git a/src/locales/zh-TW/translation.json b/src/locales/zh-TW/translation.jsonindex a742f51fa..b6fb8ef1e 100644--- a/src/locales/zh-TW/translation.json+++ b/src/locales/zh-TW/translation.json@@ -601,6 +601,7 @@"offline": "你目前離線。雲端轉錄需要網際網路連線。","dailyLimitReached": "已達今日的轉錄上限。請明天再試或升級你的方案。","providerRateLimited": "你的轉錄服務商限制了請求頻率。請稍候再試。",+ "chunkLoss": "網路問題導致錄音大部分遺失。請從歷史記錄中重新轉錄。","agentReasoningFailed": "語音助理無法處理該指令,已改為插入原始逐字稿。","screenContextSkipped": "截圖無法傳送,因此已在沒有螢幕內容的情況下執行你的指令。"},@@ -2525,6 +2526,8 @@"cancelTranscription": "取消轉錄","transcriptionComplete": "轉錄完成","partialWarning": "部分音訊內容無法轉錄。",+ "partialWarningCount": "{{total}}個音訊片段中有{{failed}}個無法轉錄。",+ "chunkLossExceeded": "由於網路問題遺失了過多音訊。請檢查網路連線後重試。","openNote": "開啟筆記","uploadAnother": "上傳另一個","retry": "重試",@@ -2571,6 +2574,8 @@"speakerDetection": "說話者偵測","speakerDetectionDescription": "辨識音訊中的不同說話者","numSpeakersPlaceholder": "自動偵測",+ "numSpeakersLabel": "說話人數",+ "numSpeakersHint": "設定準確的人數可以提高準確度,尤其是長錄音。","downloadingModels": "正在下載模型...","openaiDiarizeNote": "將替換您的轉錄模型為 gpt-4o-transcribe-diarize,這是唯一支援說話人偵測的 OpenAI 模型。費用可能與您選擇的模型不同。","mistralDiarizeNote": "使用 Voxtral 時說話人偵測無需額外費用。",@@ -3352,7 +3357,8 @@"speaker": {"you": "你","others": "其他人"- }+ },+ "missingAudio": "[音訊缺失 {{from}}-{{to}}]"},"workspaces": {"switcher": {diff --git a/src/services/fileTranscription.ts b/src/services/fileTranscription.tsindex 75fb63abd..a2a775f6a 100644--- a/src/services/fileTranscription.ts+++ b/src/services/fileTranscription.ts@@ -14,6 +14,9 @@ export interface FileTranscriptionResult {code?: string;diarized?: boolean;warning?: string;+ // Set alongside `warning` by the chunked cloud path: how much audio was lost.+ failedChunks?: number;+ totalChunks?: number;}export interface DiarizationSettings {diff --git a/src/stores/batchQueueStore.ts b/src/stores/batchQueueStore.tsindex ca2466ab8..38871dde8 100644--- a/src/stores/batchQueueStore.ts+++ b/src/stores/batchQueueStore.ts@@ -1,7 +1,7 @@import { create } from "zustand";import { transcribeFileWithSpeakers } from "../services/fileTranscription";import type { FileTranscriptionConfig, DiarizationSettings } from "../services/fileTranscription";-import { DOWNLOAD_ERROR_KEYS } from "../components/notes/shared";+import { DOWNLOAD_ERROR_KEYS, transcriptionErrorKey } from "../components/notes/shared";import { getSettings } from "./settingsStore";import { isTranscriptionContextAllowed } from "./policyRules";import { usePolicyStore } from "./policyStore";@@ -208,9 +208,9 @@ export function processBatchQueue(updateItem(item.id, {status: "error",error:- transcriptionResult.code === "NO_SPEECH_DETECTED"- ? "noSpeechDetected"- : transcriptionResult.error || "batchTranscriptionFailed",+ transcriptionErrorKey(transcriptionResult) ||+ transcriptionResult.error ||+ "batchTranscriptionFailed",});return;}@@ -251,7 +251,8 @@ export function processBatchQueue(} catch (err) {updateItem(item.id, {status: "error",- error: err instanceof Error ? err.message : "batchUnknownError",+ error:+ transcriptionErrorKey(err) || (err instanceof Error ? err.message : "batchUnknownError"),});} finally {// Nothing else owns the temp file, so delete it even for a stale run.diff --git a/src/types/electron.ts b/src/types/electron.tsindex 957a16faa..bf7e2bf2d 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -1791,6 +1791,8 @@ declare global {success: boolean;text?: string;warning?: string;+ failedChunks?: number;+ totalChunks?: number;} & PolicyFailureMetadata>;diff --git a/test/helpers/cloudChunkPolicy.test.js b/test/helpers/cloudChunkPolicy.test.jsindex d1810b1b3..8d6101aaa 100644--- a/test/helpers/cloudChunkPolicy.test.js+++ b/test/helpers/cloudChunkPolicy.test.js@@ -6,14 +6,22 @@ const {CLOUD_CHUNK_MAX_ATTEMPTS,CLOUD_CHUNK_GLOBAL_CONCURRENCY,CLOUD_POOL_TEARDOWN_COOLDOWN_MS,+ CLOUD_CHUNK_MAX_TEARDOWN_REFUNDS,+ CLOUD_CHUNK_MAX_LOSS_RATIO,+ SILENT_CHUNK,FATAL_CHUNK_CODES,isTransientChunkError,isNetworkLevelFailure,+ isConnectionPoisoningFailure,+ isTeardownCollateral,+ summarizeChunkResults,+ assembleChunkTranscript,chunkRetryDelayMs,abortableSleep,createTeardownGate,createUploadSlots,} = require("../../src/helpers/cloudChunkPolicy");+const { changeLanguage } = require("../../src/helpers/i18nMain");const { createAbortError } = require("../../src/helpers/abortError");// The numbers are the #1326 contract: a dead upload fails within 2 minutes and@@ -43,7 +51,7 @@ test("teardown gate admits one drop per cooldown window", () => {assert.equal(gate(), true, "a later wedge must still be recoverable");});-test("auth and quota doom the job; silence dooms only its own chunk", () => {+test("auth and quota doom the job; a no-speech chunk is nonfatal", () => {assert.equal(FATAL_CHUNK_CODES.has("AUTH_EXPIRED"), true);assert.equal(FATAL_CHUNK_CODES.has("LIMIT_REACHED"), true);// Silence in one segment says nothing about the rest, so the siblings must@@ -122,6 +130,140 @@ test("abortableSleep rejects promptly when aborted mid-wait", async () => {assert.ok(Date.now() - start < 5_000, "abort did not interrupt the sleep");});+// A fatal TLS alert (Nat Molina's net::ERR_SSL_BAD_RECORD_MAC_ALERT) kills the+// HTTP/2 connection and every stream on it; waiting out the 30s cooldown just+// feeds retries back into the same sick pool until their budgets are gone.+test("fatal TLS/protocol errors are recognized as connection-poisoning", () => {+ for (const msg of [+ "net::ERR_SSL_BAD_RECORD_MAC_ALERT",+ "Failed to fetch: net::ERR_SSL_PROTOCOL_ERROR",+ "net::ERR_HTTP2_PROTOCOL_ERROR",+ "net::ERR_QUIC_PROTOCOL_ERROR",+ ]) {+ assert.equal(isConnectionPoisoningFailure(new Error(msg)), true, msg);+ }+});++test("ordinary failures are not connection-poisoning", () => {+ assert.equal(isConnectionPoisoningFailure(new Error("net::ERR_CONNECTION_CLOSED")), false);+ assert.equal(isConnectionPoisoningFailure(new Error("aborted")), false);+ assert.equal(+ isConnectionPoisoningFailure(Object.assign(new Error("x"), { statusCode: 502 })),+ false+ );+ assert.equal(isConnectionPoisoningFailure({}), false);+ assert.equal(isConnectionPoisoningFailure(null), false);+});++test("a forced teardown bypasses the cooldown and restarts the window", () => {+ let now = 0;+ const gate = createTeardownGate(CLOUD_POOL_TEARDOWN_COOLDOWN_MS, () => now);++ assert.equal(gate(), true);+ assert.equal(gate(true), true, "poisoned connection must be droppable inside the cooldown");+ now += CLOUD_POOL_TEARDOWN_COOLDOWN_MS - 1;+ assert.equal(gate(), false, "the forced drop restarts the cooldown window");+ now += 1;+ assert.equal(gate(), true);+});++// closeAllConnections() aborts every sibling still on the wire. Those failures+// are self-inflicted — the sibling's connection wasn't sick — so their attempts+// are refunded instead of charged.+test("teardown collateral: network-level failure during a teardown is refunded", () => {+ const abortLike = new Error("net::ERR_ABORTED");+ assert.equal(+ isTeardownCollateral(abortLike, { timedOut: false, teardownsDuringAttempt: 1 }),+ true+ );+});++test("teardown collateral requires a teardown during the attempt", () => {+ const abortLike = new Error("net::ERR_ABORTED");+ assert.equal(+ isTeardownCollateral(abortLike, { timedOut: false, teardownsDuringAttempt: 0 }),+ false+ );+});++test("a timeout or an answered request is never teardown collateral", () => {+ assert.equal(+ isTeardownCollateral(new Error("aborted"), { timedOut: true, teardownsDuringAttempt: 1 }),+ false,+ "a stalled upload is the chunk's own failure"+ );+ assert.equal(+ isTeardownCollateral(Object.assign(new Error("x"), { statusCode: 502 }), {+ timedOut: false,+ teardownsDuringAttempt: 1,+ }),+ false,+ "an HTTP answer proves the request outlived the teardown"+ );+ assert.equal(+ isTeardownCollateral(Object.assign(new Error("x"), { code: "AUTH_EXPIRED" }), {+ timedOut: false,+ teardownsDuringAttempt: 1,+ }),+ false+ );+});++test("refunds are bounded and the loss ceiling is a real fraction", () => {+ assert.ok(+ Number.isInteger(CLOUD_CHUNK_MAX_TEARDOWN_REFUNDS) && CLOUD_CHUNK_MAX_TEARDOWN_REFUNDS > 0+ );+ assert.ok(CLOUD_CHUNK_MAX_LOSS_RATIO > 0 && CLOUD_CHUNK_MAX_LOSS_RATIO < 1);+});++// Survivors used to be joined with a bare space — a 16-minute fragment of a+// 73-minute file read as a seamless transcript.+test("assembleChunkTranscript marks failed spans and collapses consecutive holes", () => {+ const results = [{ text: "one" }, null, null, { text: "four" }, null];+ assert.equal(+ assembleChunkTranscript(results, 240),+ "one [missing audio 4:00-12:00] four [missing audio 16:00-20:00]"+ );+});++test("assembleChunkTranscript handles a hole at the start and hour-long offsets", () => {+ const results = [null, { text: "later" }];+ assert.equal(assembleChunkTranscript(results, 3600), "[missing audio 0:00-1:00:00] later");+});++test("assembleChunkTranscript with no holes matches the plain join", () => {+ const results = [{ text: " a " }, { text: "b\n\nc" }];+ assert.equal(assembleChunkTranscript(results, 240), "a b c");+});++test("silent chunks are omitted without consuming the failure budget", () => {+ const results = [{ text: "one" }, SILENT_CHUNK, null, { text: "four" }];+ assert.deepEqual(summarizeChunkResults(results), {+ responses: [{ text: "one" }, { text: "four" }],+ failedChunks: 1,+ silentChunks: 1,+ });+ assert.equal(assembleChunkTranscript(results, 240), "one [missing audio 8:00-12:00] four");+});++test("the final missing-audio marker ends at the real input duration", () => {+ const results = new Array(19).fill(SILENT_CHUNK);+ results[18] = null;+ assert.equal(assembleChunkTranscript(results, 240, 73 * 60), "[missing audio 1:12:00-1:13:00]");+});++// The marker is persisted into notes and pasted by dictation, so it belongs to+// the UI language like the [Speaker N] labels do.+test("the missing-audio marker follows the UI language", (t) => {+ changeLanguage("de");+ t.after(() => changeLanguage("en"));++ assert.equal(+ assembleChunkTranscript([{ text: "eins" }, null], 240),+ "eins [fehlendes Audio 4:00-8:00]"+ );+});+test("upload slots cap concurrent holders across independent acquirers", async () => {const slots = createUploadSlots(2);const r1 = await slots.acquire();diff --git a/test/helpers/diarizationPolicy.test.js b/test/helpers/diarizationPolicy.test.jsnew file mode 100644index 000000000..0573566aa--- /dev/null+++ b/test/helpers/diarizationPolicy.test.js@@ -0,0 +1,100 @@+const test = require("node:test");+const assert = require("node:assert/strict");++const {+ DEFAULT_CLUSTER_THRESHOLD,+ LONG_AUDIO_CLUSTER_THRESHOLD,+ THRESHOLD_RAMP_START_SECONDS,+ THRESHOLD_RAMP_END_SECONDS,+ MIN_CLUSTER_TOTAL_SECONDS,+ clusterThresholdForDuration,+ resolveClusterThreshold,+ dropNegligibleClusters,+} = require("../../src/helpers/diarizationPolicy");++// 0.55 is tuned for short clean audio; on a 73-minute single-mic voice memo one+// speaker's embeddings spread past it and clustering stopped merging at 46+// "speakers". The threshold must grow with duration.+test("short audio keeps the sherpa default threshold", () => {+ assert.equal(clusterThresholdForDuration(0), DEFAULT_CLUSTER_THRESHOLD);+ assert.equal(+ clusterThresholdForDuration(THRESHOLD_RAMP_START_SECONDS),+ DEFAULT_CLUSTER_THRESHOLD+ );+});++test("threshold ramps between the boundaries and is monotonic", () => {+ const mid = clusterThresholdForDuration(+ (THRESHOLD_RAMP_START_SECONDS + THRESHOLD_RAMP_END_SECONDS) / 2+ );+ assert.ok(mid > DEFAULT_CLUSTER_THRESHOLD && mid < LONG_AUDIO_CLUSTER_THRESHOLD);+ assert.ok(+ clusterThresholdForDuration(THRESHOLD_RAMP_START_SECONDS + 60) <= mid,+ "threshold must not decrease with duration"+ );+});++test("hour-plus audio is clamped to the long-audio threshold", () => {+ assert.equal(+ clusterThresholdForDuration(THRESHOLD_RAMP_END_SECONDS),+ LONG_AUDIO_CLUSTER_THRESHOLD+ );+ assert.equal(clusterThresholdForDuration(3 * 3600), LONG_AUDIO_CLUSTER_THRESHOLD);+});++test("unknown duration falls back to the default threshold", () => {+ assert.equal(clusterThresholdForDuration(NaN), DEFAULT_CLUSTER_THRESHOLD);+ assert.equal(clusterThresholdForDuration(undefined), DEFAULT_CLUSTER_THRESHOLD);+ assert.equal(clusterThresholdForDuration(-5), DEFAULT_CLUSTER_THRESHOLD);+});++test("explicit thresholds accept zero, clamp bounds, and reject non-finite values", () => {+ assert.equal(resolveClusterThreshold(3600, 0), 0);+ assert.equal(resolveClusterThreshold(3600, 2), 1);+ assert.equal(resolveClusterThreshold(3600, -1), 0);+ assert.equal(resolveClusterThreshold(3600, ""), clusterThresholdForDuration(3600));+ assert.equal(resolveClusterThreshold(3600, "not-a-number"), clusterThresholdForDuration(3600));+ assert.equal(resolveClusterThreshold(3600, Infinity), clusterThresholdForDuration(3600));+});++// Every cluster — however tiny — wins at least one sentence in the character-+// proportional merge, so a stray blip becomes a phantom [Speaker N].+test("clusters below the minimum total speaking time are dropped", () => {+ const segments = [+ { start: 0, end: 30, speaker: "speaker_0" },+ { start: 30, end: 30.4, speaker: "speaker_7" },+ { start: 31, end: 60, speaker: "speaker_1" },+ { start: 60, end: 60.3, speaker: "speaker_7" },+ ];+ const kept = dropNegligibleClusters(segments);+ assert.deepEqual(+ kept.map((s) => s.speaker),+ ["speaker_0", "speaker_1"]+ );+});++test("a cluster whose short segments add up past the minimum survives", () => {+ const segments = [+ { start: 0, end: 30, speaker: "speaker_0" },+ { start: 30, end: 30.6, speaker: "speaker_1" },+ { start: 40, end: 40.6, speaker: "speaker_1" },+ ];+ assert.equal(dropNegligibleClusters(segments).length, 3);+});++test("dropping never empties the result or touches a clean input", () => {+ const allTiny = [+ { start: 0, end: 0.3, speaker: "speaker_0" },+ { start: 1, end: 1.2, speaker: "speaker_1" },+ ];+ assert.deepEqual(dropNegligibleClusters(allTiny), allTiny);++ const clean = [{ start: 0, end: 10, speaker: "speaker_0" }];+ assert.deepEqual(dropNegligibleClusters(clean), clean);+ assert.deepEqual(dropNegligibleClusters([]), []);+ assert.equal(dropNegligibleClusters(null), null);+});++test("minimum speaking time constant is sane", () => {+ assert.ok(MIN_CLUSTER_TOTAL_SECONDS >= 0.5 && MIN_CLUSTER_TOTAL_SECONDS <= 5);+});diff --git a/test/helpers/ffmpegUtils.test.js b/test/helpers/ffmpegUtils.test.jsnew file mode 100644index 000000000..ca6ae2901--- /dev/null+++ b/test/helpers/ffmpegUtils.test.js@@ -0,0 +1,14 @@+const test = require("node:test");+const assert = require("node:assert/strict");++const { parseFfmpegDuration } = require("../../src/helpers/ffmpegUtils");++test("parseFfmpegDuration reads the input duration from ffmpeg output", () => {+ const stderr = "Input #0, mp3, from 'recording.mp3':\n Duration: 01:13:00.25, start: 0.000000";+ assert.equal(parseFfmpegDuration(stderr), 4380.25);+});++test("parseFfmpegDuration returns null when ffmpeg reports no duration", () => {+ assert.equal(parseFfmpegDuration("Duration: N/A"), null);+ assert.equal(parseFfmpegDuration(""), null);+});diff --git a/test/helpers/ipcPolicyHeaderCoverage.test.js b/test/helpers/ipcPolicyHeaderCoverage.test.jsindex 900cef0a2..63d41be9c 100644--- a/test/helpers/ipcPolicyHeaderCoverage.test.js+++ b/test/helpers/ipcPolicyHeaderCoverage.test.js@@ -37,6 +37,25 @@ test("all OpenWhispr multipart transcription transports use policy headers", ());});+test("chunk pool recovery cannot abort inline multipart uploads", () => {+ const chunkedStart = source.indexOf("async function chunkedCloudTranscribe");+ const handlersStart = source.indexOf("class IPCHandlers");+ assert.ok(chunkedStart >= 0 && handlersStart > chunkedStart);++ const chunkedSource = source.slice(chunkedStart, handlersStart);+ assert.match(chunkedSource, /session:\s*getChunkCloudUploadSession\(\)/);+ assert.doesNotMatch(chunkedSource, /getInlineCloudUploadSession/);+ assert.match(+ source,+ /async function dropUploadConnections[\s\S]{0,300}?getChunkCloudUploadSession\(\)\.closeAllConnections/+ );++ const handlerSource = source.slice(handlersStart);+ assert.match(handlerSource, /session:\s*getInlineCloudUploadSession\(\)/);+ assert.doesNotMatch(handlerSource, /session:\s*getChunkCloudUploadSession\(\)/);+ assert.doesNotMatch(source, /session:\s*getCloudUploadSession\(/);+});+test("the shared realtime-token helper applies policy headers", () => {assert.match(source,diff --git a/test/helpers/transcriptionErrorKeys.test.js b/test/helpers/transcriptionErrorKeys.test.jsnew file mode 100644index 000000000..7feec656e--- /dev/null+++ b/test/helpers/transcriptionErrorKeys.test.js@@ -0,0 +1,43 @@+const test = require("node:test");+const assert = require("node:assert/strict");++const en = require("../../src/locales/en/translation.json");++const load = () => import("../../src/components/notes/shared.ts");++// Codes chunkedCloudTranscribe and interpretTranscribeResponse surface to the+// upload UI. Anything added there needs a locale key or it reaches the user as+// a raw English main-process string.+const MAPPED_CODES = ["NO_SPEECH_DETECTED", "CHUNK_LOSS_EXCEEDED"];++test("every mapped code resolves to a key that exists in en", async () => {+ const { transcriptionErrorKey } = await load();++ for (const code of MAPPED_CODES) {+ const key = transcriptionErrorKey({ code });+ assert.ok(key, `${code} has no i18n key`);+ assert.ok(en.notes.upload[key], `notes.upload.${key} is missing from en`);+ }+});++// OpenWhispr Cloud rethrows coded failures through withSessionRefresh, so the+// upload views only see them in a catch block — resolving from the returned+// result alone silently left cloud users with the raw English message.+test("a thrown failure resolves the same key as a returned one", async () => {+ const { transcriptionErrorKey } = await load();++ const thrown = Object.assign(new Error("12 of 19 audio segments were lost"), {+ code: "CHUNK_LOSS_EXCEEDED",+ });+ assert.equal(transcriptionErrorKey(thrown), "chunkLossExceeded");+ assert.equal(transcriptionErrorKey({ code: "CHUNK_LOSS_EXCEEDED" }), "chunkLossExceeded");+});++test("unmapped, codeless and absent failures fall through to the raw message", async () => {+ const { transcriptionErrorKey } = await load();++ assert.equal(transcriptionErrorKey({ code: "SERVER_ERROR" }), undefined);+ assert.equal(transcriptionErrorKey(new Error("boom")), undefined);+ assert.equal(transcriptionErrorKey(null), undefined);+ assert.equal(transcriptionErrorKey(undefined), undefined);+});