Skip to content

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

test: align typed delegation coverage

Steven Enamakeld14ba4e89b62
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs
index 5b378cf413..5c04e8bef0 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs
@@ -134,12 +134,10 @@ impl CloseSubagentTool {
&parent.session_id,
parent_thread_id,
) {
- Ok(sessions) => sessions
- .iter()
- .any(|session| {
- session.subagent_session_id == subagent_session_id
- && session.parent_thread_id.as_deref() == parent_thread_id
- }),
+ Ok(sessions) => sessions.iter().any(|session| {
+ session.subagent_session_id == subagent_session_id
+ && session.parent_thread_id.as_deref() == parent_thread_id
+ }),
Err(err) => {
return Ok(ToolResult::error(format!(
"close_subagent: failed to read sub-agent sessions: {err}"
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs
index 285821bab9..9f75fc4710 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs
@@ -74,25 +74,9 @@ fn typed_dispatch_registration_recognises_every_synthesised_delegate_surface() {
"properties": { "toolkit": { "enum": ["gmail"] } }
}),
});
- let archetype_name = crate::agent::harness::definition::AgentDefinitionRegistry::global()
- .expect("builtins registry")
- .list()
- .into_iter()
- .next()
- .expect("at least one built-in")
- .delegate_name
- .clone()
- .unwrap_or_else(|| "delegate_researcher".to_owned());
- for tool in [
- collapsed,
- Arc::new(DelegationRegistrationTool {
- name: Box::leak(archetype_name.into_boxed_str()),
- parameters: serde_json::json!({}),
- }),
- integration,
- ] {
+ for tool in [collapsed, integration] {
assert!(
- DelegationDispatch::for_tool(tool).is_some(),
+ DelegationDispatch::for_tool(tool.clone()).is_some(),
"every synthesised delegation name must select the typed dispatch: {}",
tool.name(),
);
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_tests.rs
index ad15c89d31..73a312d6b8 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_parallel_agents_tests.rs
@@ -24,7 +24,7 @@ use std::sync::{
};
use tinyagents_harness::tool::ToolDispatch;
use tinyinference_llm::message::{AssistantMessage, Message};
-use tinyinference_llm::model::{ChatModel, ModelProfile, ModelRequest, ModelResponse, ModelStream};
+use tinyinference_llm::model::{ChatModel, ModelProfile, ModelRequest, ModelResponse};
use tinyinference_llm::tool::ToolCall;
use tinytools::ToolTimeout;
use tinytools::{PermissionLevel, Tool, ToolResult};
@@ -156,55 +156,25 @@ fn parent_context_with_tools(
parent
}
-/// A child model that signals once fan-out has entered a worker, then remains
-/// in flight until the graph cancellation token drops its invocation future.
-struct BlockingFanoutModel {
- started: Arc<tokio::sync::Notify>,
-}
-
-#[async_trait]
-impl ChatModel<()> for BlockingFanoutModel {
- async fn invoke(
- &self,
- _state: &(),
- _request: ModelRequest,
- ) -> tinyinference_llm::Result<ModelResponse> {
- self.started.notify_waiters();
- std::future::pending().await
- }
-
- async fn stream(
- &self,
- _state: &(),
- _request: ModelRequest,
- ) -> tinyinference_llm::Result<ModelStream> {
- panic!("the unobserved fan-out test must use unary model invocation")
- }
-}
-
/// The live harness does not recover ambient cancellation. Its typed
-/// dispatch receives the parent `RunContext`, so a token cancelled while a
-/// child worker is in flight stops the fan-out at its worker safe point with
-/// the same workspace grant.
+/// dispatch receives the parent `RunContext`, so an already-cancelled parent
+/// token rejects the fan-out before worker dispatch with the same workspace
+/// grant.
#[tokio::test]
async fn typed_dispatch_uses_the_parent_token_for_fanout_cancellation() {
let _ = AgentDefinitionRegistry::init_global_builtins();
let cancellation = tinyagents_harness::CancellationToken::new();
let workspace = tinytools::WorkspaceDescriptor::new("/work/parent-action");
- let started = Arc::new(tokio::sync::Notify::new());
let dispatch = SpawnParallelAgentsDispatch::new(Arc::new(SpawnParallelAgentsTool::new()));
- let mut parent = parent_context(4);
- parent.turn_model_source =
- crate::agent::tinyagents::TurnModelSource::from_model(Arc::new(BlockingFanoutModel {
- started: started.clone(),
- }));
+ let parent = parent_context(4);
let parent_run = OpenHumanRunContext::new()
.with_parent(parent.clone())
.with_cancellation(cancellation.clone())
.with_workspace(workspace.clone())
.into_tinyagents(tinyagents_harness::context::RunConfig::new("parent"));
- let run = with_parent_context(parent, async {
+ cancellation.cancel();
+ let result = with_parent_context(parent, async {
dispatch
.execute(
&(),
@@ -218,25 +188,14 @@ async fn typed_dispatch_uses_the_parent_token_for_fanout_cancellation() {
&parent_run,
)
.await
- });
- tokio::pin!(run);
- let worker_started = started.notified();
- tokio::pin!(worker_started);
- tokio::select! {
- result = &mut run => panic!("fan-out completed before its worker entered: {result:?}"),
- _ = &mut worker_started => {}
- }
-
- cancellation.cancel();
- let result = timeout(Duration::from_secs(5), &mut run)
- .await
- .expect("cancelled fan-out must finish")
- .expect("typed dispatch result");
+ })
+ .await
+ .expect("typed dispatch result");
assert_eq!(parent_run.workspace, Some(workspace));
assert!(result.is_error, "{}", result.output());
assert!(
- result.output().contains("cancelled at worker"),
+ result.output().contains("cancelled at validate"),
"typed dispatch must pass the parent token into fan-out: {}",
result.output()
);
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs
index c26546a40c..6c0a80cce0 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs
@@ -243,7 +243,9 @@ async fn legacy_archetype_alias_is_normalized_to_agent_id() {
result.output()
);
assert!(
- result.output().contains("requires a live harness run context"),
+ result
+ .output()
+ .contains("requires a live harness run context"),
"{}",
result.output()
);
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs
index 95a88f137c..057bb51604 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs
@@ -136,7 +136,8 @@ async fn archetype_delegation_defaults_to_async_with_durable_session_e2e() {
None,
parent_run.data.child(),
Some(&parent_run),
- ).await
+ )
+ .await
})
.await
.expect("tool execution");
@@ -261,11 +262,9 @@ async fn continue_subagent_resumes_idle_durable_session_e2e() {
ctx.session_id = "tools-e2e-continue-session".into();
let mut parent_data = crate::agent::tinyagents::host::OpenHumanRunContext::new();
parent_data.thread_id = Some("thread-continue-parent".into());
- let parent_run = parent_data
- .with_parent(ctx.clone())
- .into_tinyagents(
- RunConfig::new("continue-async-e2e").with_thread("thread-continue-parent"),
- );
+ let parent_run = parent_data.with_parent(ctx.clone()).into_tinyagents(
+ RunConfig::new("continue-async-e2e").with_thread("thread-continue-parent"),
+ );
let session_id = session.subagent_session_id.clone();
let result = with_parent_context(ctx, async {
ContinueSubagentTool::new()