Skip to content

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

fix(orchestration): release driver task owner slots on subagent cancel

Steven Enamakelaf34612a91d2
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
index a1fd96879c..cd5b26c2b2 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
@@ -396,11 +396,16 @@ pub(crate) async fn cancel_for_thread(
));
}
}
- if let Err(error) = jobs.wait_owned(job.id.as_str(), &owner_key).await {
- failures.push(format!(
+ match jobs.wait_owned(job.id.as_str(), &owner_key).await {
+ Ok(_) => {
+ crate::agent::orchestration::completion_owners::finish_driver_task(
+ ctx, &task_id,
+ );
+ }
+ Err(error) => failures.push(format!(
"failed waiting for deleted-thread child {} to settle: {error}",
job.id
- ));
+ )),
}
}
}
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_driver_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_driver_tests.rs
index 04dfd486f0..a9ae1ff21e 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_driver_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_driver_tests.rs
@@ -525,6 +525,13 @@ async fn deleting_parent_thread_cancels_driver_child_before_discarding_completio
Some(SubAgentJobStatus::Cancelled),
"deleting a parent thread cancels its live TinyAgents child"
);
+ assert!(
+ crate::agent::orchestration::completion_owners::driver_tasks_for_thread(
+ &dispatch, &workspace, thread_id,
+ )
+ .is_empty(),
+ "settled thread deletion releases active child owner slots"
+ );
assert!(
background_completions::pending_for(&workspace, thread_id).is_empty(),
"queued child completions are discarded after cancellation"
diff --git a/crates/openhuman-core/src/agent_runs/subagent_control.rs b/crates/openhuman-core/src/agent_runs/subagent_control.rs
index 2e8265223d..c14404304b 100644
--- a/crates/openhuman-core/src/agent_runs/subagent_control.rs
+++ b/crates/openhuman-core/src/agent_runs/subagent_control.rs
@@ -229,6 +229,7 @@ async fn settle_paused_driver_cancel(
.await
.map_err(|error| format!("subagent_cancel: failed to settle paused child: {error}"))?;
if transitioned {
+ crate::agent::orchestration::completion_owners::finish_driver_task(ctx, &paused.task_id);
let parent_epoch = paused
.parent_thread_id
.as_ref()
diff --git a/crates/openhuman-core/src/agent_runs/subagent_control_tests.rs b/crates/openhuman-core/src/agent_runs/subagent_control_tests.rs
index acacce8897..582dfe8415 100644
--- a/crates/openhuman-core/src/agent_runs/subagent_control_tests.rs
+++ b/crates/openhuman-core/src/agent_runs/subagent_control_tests.rs
@@ -232,6 +232,15 @@ async fn cancelling_a_paused_driver_queues_a_failed_delivery_with_reason() {
config,
);
let ctx = DispatchCtx::new(Arc::clone(&core));
+ crate::agent::orchestration::completion_owners::note_driver_task(
+ &ctx,
+ task_id,
+ workspace_dir.clone(),
+ tinytools::WorkspaceDescriptor::new(workspace_dir.clone()),
+ parent_session.into(),
+ parent_thread.clone(),
+ )
+ .expect("paused child owner registered");
assert!(settle_paused_driver_cancel(
&ctx,
&observed,
@@ -260,6 +269,12 @@ async fn cancelling_a_paused_driver_queues_a_failed_delivery_with_reason() {
row.status,
tinyagents_orchestration::subagent::DurableSubagentStatus::Failed
);
+ assert!(crate::agent::orchestration::completion_owners::driver_tasks_for_thread(
+ &ctx,
+ &workspace_dir,
+ parent_thread.as_deref().expect("parent thread"),
+ )
+ .is_empty(), "settled paused child releases its active owner slot");
let delivery = pending_for(&workspace_dir, parent_thread.as_deref().unwrap());
assert_eq!(delivery.len(), 1);
assert_eq!(delivery[0].status, CompletionStatus::Failed);