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(meetings): never drop live transcript segments on a coverage-window miss (#3918)
Louis Beaumontdf61b293502f
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rsindex 9b955b46f..ea39a52dc 100644--- a/crates/screenpipe-db/src/db.rs+++ b/crates/screenpipe-db/src/db.rs@@ -9180,7 +9180,7 @@ LIMIT ? OFFSET ?SELECT 1 FROM meeting_transcript_segments mtsWHERE mts.meeting_id = ?2AND ABS(julianday(mts.captured_at) - julianday(audio_chunks.timestamp)) <= ?3- AND instr(audio_chunks.file_path, mts.device_name) > 0+ AND instr(lower(audio_chunks.file_path), lower(mts.device_name)) > 0AND instr(lower(audio_chunks.file_path), '(' || lower(mts.device_type) || ')') > 0)"#,@@ -9210,8 +9210,11 @@ LIMIT ? OFFSET ?/// - `speaker_id` is left NULL — live diarization stores a free-text/// `speaker_name`, not a `speakers.id`; the Meeting view still shows the live/// row's speaker (it reads `meeting_transcript_segments` directly).- /// - Segments with no covering chunk within `coverage_window_secs` are skipped- /// (the timeline still surfaces them live via `find_video_chunks`).+ /// - A segment whose nearest same-device chunk is OUTSIDE `coverage_window_secs`+ /// is still mirrored onto that chunk (carrying the segment's real timestamp)+ /// rather than dropped, so live transcript text is never lost. Only a segment+ /// whose device has NO chunk at all is skipped (the timeline still surfaces it+ /// live via `find_video_chunks`)./// - `timestamp` is bound as a `DateTime<Utc>` so its on-disk format matches/// every other `audio_transcriptions` row (range queries stay consistent).pub async fn mirror_live_meeting_to_audio_transcriptions(@@ -9297,9 +9300,16 @@ LIMIT ? OFFSET ?// Match the SAME physical device's chunk so an input (mic) segment can't// inherit a remote speaker from a System Audio (output) chunk, and vice// versa. The device string is sanitized the same way the recorder names- // files (only '/' and '\\' replaced). If no same-device chunk exists,- // skip the mirror and leave the chunk pending for backfill rather than- // corrupting source attribution.+ // files (only '/' and '\\' replaced). Prefer the nearest same-device chunk+ // WITHIN the window; if none is in the window (the live provider can+ // finalize a turn seconds after the audio, drifting captured_at past the+ // chunk timestamp, and chunks longer than 2x the window leave segments with+ // no in-window chunk) fall back to the nearest same-device chunk regardless+ // of distance rather than silently DROPPING the segment. Losing the+ // transcript text is worse than a small playback offset, and the stored+ // `timestamp` is the segment's real captured_at so search/timeline stay+ // correct. Only skip when the device has NO chunk at all (leave it pending+ // for backfill). Device attribution stays strict: never a different device.let device_key = format!("{} ({})",s.device_name,@@ -9309,8 +9319,14 @@ LIMIT ? OFFSET ?.to_lowercase();let pick = chunks.iter()- .filter(|c| (c.1 - seg_ms).abs() <= window_ms && c.2.contains(device_key.as_str()))- .min_by_key(|c| (c.1 - seg_ms).abs());+ .filter(|c| c.2.contains(device_key.as_str()))+ .min_by_key(|c| {+ // In-window chunks (false) sort before out-of-window (true); the+ // nearest wins within each group. So an in-window chunk is always+ // preferred, but a far same-device chunk still beats dropping.+ let dt = (c.1 - seg_ms).abs();+ (dt > window_ms, dt)+ });let Some(chunk) = pick else {continue;};diff --git a/crates/screenpipe-db/tests/live_coverage_marker_test.rs b/crates/screenpipe-db/tests/live_coverage_marker_test.rsindex c6f168e7c..1b47805f2 100644--- a/crates/screenpipe-db/tests/live_coverage_marker_test.rs+++ b/crates/screenpipe-db/tests/live_coverage_marker_test.rs@@ -244,4 +244,43 @@ mod tests {assert_eq!(second, 0);assert_eq!(chunk_status(&db, chunk).await, "transcribed");}++ /// The device-name match between a live segment and a chunk's file path must be+ /// case-insensitive: the chunk file path and the segment's stored device name+ /// can differ in case. Pre-fix this was a case-sensitive `instr`, so a casing+ /// difference left the meeting's chunk pending — re-transcribed by the batch+ /// reconciler and inconsistent with the mirror, which already matched+ /// case-insensitively.+ #[tokio::test]+ async fn matches_device_name_case_insensitively() {+ let db = setup_test_db().await;+ let start = Utc::now() - Duration::minutes(10);+ let end = Utc::now();+ let meeting_id = insert_meeting(&db, &start.to_rfc3339(), Some(&end.to_rfc3339())).await;++ // Chunk file path stores the device lowercased...+ let chunk_ts = start + Duration::minutes(5);+ let chunk = db+ .insert_audio_chunk("system audio (output)_x.mp4", Some(chunk_ts))+ .await+ .unwrap();++ // ...while the live segment's device name is differently cased.+ let live_ts = chunk_ts + Duration::seconds(2);+ insert_live_segment_for_device(+ &db,+ meeting_id,+ &live_ts.to_rfc3339(),+ "System Audio",+ "output",+ )+ .await;++ let updated = db+ .mark_chunks_covered_by_live(meeting_id, 15.0)+ .await+ .unwrap();+ assert_eq!(updated, 1, "case-different device name must still match");+ assert_eq!(chunk_status(&db, chunk).await, "transcribed");+ }}diff --git a/crates/screenpipe-db/tests/timeline_live_meeting_test.rs b/crates/screenpipe-db/tests/timeline_live_meeting_test.rsindex 8bebe51b0..533e7bc74 100644--- a/crates/screenpipe-db/tests/timeline_live_meeting_test.rs+++ b/crates/screenpipe-db/tests/timeline_live_meeting_test.rs@@ -228,24 +228,30 @@ mod timeline_live_meeting_tests {assert_eq!(again, 0, "re-mirroring should insert nothing");}- /// A live segment with no covering chunk within the window is skipped (the- /// timeline still surfaces it live via the read-side fallback).+ /// A live segment whose nearest same-device chunk is OUTSIDE the window is+ /// mirrored onto that chunk (carrying its own timestamp) instead of being+ /// silently dropped — losing live transcript text is worse than a small+ /// playback offset. This is the "recorded both sides, then the other side+ /// stopped surfacing in the transcript" class.#[tokio::test]- async fn test_mirror_skips_segment_with_no_covering_chunk() {+ async fn test_mirror_uses_far_same_device_chunk_instead_of_dropping() {let db = setup_test_db().await;let base = Utc::now();- // Only chunk is 5 minutes away — outside the 15s coverage window.- db.insert_audio_chunk(- "System Audio (output)_far.mp4",- Some(base - Duration::minutes(5)),- )- .await- .unwrap();+ // One output chunk at T=0. Real meetings capture contiguous chunks; this+ // models a live final landing far from the nearest chunk timestamp — a+ // long chunk, a capture gap, or the provider finalizing a turn seconds+ // after the audio.+ db.insert_audio_chunk("System Audio (output)_c.mp4", Some(base))+ .await+ .unwrap();let meeting_id = db.insert_meeting("zoom.us", "ui_scan", None, None).await.unwrap();++ // An in-window segment at T=0 anchors the candidate-chunk fetch span (the+ // fetch is bounded by min/max segment time ±window) and matches normally.db.insert_meeting_transcript_segment(meeting_id,"screenpipe-cloud",@@ -254,20 +260,47 @@ mod timeline_live_meeting_tests {"System Audio","output",None,- "no chunk nearby",+ "near turn",base,).await.unwrap();+ // The segment under test: +40s from the only output chunk, OUTSIDE the 15s+ // window. Pre-fix it was silently dropped from every post-call surface;+ // now it falls back to the nearest same-device chunk so the audience turn+ // survives (with its own timestamp).+ db.insert_meeting_transcript_segment(+ meeting_id,+ "screenpipe-cloud",+ None,+ "deepgram:0:1",+ "System Audio",+ "output",+ None,+ "audience turn out of window",+ base + Duration::seconds(40),+ )+ .await+ .unwrap();+let inserted = db.mirror_live_meeting_to_audio_transcriptions(meeting_id, 15.0).await.unwrap();assert_eq!(- inserted, 0,- "no covering chunk within window → nothing mirrored"+ inserted, 2,+ "both the in-window and the far same-device segment must be mirrored, not dropped");++ let count: i64 = sqlx::query_scalar(+ "SELECT COUNT(*) FROM audio_transcriptions \+ WHERE transcription = 'audience turn out of window' AND is_input_device = 0",+ )+ .fetch_one(&db.pool)+ .await+ .unwrap();+ assert_eq!(count, 1, "the far audience turn was preserved, not dropped");}/// A live output/system segment must not be mirrored onto a nearby mic/input