Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(meetings): release deferral before DB write so a wedged pool can't make stop a deadlock (#4525) (#4552)

Louis Beaumontf3cd3f8b8d46
diff --git a/apps/screenpipe-app-tauri/components/meeting-notes/note-view.tsx b/apps/screenpipe-app-tauri/components/meeting-notes/note-view.tsx
index e1790f481..09a7f361f 100644
--- a/apps/screenpipe-app-tauri/components/meeting-notes/note-view.tsx
+++ b/apps/screenpipe-app-tauri/components/meeting-notes/note-view.tsx
@@ -702,14 +702,27 @@ export function NoteView({
try {
const current = { title, attendees, note };
if (!sameMeetingNoteDraft(current, lastSavedRef.current)) {
- await save(current, { throwOnError: true });
+ // Best-effort: a failed note save must NEVER block the stop. If the DB
+ // write pool is wedged the save can 500, and gating stop on it leaves
+ // the meeting permanently un-stoppable (#4525). Warn and stop anyway —
+ // stopping is what releases the deferral pressure that wedged the pool.
+ try {
+ await save(current, { throwOnError: true });
+ } catch (saveErr) {
+ console.error("failed to save meeting note before stop", saveErr);
+ toast({
+ title: "couldn't save notes",
+ description: "stopping anyway — your latest edits may not be saved.",
+ variant: "destructive",
+ });
+ }
}
await onStop();
} catch (err) {
- console.error("failed to save meeting note before stop", err);
+ console.error("failed to stop meeting", err);
toast({
- title: "couldn't save notes",
- description: "try again before stopping the meeting.",
+ title: "couldn't stop meeting",
+ description: String(err),
variant: "destructive",
});
} finally {
diff --git a/crates/screenpipe-engine/src/routes/meetings.rs b/crates/screenpipe-engine/src/routes/meetings.rs
index 90da4d511..662cfe841 100644
--- a/crates/screenpipe-engine/src/routes/meetings.rs
+++ b/crates/screenpipe-engine/src/routes/meetings.rs
@@ -768,6 +768,46 @@ pub(crate) async fn stop_meeting_handler(
let now = Utc::now().format("%Y-%m-%dT%H:%M:%S%.3fZ").to_string();
+ // Release runtime state BEFORE persisting. An explicit stop is a runtime
+ // intent — the audio batch-deferral flag and detector tracking must release
+ // even when the write pool is wedged. If they only release *after* the
+ // end-write (as before), a stalled write pool turns the stop into a
+ // deadlock: audio stays in batch-deferral, the transcription/write queue
+ // never drains, so the end-write can never acquire a connection
+ // ("pool timed out while waiting for an open connection"), so the flag
+ // never clears — leaving the meeting permanently unstoppable with hundreds
+ // of transcription segments stranded (#4525). These three releases touch
+ // no DB (RwLock + AtomicBool + in-process event bus), so a stalled write
+ // pool cannot block them.
+ {
+ let mut lock = state.manual_meeting.write().await;
+ if *lock == Some(id) {
+ *lock = None;
+ }
+ }
+ if let Some(detector) = state.audio_manager.meeting_detector().await {
+ detector.set_v2_in_meeting(false);
+ }
+ // Signal the detector loop to drop tracking immediately (skip grace period).
+ // The app comes from the already-resolved status so this needs no DB read
+ // and fires even when the pool is wedged.
+ if let Err(e) = screenpipe_events::send_event(
+ "detector_stop_tracking",
+ serde_json::json!({
+ "meeting_id": id,
+ "app": status.meeting_app.clone().unwrap_or_default(),
+ }),
+ ) {
+ tracing::warn!(
+ "failed to emit detector_stop_tracking event for meeting {}: {}",
+ id,
+ e
+ );
+ }
+
+ // Persist the end best-effort. The runtime is already released above, so
+ // even if this times out (pool wedged), the deferral drains and a retry —
+ // or the detector's own grace-timeout end — completes persistence.
state
.db
.end_meeting_with_typed_text(
@@ -784,16 +824,6 @@ pub(crate) async fn stop_meeting_handler(
)
})?;
- {
- let mut lock = state.manual_meeting.write().await;
- if *lock == Some(id) {
- *lock = None;
- }
- }
- if let Some(detector) = state.audio_manager.meeting_detector().await {
- detector.set_v2_in_meeting(false);
- }
-
if let Ok(status) = resolve_meeting_status(&state).await {
emit_meeting_status_changed(&status);
}
@@ -819,18 +849,6 @@ pub(crate) async fn stop_meeting_handler(
None,
);
- // Signal detector to stop tracking this meeting immediately (skip grace period)
- if let Err(e) = screenpipe_events::send_event(
- "detector_stop_tracking",
- serde_json::json!({ "meeting_id": id, "app": &meeting.meeting_app }),
- ) {
- tracing::warn!(
- "failed to emit detector_stop_tracking event for meeting {}: {}",
- id,
- e
- );
- }
-
Ok(JsonResponse(meeting))
}