Skip to content

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

fix(threads): await deletion queue writes during thread purge

Steven Enamakel4cb2ab0bf5d0
diff --git a/crates/openhuman-core/src/threads/store/backend.rs b/crates/openhuman-core/src/threads/store/backend.rs
index 447cb0d61a..283104b076 100644
--- a/crates/openhuman-core/src/threads/store/backend.rs
+++ b/crates/openhuman-core/src/threads/store/backend.rs
@@ -331,15 +331,27 @@ impl ConversationStore {
/// this workspace's existing best-effort queue as each header is removed.
/// Queue persistence keeps its existing IO and process-crash limitations.
pub fn purge_threads(&self) -> Result<ConversationPurgeStats, String> {
+ let ctx = self.ctx.clone();
let workspace_dir = self.workspace_dir.clone();
let stats = self.run("purge_threads", NONE, |s| async move {
- s.purge_threads_with(move |thread_id| {
- crate::memory::deletion::enqueue(
- &workspace_dir,
- crate::memory::deletion::PendingDeletion::Thread {
- thread_id: thread_id.to_owned(),
- },
- );
+ let callback_ctx = ctx.clone();
+ let callback_workspace = workspace_dir.clone();
+ s.purge_threads_with_async(move |thread_id| {
+ let ctx = callback_ctx.clone();
+ let workspace_dir = callback_workspace.clone();
+ async move {
+ // The TinyAgents callback runs inside the storage bridge.
+ // Persist off-bridge and await each header's queue write
+ // before the purge deletes the next one.
+ ctx.spawn_blocking(move || {
+ crate::memory::deletion::enqueue(
+ &workspace_dir,
+ crate::memory::deletion::PendingDeletion::Thread { thread_id },
+ );
+ })
+ .await
+ .expect("conversation purge deletion callback worker must complete");
+ }
})
.await
.map(ConversationPurgeStats::from)