The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(agent): synchronize resolved route isolation
Steven Enamakela204b55fc49d
diff --git a/crates/openhuman-core/src/agent/tinyagents/routes_tests.rs b/crates/openhuman-core/src/agent/tinyagents/routes_tests.rsindex 3396526fbd..403c6258c3 100644--- a/crates/openhuman-core/src/agent/tinyagents/routes_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/routes_tests.rs@@ -11,9 +11,18 @@ use tinyinference_llm::message::Message;use tinyinference_llm::model::{ChatModel, ModelRequest, ModelResponse, ResolvedModelRoute, RouteRecordingModel,};+use tokio::sync::Barrier;struct FailingModel;+/// A deterministic two-run gate. Each invocation waits until the test has+/// observed both contexts at the same model-call boundary, then waits again+/// for the test to release them together.+struct GatedModel {+ entered: Arc<Barrier>,+ release: Arc<Barrier>,+}+#[async_trait]impl ChatModel<()> for FailingModel {async fn invoke(@@ -27,10 +36,24 @@ impl ChatModel<()> for FailingModel {}}+#[async_trait]+impl ChatModel<()> for GatedModel {+ async fn invoke(+ &self,+ _state: &(),+ _request: ModelRequest,+ ) -> tinyinference_llm::Result<ModelResponse> {+ self.entered.wait().await;+ self.release.wait().await;+ Ok(ModelResponse::assistant("done"))+ }+}+async fn run_recorded_route(streaming: bool,fallback: bool,route: ResolvedModelRoute,+ successful_model: Arc<dyn ChatModel<()>>,) -> ResolvedModelRoute {let mut harness: AgentHarness<(), crate::agent::tinyagents::host::OpenHumanRunContext> =AgentHarness::new();@@ -47,7 +70,7 @@ async fn run_recorded_route(route.clone()};let successful = Arc::new(RouteRecordingModel::new(- Arc::new(ScriptedModel::replies(vec!["done"])),+ successful_model,served_route.clone(),));if fallback {@@ -92,12 +115,16 @@ async fn run_recorded_route(.expect("middleware records canonical response route")}+fn scripted_success() -> Arc<dyn ChatModel<()>> {+ Arc::new(ScriptedModel::replies(vec!["done"]))+}+#[tokio::test]async fn resolved_route_middleware_records_primary_routes_for_unary_and_streaming_runs() {for streaming in [false, true] {let route = ResolvedModelRoute::new("openhuman", "chat-concrete", "chat-v1");assert_eq!(- run_recorded_route(streaming, false, route.clone()).await,+ run_recorded_route(streaming, false, route.clone(), scripted_success()).await,route,"streaming={streaming}");@@ -109,7 +136,7 @@ async fn resolved_route_middleware_records_successful_fallback_for_unary_and_strfor streaming in [false, true] {let route = ResolvedModelRoute::new("anthropic", "claude-concrete", "backup");assert_eq!(- run_recorded_route(streaming, true, route.clone()).await,+ run_recorded_route(streaming, true, route.clone(), scripted_success()).await,route,"streaming={streaming}");@@ -120,10 +147,33 @@ async fn resolved_route_middleware_records_successful_fallback_for_unary_and_strasync fn resolved_route_middleware_isolates_concurrent_run_contexts() {let first = ResolvedModelRoute::new("openai", "first", "chat-v1");let second = ResolvedModelRoute::new("anthropic", "second", "reasoning-v1");- let (first_observed, second_observed) = tokio::join!(- run_recorded_route(false, false, first.clone()),- run_recorded_route(true, false, second.clone()),- );+ // The test is the third barrier participant. Both invoked model calls have+ // reached the first barrier before it can advance to the release barrier;+ // neither can return its response (and write its own route) until then.+ let entered = Arc::new(Barrier::new(3));+ let release = Arc::new(Barrier::new(3));+ let first_task = tokio::spawn(run_recorded_route(+ false,+ false,+ first.clone(),+ Arc::new(GatedModel {+ entered: entered.clone(),+ release: release.clone(),+ }),+ ));+ let second_task = tokio::spawn(run_recorded_route(+ true,+ false,+ second.clone(),+ Arc::new(GatedModel {+ entered: entered.clone(),+ release: release.clone(),+ }),+ ));+ entered.wait().await;+ release.wait().await;+ let first_observed = first_task.await.expect("first route task joins");+ let second_observed = second_task.await.expect("second route task joins");assert_eq!(first_observed, first);assert_eq!(second_observed, second);}diff --git a/scripts/ci/agent-runtime-boundary-baseline.json b/scripts/ci/agent-runtime-boundary-baseline.jsonindex efa087855e..2dc32f0d38 100644--- a/scripts/ci/agent-runtime-boundary-baseline.json+++ b/scripts/ci/agent-runtime-boundary-baseline.json@@ -2389,7 +2389,7 @@{"rule": "tinyagents-tool-calling-facade","path": "vendor/tinyagents/crates/tinyagents-harness/src/agent_loop/run_loop.rs",- "line": 998,+ "line": 999,"text": "use tinytools_agent::dialect::{DialectResponse, ToolDialect, XmlDialect};","occurrence": 1},