Skip to content

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

fix(memory): keep the host sync record through an empty folder walk

Shanua7a255a5f76e
diff --git a/crates/openhuman-core/src/memory/sources/hosted_sync.rs b/crates/openhuman-core/src/memory/sources/hosted_sync.rs
index f5b721cf7d..702d30f1b0 100644
--- a/crates/openhuman-core/src/memory/sources/hosted_sync.rs
+++ b/crates/openhuman-core/src/memory/sources/hosted_sync.rs
@@ -34,7 +34,8 @@
//! walk no longer finds is forgotten by that id (`ForgetSelector::Chunk`). Only
//! a folder's listing is the whole source; an item missing from a feed or a
//! repository listing may simply be past its window, so those stay. An empty
-//! listing is never read as "everything was deleted".
+//! listing is never read as "everything was deleted", and leaves the record
+//! as it was.
//!
//! Removing a source from the registry stops its syncs and keeps what it
//! synced, as on the local engine; deleting the source's memory
@@ -317,20 +318,28 @@ pub(in crate::memory::sources) async fn run(
let mut state = load_state(&path);
// An item the source no longer lists has nothing left to compare. When
// the listing is the whole source, it was removed, and its memory goes
- // too. An empty listing is not taken as "every file was deleted": that is
- // far likelier a folder that could not be walked.
- let vanished: Vec<(String, Seen)> = if removes_vanished(&entry.kind) && !listed_ids.is_empty() {
- state
- .items
- .iter()
- .filter(|(id, _)| !listed_ids.contains(*id))
- .map(|(id, seen)| (id.clone(), seen.clone()))
- .collect()
+ // too.
+ //
+ // An empty listing is neither: it is far likelier a folder that could not
+ // be walked than one whose every file was deleted, so the record is kept
+ // whole — dropping it would lose the ids that forget a file once a later
+ // walk confirms it is gone, and the forgets still waiting to be retried.
+ let forgotten = if listed_ids.is_empty() {
+ 0
} else {
- Vec::new()
+ let vanished: Vec<(String, Seen)> = if removes_vanished(&entry.kind) {
+ state
+ .items
+ .iter()
+ .filter(|(id, _)| !listed_ids.contains(*id))
+ .map(|(id, seen)| (id.clone(), seen.clone()))
+ .collect()
+ } else {
+ Vec::new()
+ };
+ state.items.retain(|id, _| listed_ids.contains(id));
+ forget_vanished(entry, sink, vanished, &mut state).await
};
- state.items.retain(|id, _| listed_ids.contains(id));
- let forgotten = forget_vanished(entry, sink, vanished, &mut state).await;
tracing::debug!(
source_id = %entry.id,
kind = entry.kind.as_str(),
diff --git a/crates/openhuman-core/src/memory/sources/hosted_sync_tests.rs b/crates/openhuman-core/src/memory/sources/hosted_sync_tests.rs
index bbdf6c703e..92485a8039 100644
--- a/crates/openhuman-core/src/memory/sources/hosted_sync_tests.rs
+++ b/crates/openhuman-core/src/memory/sources/hosted_sync_tests.rs
@@ -484,3 +484,29 @@ async fn an_empty_listing_forgets_nothing() {
run(&config, &entry, &sink).await.expect("empty");
assert!(forgotten(&sink).is_empty());
}
+
+/// An empty walk leaves the record whole, so a file that a later walk shows
+/// is gone can still be forgotten by the id the sink gave it.
+#[tokio::test]
+async fn an_empty_listing_keeps_the_record_for_a_later_walk() {
+ let dir = tempfile::tempdir().expect("tempdir");
+ let folder = folder_of(dir.path(), &["a", "b"], 40);
+ let entry = folder_entry(&folder);
+ let cfg = config(dir.path());
+ let sink = RecordingSink::default();
+ run(&cfg, &entry, &sink).await.expect("first");
+
+ let a = std::fs::read_to_string(folder.join("a.md")).expect("read a");
+ std::fs::remove_file(folder.join("a.md")).expect("hide a");
+ std::fs::remove_file(folder.join("b.md")).expect("delete b");
+ run(&cfg, &entry, &sink).await.expect("empty walk");
+ assert!(forgotten(&sink).is_empty(), "an empty walk forgets nothing");
+
+ std::fs::write(folder.join("a.md"), a).expect("a is back");
+ run(&cfg, &entry, &sink).await.expect("walk again");
+ assert_eq!(
+ forgotten(&sink),
+ ["stored:b.md"],
+ "the record survived the empty walk, so b is forgotten by its id"
+ );
+}