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(config): allow string or struct for VocabEntry deserialization (#4596)

sentry[bot]3b66bcabe01a
diff --git a/crates/screenpipe-config/src/recording.rs b/crates/screenpipe-config/src/recording.rs
index 71c13eced..e0255d97f 100644
--- a/crates/screenpipe-config/src/recording.rs
+++ b/crates/screenpipe-config/src/recording.rs
@@ -7,7 +7,7 @@
use serde::{Deserialize, Serialize};
/// Custom vocabulary entry for transcription biasing and word replacement.
-#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
+#[derive(Clone, Debug, Default, Serialize, PartialEq)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
pub struct VocabEntry {
/// The word or phrase to bias toward during transcription.
@@ -17,6 +17,43 @@ pub struct VocabEntry {
pub replace_with: Option<String>,
}
+// Backwards compatibility: legacy `store.bin` files stored `vocabularyWords` as a
+// list of plain strings (see `RecordingSettings::vocabulary`). Accept both a bare
+// string (mapped to `VocabEntry { word, replace_with: None }`) and the struct form
+// so existing settings deserialize without migration.
+impl<'de> Deserialize<'de> for VocabEntry {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: serde::Deserializer<'de>,
+ {
+ // Helper mirrors the struct form so its field names/defaults stay in sync.
+ #[derive(Deserialize)]
+ struct VocabEntryStruct {
+ word: String,
+ #[serde(default)]
+ replace_with: Option<String>,
+ }
+
+ #[derive(Deserialize)]
+ #[serde(untagged)]
+ enum StringOrStruct {
+ String(String),
+ Struct(VocabEntryStruct),
+ }
+
+ Ok(match StringOrStruct::deserialize(deserializer)? {
+ StringOrStruct::String(word) => VocabEntry {
+ word,
+ replace_with: None,
+ },
+ StringOrStruct::Struct(s) => VocabEntry {
+ word: s.word,
+ replace_with: s.replace_with,
+ },
+ })
+ }
+}
+
/// A single schedule rule: a day-of-week + time range + what to record.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[cfg_attr(feature = "specta", derive(specta::Type))]
@@ -934,6 +971,23 @@ mod tests {
assert_eq!(s.audio_chunk_duration, 0);
}
+ #[test]
+ fn vocab_entry_accepts_bare_string_and_struct_mixed() {
+ // Regression for SCREENPIPE-APP-DN: legacy store.bin stored vocabularyWords
+ // as bare strings; the current app stores structs. A mixed list (with a
+ // non-ASCII bare string, the exact crashing input) must all deserialize
+ // instead of failing the whole RecordingSettings object.
+ let json = r#"{"vocabularyWords": ["せばんぬ", {"word": "screenpipe"}, {"word": "foo", "replace_with": "bar"}]}"#;
+ let s: RecordingSettings = serde_json::from_str(json).unwrap();
+ assert_eq!(s.vocabulary.len(), 3);
+ assert_eq!(s.vocabulary[0].word, "せばんぬ");
+ assert_eq!(s.vocabulary[0].replace_with, None);
+ assert_eq!(s.vocabulary[1].word, "screenpipe");
+ assert_eq!(s.vocabulary[1].replace_with, None);
+ assert_eq!(s.vocabulary[2].word, "foo");
+ assert_eq!(s.vocabulary[2].replace_with.as_deref(), Some("bar"));
+ }
+
#[test]
fn round_trips_through_toml() {
let settings = RecordingSettings::default();