Skip to content

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

fix(threads): purge thread data when a thread is deleted

Steven Enamakel949034aaeb49
diff --git a/crates/openhuman-core/src/config/ops/loader/load.rs b/crates/openhuman-core/src/config/ops/loader/load.rs
index 30c7f4c2d6..2d11174bbf 100644
--- a/crates/openhuman-core/src/config/ops/loader/load.rs
+++ b/crates/openhuman-core/src/config/ops/loader/load.rs
@@ -37,16 +37,7 @@ pub async fn load_config_with_timeout() -> Result<Config, String> {
// read the task's ambient context. SaaS reads only the task's own scope, as
// `Config::load_or_init` does, so a task that lost its user scope fails
// rather than getting the operator's.
- let ambient = if crate::core::runtime::is_saas() {
- crate::core::runtime::CoreContext::scoped()
- } else {
- crate::core::runtime::CoreContext::current()
- };
- let ctx = ambient.map_or_else(
- crate::core::runtime::DispatchCtx::unbound,
- crate::core::runtime::DispatchCtx::new,
- );
- load_config_in(&ctx).await
+ load_config_in(&crate::core::runtime::DispatchCtx::ambient()).await
}
/// [`load_config_with_timeout`] for the context the caller was handed.
diff --git a/crates/openhuman-core/src/threads/ops/crud.rs b/crates/openhuman-core/src/threads/ops/crud.rs
index 8361394bb6..3827edba7a 100644
--- a/crates/openhuman-core/src/threads/ops/crud.rs
+++ b/crates/openhuman-core/src/threads/ops/crud.rs
@@ -435,6 +435,7 @@ pub async fn thread_delete(
.await
.map_err(|e| format!("load config: {e}"))?;
run_to_completion(
+ ctx,
"thread_delete",
thread_delete_inner(ctx.clone(), config, request),
)
diff --git a/crates/openhuman-core/src/threads/ops/purge.rs b/crates/openhuman-core/src/threads/ops/purge.rs
index 4e3f4d4a6c..550ea415b5 100644
--- a/crates/openhuman-core/src/threads/ops/purge.rs
+++ b/crates/openhuman-core/src/threads/ops/purge.rs
@@ -17,7 +17,7 @@ pub async fn threads_purge(
_request: EmptyRequest,
) -> Result<Outcome<ApiEnvelope<PurgeConversationThreadsResponse>>, String> {
let dir = workspace_dir().await?;
- run_to_completion("threads_purge", threads_purge_inner(ctx.clone(), dir)).await
+ run_to_completion(ctx, "threads_purge", threads_purge_inner(ctx.clone(), dir)).await
}
async fn threads_purge_inner(
diff --git a/crates/openhuman-core/src/threads/ops/support.rs b/crates/openhuman-core/src/threads/ops/support.rs
index 48289667be..1caff7e460 100644
--- a/crates/openhuman-core/src/threads/ops/support.rs
+++ b/crates/openhuman-core/src/threads/ops/support.rs
@@ -120,16 +120,20 @@ pub(crate) fn transcript_store_for(
/// to hold.
///
/// Owning the mutation *and* its cleanup in one spawned task decouples the
-/// sequence from the caller's lifetime. The ambient [`CoreContext`] is carried
-/// across explicitly: a bare `tokio::spawn` drops the `task_local` scope, and
-/// `CoreContext::current` then silently falls back to the process default —
-/// which under multi-tenant scoped dispatch is the wrong workspace.
-pub(super) async fn run_to_completion<T, F>(operation: &'static str, fut: F) -> Result<T, String>
+/// sequence from the caller's lifetime. The caller's [`CoreContext`] is moved
+/// into the task explicitly: a bare `tokio::spawn` drops the `task_local` scope,
+/// and the task would silently fall back to the process default — which under
+/// multi-tenant scoped dispatch is the wrong workspace.
+pub(super) async fn run_to_completion<T, F>(
+ dispatch: &crate::core::runtime::DispatchCtx,
+ operation: &'static str,
+ fut: F,
+) -> Result<T, String>
where
F: std::future::Future<Output = Result<T, String>> + Send + 'static,
T: Send + 'static,
{
- let ctx = CoreContext::current();
+ let ctx = dispatch.core().cloned();
tokio::spawn(async move {
match ctx {
Some(ctx) => CoreContext::scope(ctx, fut).await,