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): prevent panics on string truncation with multibyte characters (#3005)
Louis Beaumontbda451a4887f
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rsindex 9003b5fa2..c60002049 100644--- a/crates/screenpipe-db/src/db.rs+++ b/crates/screenpipe-db/src/db.rs@@ -1084,7 +1084,7 @@ impl DatabaseManager {{debug!("Skipping duplicate transcription (cross-device): {:?}",- &trimmed[..trimmed.len().min(50)]+ trimmed.chars().take(50).collect::<String>());return Ok(0);}@@ -1143,7 +1143,7 @@ impl DatabaseManager {if is_duplicate {debug!("Skipping duplicate transcription (cross-device): {:?}",- &trimmed[..trimmed.len().min(50)]+ trimmed.chars().take(50).collect::<String>());}@@ -6872,7 +6872,7 @@ LIMIT ? OFFSET ?}let display = if all_text.len() > 5000 {- format!("{}… (truncated)", &all_text[..5000])+ format!("{}… (truncated)", all_text.chars().take(5000).collect::<String>())} else {all_text};@@ -7852,3 +7852,15 @@ mod tests {assert_eq!(groups[2].group_size, 1); // Maps group 2 (separate visit)}}++#[cfg(test)]+mod truncation_tests {+ #[test]+ fn test_multibyte_truncation_panic_fix() {+ let trimmed = "восхитителен, то так бы прямо тебе и сказал. Но, по-моему, ты именно что великолепен. Ни больше, ни меньше.";+ // Previous code: &trimmed[..trimmed.len().min(50)] would panic at byte 50+ // New code works safely with char boundaries:+ let safe = trimmed.chars().take(50).collect::<String>();+ assert_eq!(safe.chars().count(), 50);+ }+}