Skip to content

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

fix(subagent_sessions): resolve task ids within the authenticated owner scope

Steven Enamakel31a29c86cac0
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs
index b11ea8c169..09e09b201d 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs
@@ -150,15 +150,39 @@ impl TinySessionStore for OpenHumanTinySubagentSessionStore {
}
async fn get(&self, id: &str) -> Result<Option<TinySession>, SubagentError> {
- let row = self
+ let mut owned_rows = self
.store
.load()
.map_err(SubagentError::Persistence)?
.into_iter()
- .find(|row| row.subagent_session_id == id);
- row.filter(|row| self.is_owned(row))
- .map(|row| self.convert(row))
- .transpose()
+ // Filter the authenticated parent and thread before matching either
+ // public identifier. Raw task IDs can collide across owners, so a
+ // foreign row must never shadow a matching owned row.
+ .filter(|row| self.is_owned(row))
+ .collect::<Vec<_>>();
+
+ // Product callers historically pass the durable session ID, while
+ // accepted spawn results also expose `current_task_id`. Prefer the
+ // unambiguous session key when both happen to match.
+ let row = if let Some(index) = owned_rows
+ .iter()
+ .position(|row| row.subagent_session_id == id)
+ {
+ Some(owned_rows.remove(index))
+ } else {
+ let mut matches = owned_rows
+ .into_iter()
+ .filter(|row| row.current_task_id.as_deref() == Some(id));
+ let row = matches.next();
+ if matches.next().is_some() {
+ return Err(SubagentError::InvalidRequest(
+ "subagent task id is ambiguous within the authenticated owner scope".into(),
+ ));
+ }
+ row
+ };
+
+ row.map(|row| self.convert(row)).transpose()
}
async fn upsert_running(
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops_tests_model_resolution_tests.rs b/crates/openhuman-core/src/agent/subagent_host/ops_tests_model_resolution_tests.rs
index 52d2440308..72349a3e5e 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops_tests_model_resolution_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops_tests_model_resolution_tests.rs
@@ -7,6 +7,7 @@ use tinyagents_harness::context::{current_run_depth, with_run_depth, RunDepth};
struct BlockingSubagentCloseTool {
started: tokio::sync::mpsc::Sender<()>,
+ release: tokio::sync::oneshot::Receiver<()>,
}
#[async_trait::async_trait]
@@ -25,8 +26,8 @@ impl tinytools::Tool for BlockingSubagentCloseTool {
async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<tinytools::ToolResult> {
let _ = self.started.send(()).await;
- std::future::pending::<()>().await;
- unreachable!("driver cancellation must stop the blocked tool")
+ let _ = self.release.await;
+ Ok(tinytools::ToolResult::text("tool released after close"))
}
}
@@ -134,6 +135,7 @@ async fn closing_a_durable_driver_session_cancels_only_its_registered_child() {
let workspace = scratch.path().join("workspace");
std::fs::create_dir_all(&workspace).expect("create isolated workspace");
let (started_tx, mut started_rx) = tokio::sync::mpsc::channel(1);
+ let (release_tx, release_rx) = tokio::sync::oneshot::channel();
let provider = ScriptedProvider::new(vec![
tool_response("blocking_close_fixture", "{}"),
text_response("sibling completed"),
@@ -142,6 +144,7 @@ async fn closing_a_durable_driver_session_cancels_only_its_registered_child() {
provider.clone(),
vec![Box::new(BlockingSubagentCloseTool {
started: started_tx,
+ release: release_rx,
})],
);
parent_context.workspace_dir = workspace.clone();
@@ -243,12 +246,23 @@ async fn closing_a_durable_driver_session_cancels_only_its_registered_child() {
&wait,
&(),
tinyagents_harness::CallId::new("wait-cancelled-close-child"),
- serde_json::json!({"task_id":job_id,"timeout_secs":1}),
+ serde_json::json!({"task_id":"close-driver-task","timeout_secs":1}),
tinytools::ToolCallOptions::default(),
&parent,
)
.await
.expect("Tiny await observes close cancellation");
+ release_tx.send(()).expect("release child for cooperative settlement");
+ let wait_result = tinyagents_harness::tool::ToolDispatch::execute(
+ &wait,
+ &(),
+ tinyagents_harness::CallId::new("wait-cancelled-close-child-settled"),
+ serde_json::json!({"task_id":"close-driver-task","timeout_secs":1}),
+ tinytools::ToolCallOptions::default(),
+ &parent,
+ )
+ .await
+ .expect("Tiny await observes settled cancellation");
assert!(
wait_result.output().contains("cancelled"),
"shared Jobs await returns the cancelled terminal result: {}",