The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(threads): close thread admission before purging
Steven Enamakeldcc206e2de5e
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_thread_delete_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_thread_delete_tests.rsindex 2eb6c9f861..f0b4674e93 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_thread_delete_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_thread_delete_tests.rs@@ -286,9 +286,13 @@ async fn thread_creation_cannot_enter_the_snapshot_to_purge_window() {personality_id: None,working_dir: None,};- blocking::ensure_thread(ctx.clone(), workspace.clone(), make_thread("purge-race-existing"))- .await- .expect("seed a thread for the purge snapshot");+ blocking::ensure_thread(+ ctx.clone(),+ workspace.clone(),+ make_thread("purge-race-existing"),+ )+ .await+ .expect("seed a thread for the purge snapshot");let (snapshot_tx, snapshot_rx) = tokio::sync::oneshot::channel();let (release_tx, release_rx) = tokio::sync::oneshot::channel();@@ -335,7 +339,10 @@ async fn thread_creation_cannot_enter_the_snapshot_to_purge_window() {.expect("thread_upsert task joins");let _ = release_tx.send(());- purge.await.expect("purge task joins").expect("purge succeeds");+ purge+ .await+ .expect("purge task joins")+ .expect("purge succeeds");assert!(direct_result.is_err(),diff --git a/crates/openhuman-core/src/threads/ops/purge.rs b/crates/openhuman-core/src/threads/ops/purge.rsindex 08b176ea17..e81115aa12 100644--- a/crates/openhuman-core/src/threads/ops/purge.rs+++ b/crates/openhuman-core/src/threads/ops/purge.rs@@ -36,6 +36,13 @@ whereF: FnOnce() -> Fut + Send,Fut: std::future::Future<Output = ()> + Send,{+ let admission_workspace = dir.clone();+ let _admission = tokio::task::spawn_blocking(move || {+ crate::threads::store::backend::begin_thread_purge(&admission_workspace)+ })+ .await+ .map_err(|error| format!("failed to close thread admission for purge: {error}"))?;+// Capture and fence the parents before deleting their rows. The owner// index is keyed by thread, and the permanent fence prevents another child// from being admitted while the purge settles the jobs already running.diff --git a/crates/openhuman-core/src/threads/store/backend.rs b/crates/openhuman-core/src/threads/store/backend.rsindex 9acd71909c..b0eefc7e4e 100644--- a/crates/openhuman-core/src/threads/store/backend.rs+++ b/crates/openhuman-core/src/threads/store/backend.rs@@ -15,9 +15,8 @@//! request paths already go through [`super::blocking`], which keeps that off//! the async workers.-use std::path::{Path, PathBuf};use std::collections::HashMap;-use std::path::PathBuf;+use std::path::{Path, PathBuf};use std::sync::{Arc, Condvar, Mutex, OnceLock, Weak};use super::ConversationPurgeStats;@@ -106,11 +105,7 @@ impl Drop for ThreadPurgeGuard {/// Closes workspace thread admission and waits for in-flight creates to settle.///-/// # Errors-///-/// This currently has no recoverable error path; the result type keeps the-/// purge caller's setup failures uniform with other storage admission errors.-pub(crate) fn begin_thread_purge(workspace_dir: &Path) -> Result<ThreadPurgeGuard, String> {+pub(crate) fn begin_thread_purge(workspace_dir: &Path) -> ThreadPurgeGuard {let admission = thread_admission(workspace_dir);let mut state = admission.state@@ -130,7 +125,7 @@ pub(crate) fn begin_thread_purge(workspace_dir: &Path) -> Result<ThreadPurgeGuar.unwrap_or_else(|error| error.into_inner());}drop(state);- Ok(ThreadPurgeGuard(admission))+ ThreadPurgeGuard(admission)}const DOMAIN: &str = "threads::store";