Skip to content

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

fix(threads): purge subagent sessions when a thread is deleted

Steven Enamakel048d1c7f1f2c
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_control.rs b/crates/openhuman-core/src/agent/orchestration/subagent_control.rs
index 345af253d0..124dc2500c 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_control.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_control.rs
@@ -101,7 +101,7 @@ fn schema_for(function: &str) -> ControllerSchema {
}
}
-fn handle_subagent_cancel(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+fn handle_subagent_cancel(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let cid = new_correlation_id();
let task_id = require_str(&params, "taskId")?;
@@ -114,7 +114,7 @@ fn handle_subagent_cancel(_ctx: DispatchCtx, params: Map<String, Value>) -> Cont
// `outcome` is set only when nothing was cancelled: how the run ended
// if the registry still knew it, else "unknown" (never registered, or
// already swept). The card settles on it instead of assuming success.
- let (cancelled, outcome) = match running_subagents::cancel_by_task(&task_id) {
+ let (cancelled, outcome) = match running_subagents::cancel_by_task(&ctx, &task_id) {
// Finished before the click landed (it stays registered until the
// terminal sweep). Its outcome is already recorded and delivered;
// announcing a cancellation would overwrite a completed session
@@ -183,7 +183,7 @@ fn handle_subagent_cancel(_ctx: DispatchCtx, params: Map<String, Value>) -> Cont
})
}
-fn handle_subagent_steer(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+fn handle_subagent_steer(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let cid = new_correlation_id();
let task_id = require_str(&params, "taskId")?;
@@ -198,7 +198,7 @@ fn handle_subagent_steer(_ctx: DispatchCtx, params: Map<String, Value>) -> Contr
message.chars().count()
);
- match running_subagents::steer_control(&task_id, message, lane).await {
+ match running_subagents::steer_control(&ctx, &task_id, message, lane).await {
Ok(()) => {
log::debug!(
target: "subagent_control_rpc",
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 1f38e95f37..f70bdbb70b 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -461,6 +461,7 @@ impl OpenHumanTurnPrelude {
};
if let Some(block) =
crate::agent::orchestration::running_subagents::active_subagents_context_block(
+ &self.dispatch_ctx(),
&self.event_session_id,
&self.workspace_dir,
&turn_fleet,
diff --git a/crates/openhuman-core/src/threads/ops/crud.rs b/crates/openhuman-core/src/threads/ops/crud.rs
index 04db99beeb..bffb8bfef5 100644
--- a/crates/openhuman-core/src/threads/ops/crud.rs
+++ b/crates/openhuman-core/src/threads/ops/crud.rs
@@ -466,7 +466,7 @@ async fn thread_delete_inner(
// queued for delivery. Both target a thread that's being deleted, so there's
// nowhere left to deliver to — abort + cleanup is the whole behavior.
let cancelled =
- crate::agent::orchestration::running_subagents::cancel_for_thread(&request.thread_id);
+ crate::agent::orchestration::running_subagents::cancel_for_thread(&ctx, &request.thread_id);
let discarded = crate::agent::orchestration::background_completions::discard_for_thread(
&dir,
&request.thread_id,
diff --git a/crates/openhuman-core/src/threads/ops/purge.rs b/crates/openhuman-core/src/threads/ops/purge.rs
index c10e8b4307..0b7a1f0db3 100644
--- a/crates/openhuman-core/src/threads/ops/purge.rs
+++ b/crates/openhuman-core/src/threads/ops/purge.rs
@@ -32,7 +32,7 @@ async fn threads_purge_inner(
// wins the cooperative-abort race (records after the wipe) is still dropped
// by `record_completion` rather than delivered into a purged thread.
use crate::agent::orchestration::{background_completions, running_subagents};
- let cancelled_threads = running_subagents::cancel_all();
+ let cancelled_threads = running_subagents::cancel_all(&ctx);
let mut discarded = 0;
for thread_id in &cancelled_threads {
discarded += background_completions::discard_for_thread(&dir, thread_id);