Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and

## [Unreleased]

### Security

- Update `zip` and `lettre` to fix archive-reading and SMTP security advisories.

### Fixed

- Failed and stopped Ask AI answers save their final status before notifying clients, so reloading an ended stream cannot leave the answer busy.
- Audio pipeline progress keeps updating after temporary network failures, and interrupted Ask AI answers reconnect without duplicating text.
- Transcript searches refresh after re-transcription, and browser transcription progress and notifications follow the interface language.

- A failure to open or lock the Mac app's instance-lock file now shows a startup error instead of silently exiting as if another copy were running.
- Launch at Login keeps its tray check mark in sync after an interface-language change rebuilds the menu.
- Changing the Mac app's locale through desktop preferences no longer hangs while rebuilding the tray menu.
- Native Mac menu labels and dialogs now change language immediately instead of keeping the language selected at startup.
- The Mac app grants its own page permission to save an interface-language choice through the desktop bridge.
- The Mac app builds its bundled ffmpeg, ffprobe and their C dependencies for the app's minimum macOS version, and rejects sidecars that require a newer system.

### Security

- Update `zip` and `lettre` to fix archive-reading and SMTP security advisories.

## [1.6.0] - 2026-11-06

### Added
Expand Down
97 changes: 97 additions & 0 deletions contract-tests/tests/recording-recovery-ui.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { type Browser, expect, test } from "@playwright/test";
import { configureAccount, newUserContext, uploadRecording } from "../helpers/api";

async function recordingPage(browser: Browser) {
const api = await newUserContext("recovery-ui");
await configureAccount(api);
const id = await uploadRecording(api);
const saved = await api.post(`/api/recordings/${id}/transcription/from-browser`, {
data: { text: "Words for the recording", model: "whisper-base" },
});
expect(saved.status()).toBe(200);
const initialChat = await (await api.get(`/api/recordings/${id}/chat`)).json();
const context = await browser.newContext({
storageState: await api.storageState(),
baseURL: process.env.OAH_BASE_URL,
viewport: { width: 1440, height: 900 },
});
return { id, initialChat, page: await context.newPage(), async dispose() { await context.close(); await api.dispose(); } };
}

test("active pipeline polling recovers from a failed poll and stops on completion", async ({ browser }) => {
const account = await recordingPage(browser);
try {
let polls = 0;
await account.page.route(`**/api/recordings/${account.id}/audio-pipeline`, async (route) => {
polls++;
if (polls === 2) return route.abort("failed");
await route.fulfill({ json: {
job: { id: "job", status: polls >= 4 ? "completed" : "running", phase: "transcribe", progress: polls >= 4 ? 100 : 25 },
timeline: null, timestampSource: null, transcription: null,
} });
});
await account.page.goto(`/recordings/${account.id}`);
await expect(account.page.getByTestId("pipeline-status")).toBeVisible();
await expect.poll(() => polls, { timeout: 20_000 }).toBe(4);
await expect(account.page.getByTestId("pipeline-status")).toHaveCount(0);
await account.page.clock.install();
await account.page.clock.fastForward(60_000);
expect(polls).toBe(4);
} finally {
await account.dispose();
}
});

for (const interruption of ["clean EOF", "network error", "none", "exhausted"] as const) {
test(`chat stream recovery: ${interruption}`, async ({ browser }) => {
const account = await recordingPage(browser);
try {
let streams = 0;
let submitted = false;
let completed = false;
const turn = {
id: "recovery-turn", seq: 1, status: "running", question: "What happened?", answer: "", citations: [], partial: false,
provider: "Custom", model: "fake-chat-1", effort: { requested: null, sent: null, known: false }, error: null,
createdAt: new Date().toISOString(), finishedAt: null,
};
await account.page.route(`**/api/recordings/${account.id}/chat**`, async (route) => {
const path = new URL(route.request().url()).pathname;
if (path.endsWith("/events")) {
streams++;
if (interruption === "network error" && streams === 1) return route.abort("failed");
if (interruption === "exhausted") return route.fulfill({ contentType: "text/event-stream", body: "" });
if (interruption === "clean EOF" && streams === 1) {
return route.fulfill({ contentType: "text/event-stream", body: 'event: snapshot\ndata: {"status":"running","answer":"Hello"}\n\nevent: delta\ndata: {"text":" wor"}\n\n' });
}
completed = true;
return route.fulfill({ contentType: "text/event-stream", body: 'event: snapshot\ndata: {"status":"running","answer":"Hello"}\n\nevent: delta\ndata: {"text":" world"}\n\nevent: done\ndata: {}\n\n' });
}
if (path.endsWith("/turns") && route.request().method() === "POST") {
submitted = true;
return route.fulfill({ json: { turn } });
}
if (route.request().method() === "GET" && path.endsWith("/chat")) {
const current = { ...turn, status: completed ? "completed" : "running", answer: completed ? "Hello world" : "" };
return route.fulfill({ json: { ...account.initialChat, activeTurn: submitted && !completed ? current : null, turns: submitted ? [current] : [] } });
}
return route.continue();
});
await account.page.goto(`/recordings/${account.id}`);
await account.page.getByTestId("recording-ask-ai").click();
await account.page.getByLabel("Your question").fill(turn.question);
await account.page.getByTestId("chat-send").click();
if (interruption === "exhausted") {
await expect(account.page.getByText("The connection to the answer was lost.")).toBeVisible({ timeout: 20_000 });
expect(streams).toBe(5);
} else {
await expect(account.page.getByTestId("chat-turn")).toHaveAttribute("data-status", "completed");
await expect(account.page.getByTestId("chat-turn").locator(".chat-markdown")).toHaveText("Hello world");
expect(streams).toBe(interruption === "none" ? 1 : 2);
await expect(account.page.getByTestId("chat-stop")).toHaveCount(0);
await expect(account.page.getByTestId("chat-turn")).toHaveCount(1);
}
} finally {
await account.dispose();
}
});
}
153 changes: 139 additions & 14 deletions crates/oah/src/chat/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ pub fn spawn(state: AppState, job: Job) {
"This answer took longer than this app allows.",
),
};
save(&state, &job, outcome, hub).await;
if let Err(error) = save(&state, &job, outcome, hub).await {
tracing::error!(turn_id, %error, "saving chat outcome failed");
}
super::hub::unregister(&turn_id);
unregister(&turn_id);
});
Expand Down Expand Up @@ -580,13 +582,17 @@ fn answer_messages(job: &Job, material: &Material) -> Value {
}

