diff --git a/crates/tinymemory-tools/src/recall/gather.rs b/crates/tinymemory-tools/src/recall/gather.rs index 6883bf6e..c8bc9cd9 100644 --- a/crates/tinymemory-tools/src/recall/gather.rs +++ b/crates/tinymemory-tools/src/recall/gather.rs @@ -236,7 +236,7 @@ async fn with_listed_beliefs( engine: &dyn MemoryEngine, section: &ScopeSection, want: usize, - keep: &dyn Fn(&Hit) -> bool, + keep: &(dyn Fn(&Hit) -> bool + Sync), ) -> tinymemory_api::Result<(Vec, Vec)> { if !reads_learnings(section) { return Ok(( @@ -324,7 +324,7 @@ async fn fetch( query: &str, limit: usize, beliefs: usize, - keep: &dyn Fn(&Hit) -> bool, + keep: &(dyn Fn(&Hit) -> bool + Sync), ) -> tinymemory_api::Result<(Vec, Vec)> { let Some(mode) = preferred_mode(engine) else { return Ok((latest(engine, filter, limit, keep).await?, Vec::new())); @@ -347,7 +347,7 @@ async fn latest( engine: &dyn MemoryEngine, filter: &MetaFilter, limit: usize, - keep: &dyn Fn(&Hit) -> bool, + keep: &(dyn Fn(&Hit) -> bool + Sync), ) -> tinymemory_api::Result> { let mut all: Vec = Vec::new(); let mut cursor: Option = None; diff --git a/crates/tinymemory-tools/src/recall/mod_tests.rs b/crates/tinymemory-tools/src/recall/mod_tests.rs index 4da9295f..2ffbfd02 100644 --- a/crates/tinymemory-tools/src/recall/mod_tests.rs +++ b/crates/tinymemory-tools/src/recall/mod_tests.rs @@ -615,3 +615,19 @@ async fn a_belief_the_filter_rules_out_is_left_out() { .unwrap(); assert!(!pack.markdown.contains("pnpm"), "{}", pack.markdown); } + +/// Hosts run recall on multi-threaded runtimes (a spawned pre-turn, an +/// `async_trait` method), which need its future to be `Send`. Every +/// reference it holds across an `.await` must therefore be `Sync`, +/// including the `keep` predicate the gathering passes down. +#[test] +fn a_recall_future_can_cross_threads() { + fn send(_: &T) {} + let engine = ReferenceEngine::new(); + let request = HolisticRecall::new( + Some("refunds".into()), + vec![ScopeSection::fetch("Docs", docs(), 5)], + ); + let future = holistic_recall(&engine, &request); + send(&future); +}