From 46dee3c29f39011623ab8be2568e21ee8ba86b22 Mon Sep 17 00:00:00 2001 From: Jeremy Liu Date: Thu, 19 Nov 2026 23:30:15 +0000 Subject: [PATCH 1/2] fix: expose all recording transcript sources in preferred order Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- CHANGELOG.md | 4 + crates/oah/src/routes/recordings/mod.rs | 152 +++++++++++++++++- spec/recordings.md | 17 +- spec/ui-library.md | 1 + .../components/recording/recording-detail.tsx | 3 +- 5 files changed, 162 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 113da9e..3dc0645 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and ## [Unreleased] +### Fixed + +- Recordings with multiple transcript sources show every source in the transcript switcher, with the preferred source first. The detail API includes all transcripts while keeping the singular `transcription` field for existing clients. + ## [1.6.0] - 2026-11-06 ### Added diff --git a/crates/oah/src/routes/recordings/mod.rs b/crates/oah/src/routes/recordings/mod.rs index 811ee75..c963305 100644 --- a/crates/oah/src/routes/recordings/mod.rs +++ b/crates/oah/src/routes/recordings/mod.rs @@ -557,22 +557,28 @@ async fn detail( UrlPath(id): UrlPath, ) -> ApiResult> { let row = find(&state, &user.id, &id).await?; - let transcript = sqlx::query_as::<_, TranscriptRow>( + let settings = crate::routes::settings::effective(&state, &user.id).await?; + let preferred = settings["preferredTranscriptSource"] + .as_str() + .unwrap_or("plaud"); + let transcripts = sqlx::query_as::<_, TranscriptRow>( "SELECT id, recording_id, user_id, text, detected_language, transcription_type, provider, model, timeline, timeline_source, \ source, created_at FROM transcriptions WHERE recording_id = ? AND user_id = ? \ - ORDER BY created_at DESC LIMIT 1", + ORDER BY CASE WHEN source = ? THEN 0 ELSE 1 END, created_at DESC, id DESC", ) .bind(id.as_str()) .bind(user.id.as_str()) - .fetch_optional(&state.db) + .bind(preferred) + .fetch_all(&state.db) .await?; - let transcription = match transcript { - Some(t) => transcript_json(&state.config.field_key, t)?, - None => Value::Null, - }; + let transcriptions = transcripts + .into_iter() + .map(|t| transcript_json(&state.config.field_key, t)) + .collect::>>()?; + let transcription = transcriptions.first().cloned().unwrap_or(Value::Null); let recording = row_json(&state.config.field_key, row)?; Ok(Json( - json!({ "recording": recording, "transcription": transcription }), + json!({ "recording": recording, "transcription": transcription, "transcriptions": transcriptions }), )) } @@ -2016,6 +2022,136 @@ mod tests { .to_vec() } + #[tokio::test] + async fn detail_returns_all_sources_in_preferred_order() { + let dir = tempfile::tempdir().unwrap(); + let config = crate::config::Config::for_tests(dir.path()); + let state = AppState::new(config, crate::db::open_memory().await.unwrap()); + for id in ["u1", "u2"] { + sqlx::query( + "INSERT INTO users (id, email, created_at, updated_at) VALUES (?, ?, 0, 0)", + ) + .bind(id) + .bind(format!("{id}@example.test")) + .execute(&state.db) + .await + .unwrap(); + } + insert( + &state.db, + &state.config.field_key, + NewRecording { + id: "rec", + user_id: "u1", + plaud_file_id: "rec", + title: "Meeting", + duration: 3_000, + start: 0, + filesize: 10, + file_md5: "00000000000000000000000000000000", + storage_type: "local", + storage_path: "u1/rec.mp3", + title_source: "original", + auto_export_eligible: false, + waveform_peaks: None, + }, + ) + .await + .unwrap(); + let user = |id: &str| CurrentUser { + id: id.into(), + email: format!("{id}@example.test"), + name: None, + session_id: "session".into(), + }; + let read = || detail(State(state.clone()), user("u1"), UrlPath("rec".into())); + let Json(empty) = read().await.unwrap(); + assert_eq!(empty["transcriptions"], json!([])); + assert_eq!(empty["transcription"], Value::Null); + + let timeline = json!([{ "start_ms": 0, "end_ms": 1000, "text": "Hello" }]); + for (id, owner, source, created) in [ + ("p", "u1", "plaud", 10), + ("a", "u1", "openaudiohub", 20), + ("m", "u1", "mixed", 20), + ("foreign", "u2", "plaud", 100), + ] { + sqlx::query( + "INSERT INTO transcriptions (id, recording_id, user_id, text, provider, model, timeline, timeline_source, source, created_at) \ + VALUES (?, 'rec', ?, ?, 'provider', 'model', ?, 'native', ?, ?)", + ) + .bind(id) + .bind(owner) + .bind(state.config.field_key.encrypt(&format!("Text from {source}"))) + .bind(state.config.field_key.encrypt_json(&timeline).to_string()) + .bind(source) + .bind(created) + .execute(&state.db) + .await + .unwrap(); + } + let sources = |data: &Value| -> Vec { + data["transcriptions"] + .as_array() + .unwrap() + .iter() + .map(|t| t["source"].as_str().unwrap().to_owned()) + .collect() + }; + let Json(default) = read().await.unwrap(); + assert_eq!(sources(&default), ["plaud", "mixed", "openaudiohub"]); + assert_eq!(default["transcription"], default["transcriptions"][0]); + assert_eq!(default["transcription"]["text"], "Text from plaud"); + assert_eq!(default["transcription"]["timeline"], timeline); + for row in default["transcriptions"].as_array().unwrap() { + assert_eq!(row["userId"], "u1"); + assert_eq!(row["timeline"], timeline); + } + sqlx::query("INSERT INTO user_settings (user_id, data, updated_at) VALUES ('u1', ?, 0)") + .bind(json!({ "preferredTranscriptSource": "openaudiohub" }).to_string()) + .execute(&state.db) + .await + .unwrap(); + let Json(preferred) = read().await.unwrap(); + assert_eq!(sources(&preferred), ["openaudiohub", "mixed", "plaud"]); + assert_eq!(preferred["transcription"], preferred["transcriptions"][0]); + + sqlx::query("DELETE FROM transcriptions WHERE id = 'a'") + .execute(&state.db) + .await + .unwrap(); + let Json(absent) = read().await.unwrap(); + assert_eq!(sources(&absent), ["mixed", "plaud"]); + assert_eq!(absent["transcription"]["source"], "mixed"); + sqlx::query("DELETE FROM transcriptions WHERE id = 'm'") + .execute(&state.db) + .await + .unwrap(); + let Json(single) = read().await.unwrap(); + assert_eq!(sources(&single), ["plaud"]); + assert_eq!(single["transcription"], single["transcriptions"][0]); + + for (owner, id) in [("u2", "rec"), ("u1", "missing")] { + let error = detail(State(state.clone()), user(owner), UrlPath(id.into())) + .await + .unwrap_err(); + assert_eq!(error.code, "RECORDING_NOT_FOUND"); + } + sqlx::query("UPDATE transcriptions SET text = 'v1:invalid' WHERE id = 'p'") + .execute(&state.db) + .await + .unwrap(); + assert_eq!( + read().await.unwrap_err().status, + StatusCode::INTERNAL_SERVER_ERROR + ); + sqlx::query("UPDATE recordings SET deleted_at = 1 WHERE id = 'rec'") + .execute(&state.db) + .await + .unwrap(); + assert_eq!(read().await.unwrap_err().code, "RECORDING_NOT_FOUND"); + } + #[tokio::test] async fn mixed_library_streams_ranges_zips_and_deletes() { use crate::config::{Config, StorageType}; diff --git a/spec/recordings.md b/spec/recordings.md index bf2ba04..731c92c 100644 --- a/spec/recordings.md +++ b/spec/recordings.md @@ -3,8 +3,8 @@ This file covers recordings as a client sees them over HTTP: the list, one recording, edits, deletion, starring, upload, audio streaming, waveform peaks, batch download, and merge. Transcripts and summaries live in -`transcription.md` and `ai.md`. The detail response includes a `transcription` -field; its shape is described there. +`transcription.md` and `ai.md`. The detail response includes `transcriptions` +and a compatible singular `transcription` field; their row shape is described there. Tests: `contract-tests/tests/recordings.spec.ts`. @@ -106,12 +106,17 @@ Response: `200` ```json { "recording": { "id": "abc", "filename": "Standup", "duration": 3096 }, - "transcription": null + "transcription": null, + "transcriptions": [] } ``` -`recording` has the full field set above. `transcription` is the caller's -transcript row for this recording, with its text in plaintext, or `null` when -none exists. See `transcription.md` for its fields. +`recording` has the full field set above. `transcriptions` contains all of the +caller's transcript rows for this recording, with text and timelines decrypted. +Rows matching the caller's `preferredTranscriptSource` setting (default `plaud`) +come first, then rows are ordered by `created_at` descending and `id` descending +to break ties. If the preferred source is absent, the newest available row comes +first. `transcription` is the first row, or `null` when the array is empty, for +clients that read only one transcript. See `transcription.md` for row fields. Errors: `401` `AUTH_SESSION_MISSING`; `404` `RECORDING_NOT_FOUND` (unknown, deleted, or not the caller's) Side effects: none diff --git a/spec/ui-library.md b/spec/ui-library.md index 819d030..038b83c 100644 --- a/spec/ui-library.md +++ b/spec/ui-library.md @@ -365,6 +365,7 @@ Body: - Source switcher (`source-switcher`): one button per transcript source ("Plaud", "Mix", "Your provider"). Shown only when there is more than one transcript. Selecting one switches the text. The primary source comes first. + The detail response's `transcriptions` array supplies every source in preferred-source order. With no explicit selection, the first transcript is shown; if a selected source is removed, the view and active switcher button fall back to the first remaining transcript. Older servers returning only `transcription` remain supported. - Toolbar (`transcript-toolbar`): "Download transcript as TXT", "Download transcript as JSON" (both download a file built in the browser), and "Delete" (`DELETE /api/recordings/{id}/transcription?source=` after a confirmation titled "Delete this transcript?"; the summary is removed with it). diff --git a/web/src/components/recording/recording-detail.tsx b/web/src/components/recording/recording-detail.tsx index 5320e3c..0dceb20 100644 --- a/web/src/components/recording/recording-detail.tsx +++ b/web/src/components/recording/recording-detail.tsx @@ -247,6 +247,7 @@ function RecordingDetailView({ id, variant }: RecordingDetailProps) { const { recording } = data; const transcripts: TranscriptRecord[] = data.transcriptions ?? (data.transcription ? [data.transcription] : []); const transcript = transcripts.find((tr) => tr.source === source) ?? transcripts[0] ?? null; + const selectedSource = transcript?.source ?? null; const busy = transcribing || pipe.active; const runTranscribe = async (body: { providerId?: string; model?: string }) => { @@ -353,7 +354,7 @@ function RecordingDetailView({ id, variant }: RecordingDetailProps) { recordingTitle={recording.filename} transcript={transcript} transcripts={transcripts} - selectedSource={source} + selectedSource={selectedSource} onSelectSource={setSource} pipeline={pipe.pipeline} pipelineActive={pipe.active} From 6d7d6b8a59f4dc37119fbfc92ac0f0032db1efd4 Mon Sep 17 00:00:00 2001 From: Jeremy Liu Date: Thu, 19 Nov 2026 23:48:25 +0000 Subject: [PATCH 2/2] fix(recordings): search all transcript sources and cover source ordering Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- CHANGELOG.md | 1 + .../tests/transcript-sources.spec.ts | 73 +++++++++++++++++++ crates/oah/src/routes/recordings/search.rs | 42 +++++------ spec/recordings.md | 6 +- 4 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 contract-tests/tests/transcript-sources.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dc0645..eb1b24f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and ### Fixed - Recordings with multiple transcript sources show every source in the transcript switcher, with the preferred source first. The detail API includes all transcripts while keeping the singular `transcription` field for existing clients. +- Library text search matches every transcript source available for a recording, including older sources, without duplicate results. ## [1.6.0] - 2026-11-06 diff --git a/contract-tests/tests/transcript-sources.spec.ts b/contract-tests/tests/transcript-sources.spec.ts new file mode 100644 index 0000000..e2e3383 --- /dev/null +++ b/contract-tests/tests/transcript-sources.spec.ts @@ -0,0 +1,73 @@ +import { expect, test } from "@playwright/test"; +import { randomUUID } from "node:crypto"; +import { newUserContext, uploadRecording } from "../helpers/api"; +import { fakeControl } from "../helpers/plaud-extra"; + +test("detail exposes empty and single-source arrays and preserves missing-recording errors", async () => { + const api = await newUserContext("transcript-empty"); + try { + const id = await uploadRecording(api); + const detail = () => api.get(`/api/recordings/${id}`); + expect(await (await detail()).json()).toMatchObject({ transcription: null, transcriptions: [] }); + expect((await api.post(`/api/recordings/${id}/transcription/from-browser`, { + data: { text: "Only source", model: "whisper-base" }, + })).status()).toBe(200); + const single = await (await detail()).json(); + expect(single.transcriptions).toHaveLength(1); + expect(single.transcriptions[0]).toEqual(single.transcription); + expect(single.transcription).toMatchObject({ text: "Only source", source: "openaudiohub" }); + const other = await newUserContext("transcript-other"); + try { expect((await other.get(`/api/recordings/${id}`)).status()).toBe(404); } finally { await other.dispose(); } + expect((await api.delete(`/api/recordings/${id}`)).status()).toBe(200); + expect((await detail()).status()).toBe(404); + expect((await api.get("/api/recordings/missing-transcript-recording")).status()).toBe(404); + } finally { + await api.dispose(); + } +}); + +test("detail orders all sources by preference and search matches older sources", async () => { + const api = await newUserContext("transcript-sources"); + try { + const email = `sources-${randomUUID()}@example.test`; + const plaudId = `sources-${randomUUID()}`; + expect((await api.put("/api/settings/user", { data: { importPlaudContent: true } })).status()).toBe(200); + await fakeControl("/account", { email, recordings: [{ id: plaudId, is_trans: true }] }); + const sent = await api.post("/api/plaud/auth/send-code", { data: { email } }); + expect(sent.status()).toBe(200); + const { otpToken, apiBase } = await sent.json(); + expect((await api.post("/api/plaud/auth/verify", { data: { email, otpToken, apiBase, code: "123456" } })).status()).toBe(200); + const sync = await api.post("/api/plaud/sync"); + expect(sync.status()).toBe(200); + expect((await sync.json()).errors).toEqual([]); + const { recordings } = await (await api.get("/api/recordings")).json(); + const id = recordings.find((row: { plaudFileId: string }) => row.plaudFileId === plaudId)?.id; + expect(id).toBeTruthy(); + const detail = async () => { + const response = await api.get(`/api/recordings/${id}`); + expect(response.status()).toBe(200); + return response.json(); + }; + const imported = await detail(); + expect(imported.transcriptions).toHaveLength(1); + expect(imported.transcription.source).toBe("plaud"); + expect((await api.post(`/api/recordings/${id}/transcription/from-browser`, { + data: { text: "Unique browser words", model: "whisper-base" }, + })).status()).toBe(200); + for (const preferred of ["plaud", "openaudiohub"] as const) { + expect((await api.put("/api/settings/user", { data: { preferredTranscriptSource: preferred } })).status()).toBe(200); + const body = await detail(); + expect(body.transcriptions.map((row: { source: string }) => row.source)).toEqual( + preferred === "plaud" ? ["plaud", "openaudiohub"] : ["openaudiohub", "plaud"], + ); + expect(body.transcription).toEqual(body.transcriptions[0]); + } + for (const query of [`Fake transcript line for ${plaudId}`, "Unique browser words"]) { + const search = await api.get("/api/recordings/search", { params: { q: query } }); + expect(search.status()).toBe(200); + expect(await search.json()).toEqual({ recordingIds: [id] }); + } + } finally { + await api.dispose(); + } +}); diff --git a/crates/oah/src/routes/recordings/search.rs b/crates/oah/src/routes/recordings/search.rs index 625273e..4042299 100644 --- a/crates/oah/src/routes/recordings/search.rs +++ b/crates/oah/src/routes/recordings/search.rs @@ -78,28 +78,16 @@ pub async fn search( } } - // A recording's own transcript is the one the detail page shows: the newest one for the - // recording. Matching any older transcript would show a recording that no longer contains - // the text the user searched for. - // The transcript a search is about is the one the detail page shows: the newest for the - // recording, with the same tie-break so two rows of one timestamp cannot disagree. Grouping - // keeps it to one row per recording. let transcripts: Vec<(String, String)> = sqlx::query_as( - "SELECT recording_id, text FROM ( - SELECT recording_id, text, - ROW_NUMBER() OVER (PARTITION BY recording_id ORDER BY created_at DESC, id DESC) AS rank - FROM transcriptions WHERE user_id = ? - ) WHERE rank = 1 - AND EXISTS (SELECT 1 FROM recordings r WHERE r.id = recording_id AND r.user_id = ? AND r.deleted_at IS NULL)", + "SELECT t.recording_id, t.text FROM transcriptions t + JOIN recordings r ON r.id = t.recording_id + WHERE t.user_id = ? AND r.user_id = ? AND r.deleted_at IS NULL", ) .bind(&user.id) .bind(&user.id) .fetch_all(&state.db) .await?; for (recording_id, text) in transcripts { - if matched.contains(&recording_id) { - continue; - } let plain = state .config .field_key @@ -305,11 +293,9 @@ mod tests { } #[tokio::test] - async fn only_the_newest_transcript_is_searched() { + async fn all_transcript_sources_are_searched_once_per_recording() { let (state, _dir) = state().await; recording(&state, "r1", "u", "name").await; - // Two transcripts of different sources: the newest one is what the detail page shows, so - // it is the text a search is about. sqlx::query( "INSERT INTO transcriptions (id, recording_id, user_id, text, transcription_type, provider, model, source, created_at) VALUES ('old', 'r1', 'u', ?, 'server', 'Plaud', 'plaud-native', 'plaud', 0)", @@ -326,11 +312,25 @@ mod tests { .execute(&state.db) .await .unwrap(); + transcript(&state, "r1", "other", "foreign secret").await; + assert_eq!(ids_for(&state, "u", "old words").await.unwrap(), ["r1"]); + assert_eq!(ids_for(&state, "u", "new words").await.unwrap(), ["r1"]); + assert_eq!(ids_for(&state, "u", "words").await.unwrap(), ["r1"]); assert!( - ids_for(&state, "u", "old words").await.unwrap().is_empty(), - "an older transcript is not what a search is about" + ids_for(&state, "u", "foreign secret") + .await + .unwrap() + .is_empty() + ); + assert!(ids_for(&state, "u", "absent").await.unwrap().is_empty()); + sqlx::query("UPDATE transcriptions SET text = 'v1:invalid' WHERE id = 'old'") + .execute(&state.db) + .await + .unwrap(); + assert_eq!( + ids_for(&state, "u", "new words").await.unwrap_err().code, + "SEARCH_FAILED" ); - assert_eq!(ids_for(&state, "u", "new words").await.unwrap(), ["r1"]); } /// A stored value that cannot be read makes the search an error. Reporting it as a complete diff --git a/spec/recordings.md b/spec/recordings.md index 731c92c..5c23605 100644 --- a/spec/recordings.md +++ b/spec/recordings.md @@ -80,9 +80,9 @@ Response: `200` ```json { "recordingIds": ["abc", "def"] } ``` -The caller's non-deleted recordings whose name, or whose newest transcript text, contains -`q`. A recording appears once, whether the name or the text matched. Only the newest -transcript of a recording is searched: it is the one the detail page shows. The ids are +The caller's non-deleted recordings whose name, or any of the caller's transcript sources, contains +`q`. A recording appears once, whether its name or one or more transcripts matched. Every +source available in the detail switcher is searched, not only the newest or preferred one. The ids are returned in no particular order, and the list the client already has is what sorts and filters them.