Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(storage): preserve non-UTF-8 notification workspace keys

Steven Enamakela794c36a9d4c
diff --git a/crates/openhuman-core/src/desktop/notifications/store_documents.rs b/crates/openhuman-core/src/desktop/notifications/store_documents.rs
index 419459003d..d68983ea0e 100644
--- a/crates/openhuman-core/src/desktop/notifications/store_documents.rs
+++ b/crates/openhuman-core/src/desktop/notifications/store_documents.rs
@@ -71,6 +71,10 @@ fn collections() -> Vec<CollectionSpec> {
]
}
+fn workspace_key(path: &std::path::Path) -> String {
+ format!("path:{}", hex::encode(path.as_os_str().as_encoded_bytes()))
+}
+
/// The document store for this call: the host's configured backend or, by
/// default, the document tables in `notifications.db` (the legacy tables
/// imported on first open). `None` keeps the legacy tables.
@@ -80,7 +84,7 @@ pub(super) fn current(config: &Config) -> Result<Option<Docs>> {
// the workspace and moves with it, so it uses a fixed key: a renamed or
// restored workspace still finds its notifications.
let workspace = if crate::storage::installed().is_some() {
- config.workspace_dir.to_string_lossy().into_owned()
+ workspace_key(&config.workspace_dir)
} else {
LOCAL_WORKSPACE.to_string()
};
@@ -96,6 +100,7 @@ pub(super) fn current(config: &Config) -> Result<Option<Docs>> {
)
}
+
fn status_of(raw: Option<&str>) -> NotificationStatus {
match raw {
Some("read") => NotificationStatus::Read,
diff --git a/crates/openhuman-core/src/desktop/notifications/store_documents_tests.rs b/crates/openhuman-core/src/desktop/notifications/store_documents_tests.rs
index 5de61b2832..4ca6787f8d 100644
--- a/crates/openhuman-core/src/desktop/notifications/store_documents_tests.rs
+++ b/crates/openhuman-core/src/desktop/notifications/store_documents_tests.rs
@@ -345,3 +345,15 @@ fn dedup_ids_do_not_collide_across_fields() {
dedup_id("a", None, "bc", "d")
);
}
+
+#[cfg(unix)]
+#[test]
+fn workspace_keys_preserve_non_utf8_path_differences() {
+ use std::os::unix::ffi::OsStrExt;
+
+ let first = std::path::Path::new(std::ffi::OsStr::from_bytes(b"/tmp/workspace-\x80"));
+ let second = std::path::Path::new(std::ffi::OsStr::from_bytes(b"/tmp/workspace-\x81"));
+
+ assert_eq!(first.to_string_lossy(), second.to_string_lossy());
+ assert_ne!(workspace_key(first), workspace_key(second));
+}