Skip to content

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

fix(orchestration): release sub-agent owner slot on completion

Steven Enamakel2b66dedd588c
diff --git a/crates/openhuman-core/src/agent/orchestration/completion_owners.rs b/crates/openhuman-core/src/agent/orchestration/completion_owners.rs
index 59cae5bd4a..b23da1487e 100644
--- a/crates/openhuman-core/src/agent/orchestration/completion_owners.rs
+++ b/crates/openhuman-core/src/agent/orchestration/completion_owners.rs
@@ -103,7 +103,9 @@ fn remember_active_driver_task(
capacity: usize,
) -> Result<(), String> {
if !st.driver_tasks.contains_key(&key) && st.driver_tasks.len() >= capacity {
- return Err(format!("active sub-agent owner capacity ({capacity}) is full"));
+ return Err(format!(
+ "active sub-agent owner capacity ({capacity}) is full"
+ ));
}
st.terminal_driver_tasks.remove(&key);
st.terminal_driver_task_order
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_completion.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_completion.rs
index 4cceb6e746..d6f91270d3 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_completion.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_completion.rs
@@ -127,7 +127,14 @@ pub(super) fn make_completion(
let background_store = background_store.clone();
let background_subagent_session_id = background_subagent_session_id.clone();
let background_parent_thread_id = background_parent_thread_id.clone();
+ let owner_dispatch = background_dispatch.clone();
+ let owner_task_id = background_task_id.clone();
Box::pin(async move {
+ let keep_owner_active = matches!(
+ &result,
+ Ok(outcome)
+ if matches!(&outcome.status, SubagentRunStatus::AwaitingUser { .. })
+ );
let finish = async move {
let mut abort_report =
AbortReport::arm(progress_sink, &background_agent_id, &background_task_id);
@@ -470,6 +477,12 @@ pub(super) fn make_completion(
}
None => finish.await,
}
+ if !keep_owner_active {
+ crate::agent::orchestration::completion_owners::finish_driver_task(
+ &owner_dispatch,
+ &owner_task_id,
+ );
+ }
})
}
}
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs
index f6e8a8c09c..862a4e448c 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs
@@ -603,14 +603,32 @@ impl SpawnSubagentTool {
thread_id,
);
}
- crate::agent::orchestration::completion_owners::note_driver_task(
+ if let Err(error) = crate::agent::orchestration::completion_owners::note_driver_task(
&dispatch,
&task_id,
parent.workspace_dir.clone(),
task_workspace.clone(),
parent_session.clone(),
parent_thread_id.clone(),
- );
+ ) {
+ if let Err(store_error) = driver_store
+ .mark_failed(
+ &durable_session.subagent_session_id,
+ &task_id,
+ error.clone(),
+ )
+ .await
+ {
+ log::warn!(
+ "[subagent_reuse] mark_failed after owner admission refusal failed subagent_session_id={} task_id={} error={store_error}",
+ durable_session.subagent_session_id,
+ task_id
+ );
+ }
+ return Ok(ToolResult::error(format!(
+ "spawn_subagent: registration refused: {error}"
+ )));
+ }
crate::agent::orchestration::subagent_events::publish_subagent_spawned(
parent_session.clone(),
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 f55a095929..bddb0c9ed8 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
@@ -632,7 +632,8 @@ async fn thread_delete_keeps_completions_when_driver_task_scope_cannot_be_resolv
workspace_descriptor,
parent_session.into(),
Some(thread_id.into()),
- );
+ )
+ .expect("record active owner for fail-closed regression");
let result = crate::threads::ops::thread_delete(
&dispatch,