/// Saves how a run ended.
async fn save(state: &AppState, job: &Job, outcome: Outcome, hub: Arc<super::hub::TurnHub>) {
async fn save(
state: &AppState,
job: &Job,
outcome: Outcome,
hub: Arc<super::hub::TurnHub>,
) -> Result<(), sqlx::Error> {
let key = &state.config.field_key;
let turn_id = &job.turn_id;
if outcome.stopped {
hub.send(super::hub::HubEvent::State(TurnState::Cancelled));
// A stop keeps the text written so far and is final, whichever run asks.
let _ = store::end_run(
store::end_run(
&state.db,
key,
None,
Expand All @@ -595,19 +601,19 @@ async fn save(state: &AppState, job: &Job, outcome: Outcome, hub: Arc<super::hub
None,
None,
)
.await;
.await?;
hub.send(super::hub::HubEvent::State(TurnState::Cancelled));
// `done` follows the write, so a client that reloads on it reads the final turn.
hub.send(super::hub::HubEvent::Done);
return;
return Ok(());
}
if let Some((code, message)) = outcome.failure {
let name = if code == "CHAT_INTERRUPTED" {
TurnState::Interrupted
} else {
TurnState::Failed
};
hub.send(super::hub::HubEvent::State(name));
let _ = store::end_run(
store::end_run(
&state.db,
key,
None,
Expand All @@ -616,9 +622,10 @@ async fn save(state: &AppState, job: &Job, outcome: Outcome, hub: Arc<super::hub
Some(code),
Some(&message),
)
.await;
.await?;
hub.send(super::hub::HubEvent::State(name));
hub.send(super::hub::HubEvent::Done);
return;
return Ok(());
}
// The answer is checked against the units of this revision, so only real lines are cited.
let citations = verify(&outcome.answer, &job.units);
Expand All @@ -636,9 +643,9 @@ async fn save(state: &AppState, job: &Job, outcome: Outcome, hub: Arc<super::hub
partial: outcome.partial,
},
)
.await;
if !matches!(saved, Ok(true)) {
let _ = store::end_run(
.await?;
if !saved {
store::end_run(
&state.db,
key,
None,
Expand All @@ -647,9 +654,10 @@ async fn save(state: &AppState, job: &Job, outcome: Outcome, hub: Arc<super::hub
Some("CHAT_INTERRUPTED"),
Some("This answer was replaced before it finished."),
)
.await;
.await?;
}
hub.send(super::hub::HubEvent::Done);
Ok(())
}

/// A rough token count. A character of a script written without spaces counts as a token and other
Expand Down Expand Up @@ -706,6 +714,123 @@ pub fn asks_about_whole(question: &str) -> bool {
#[cfg(test)]
mod tests {
use super::*;
use std::future::Future;
use std::task::Poll;

async fn pending_turn() -> (AppState, Job, tempfile::TempDir) {
let dir = tempfile::tempdir().unwrap();
let state = AppState::new(
crate::Config::for_tests(dir.path()),
crate::db::open_memory().await.unwrap(),
);
sqlx::raw_sql(
"INSERT INTO users (id, email, created_at, updated_at) VALUES ('u', 'u@test', 0, 0);
INSERT INTO recordings (id, user_id, device_sn, plaud_file_id, filename, duration,
start_time, end_time, filesize, file_md5, storage_type, storage_path, plaud_version,
created_at, updated_at)
VALUES ('r', 'u', 'd', 'p', 'name', 0, 0, 0, 0, '', 'local', 'r', '1', 0, 0);
INSERT INTO recording_chats (id, recording_id, user_id, created_at, updated_at)
VALUES ('chat', 'r', 'u', 0, 0);
INSERT INTO recording_chat_turns (id, chat_id, recording_id, user_id, request_id, seq,
status, generation, question, revision, created_at, updated_at)
VALUES ('turn', 'chat', 'r', 'u', 'request', 1, 'running', 0, 'question', 'rev', 0, 0);",
)
.execute(&state.db)
.await
.unwrap();
let job = Job {
recording_id: "r".into(),
user_id: "u".into(),
turn_id: "turn".into(),
generation: 0,
attempt: 1,
revision: Revision {
hash: "rev".into(),
transcript_id: "tr".into(),
source: "openaudiohub".into(),
timing: super::super::revision::Timing::None,
},
question: "question".into(),
history: Vec::new(),
provider: crate::ai::Provider::default(),
effort_choice: EffortChoice::Default,
effort: EffortDecision::Default,
units: Vec::new(),
whole: false,
};
(state, job, dir)
}

#[tokio::test]
async fn terminal_events_follow_the_saved_outcome() {
for (status, code) in [
(TurnState::Failed, Some("AI_PROVIDER_ERROR")),
(TurnState::Interrupted, Some("CHAT_INTERRUPTED")),
(TurnState::Cancelled, None),
] {
let (state, job, _dir) = pending_turn().await;
let hub = Arc::new(super::super::hub::TurnHub::new(&job.turn_id));
let mut events = hub.subscribe();
let outcome = Outcome {
answer: String::new(),
partial: false,
failure: code.map(|code| (code, "failed".into())),
stopped: status == TurnState::Cancelled,
};
let connection = state.db.acquire().await.unwrap();
let saving = save(&state, &job, outcome, hub.clone());
tokio::pin!(saving);
std::future::poll_fn(|cx| {
assert!(saving.as_mut().poll(cx).is_pending());
Poll::Ready(())
})
.await;
assert!(matches!(
events.try_recv(),
Err(tokio::sync::broadcast::error::TryRecvError::Empty)
));
assert!(!hub.is_finished());
drop(connection);
saving.await.unwrap();
assert!(
matches!(events.recv().await.unwrap(), super::super::hub::HubEvent::State(saved) if saved == status)
);
let saved: (String, Option<String>) = sqlx::query_as(
"SELECT status, error_code FROM recording_chat_turns WHERE id = 'turn'",
)
.fetch_one(&state.db)
.await
.unwrap();
assert_eq!(saved, (status.as_str().into(), code.map(str::to_owned)));
assert!(matches!(
events.recv().await.unwrap(),
super::super::hub::HubEvent::Done
));
}
}

#[tokio::test]
async fn a_failed_save_does_not_announce_a_terminal_outcome() {
let (state, job, _dir) = pending_turn().await;
let hub = Arc::new(super::super::hub::TurnHub::new(&job.turn_id));
let mut events = hub.subscribe();
state.db.close().await;
assert!(
save(
&state,
&job,
Outcome::failed("AI_PROVIDER_ERROR", "failed"),
hub.clone()
)
.await
.is_err()
);
assert!(!hub.is_finished());
assert!(matches!(
events.try_recv(),
Err(tokio::sync::broadcast::error::TryRecvError::Empty)
));
}

#[test]
fn a_whole_recording_question_is_recognised() {
Expand Down
2 changes: 2 additions & 0 deletions spec/recording-chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Server-sent events for one turn. Auth: session. The response is `private, no-sto
- Live tokens and deltas stream directly through an in-process broadcast channel as they arrive from the provider, with periodic database checkpoints for reconnection resilience.
- When an upstream provider answers with a complete JSON body instead of an event stream, the content is parsed and delivered as a completed answer.
- `version` grows with each saved change. A client that loses events reconnects and reads the new snapshot instead of asking the provider again.
- The web client retries network failures and an EOF before a terminal event up to five total connection attempts, waiting 500, 1000, 2000 and 4000 milliseconds between attempts. A snapshot replaces the displayed answer before new deltas are appended. After the last failure it reports "The connection to the answer was lost." Closing the view cancels pending retries; a final snapshot, final state or `done` ends the watch.
- Terminal state events and `done` are broadcast only after the final turn is persisted, so a client reloading on either observes a final status. A persistence error is logged rather than announcing an unsaved outcome.
- Opening the stream never starts a provider call. A finished turn answers a single snapshot and `done`.
- The stream ends after `done`, after 15 minutes without a change to the turn, or when the client disconnects.

Expand Down
1 change: 1 addition & 0 deletions spec/transcription.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ Response:
```

Poll `GET /api/recordings/{id}/audio-pipeline` until the job reaches a final state. See `audio-pipeline.md`.
The web client polls active jobs every two seconds. Failed polls double the delay up to 30 seconds; a successful poll resets it to two seconds. Polling stops when the job is inactive or the view unmounts.

Errors:

Expand Down
Loading
Loading