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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(db): re-apply benign UNIQUE in update_audio_transcription
Louis Beaumonte7d4945b6e87
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rsindex af197ac53..8809d659c 100644--- a/crates/screenpipe-db/src/db.rs+++ b/crates/screenpipe-db/src/db.rs@@ -111,6 +111,16 @@ impl ImmediateTx {}}+/// True when `e` is a UNIQUE-constraint violation from SQLite. Used by+/// callers that want to treat benign duplicates as a no-op instead of+/// letting the ImmediateTx drop uncommitted (which logs a warning).+fn is_unique_violation(e: &sqlx::Error) -> bool {+ if let sqlx::Error::Database(db_err) = e {+ return db_err.is_unique_violation();+ }+ false+}+impl Drop for ImmediateTx {fn drop(&mut self) {if !self.committed {@@ -1224,19 +1234,34 @@ impl DatabaseManager {let mut tx = self.begin_immediate_with_retry().await?;// Insert the full transcription- let affected = sqlx::query(+ let result = sqlx::query("UPDATE audio_transcriptions SET transcription = ?1, text_length = ?2 WHERE audio_chunk_id = ?3",).bind(trimmed).bind(text_length).bind(audio_chunk_id).execute(&mut **tx.conn())- .await?- .rows_affected();+ .await;- // Commit the transaction for the full transcription- tx.commit().await?;- Ok(affected as i64)+ match result {+ Ok(r) => {+ tx.commit().await?;+ Ok(r.rows_affected() as i64)+ }+ // UNIQUE(audio_chunk_id, transcription) is enforced by+ // idx_audio_transcription_chunk_text. When overlap cleanup re-runs+ // the UPDATE with text identical to an existing row for this chunk+ // (multi-row chunks from VAD overlap), the composite collides+ // benignly — caller in transcription_result.rs already treats this+ // as a no-op. Commit an empty tx so Drop doesn't fire the noisy+ // "ImmediateTx dropped without commit" warning. Originally fixed+ // in 1d4f75669; reverted by perf refactor e35be21f9; restored here.+ Err(e) if is_unique_violation(&e) => {+ tx.commit().await?;+ Ok(0)+ }+ Err(e) => Err(e),+ }}/// Replace all transcription rows for an audio chunk with a single new transcription.