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
fix(agent): give the lead run its own error slot, not its sub-agents (#6724)
M3gA-Mindce1e017e3fed
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rsindex 57c833ab6e..427b7843e4 100644--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs@@ -22,6 +22,7 @@ use crate::agent::tinyagents::harness_tool_registration::register_turn_tools_anduse crate::agent::tinyagents::host::steering;use crate::agent::tinyagents::host::OpenHumanRunContext;use crate::agent::tinyagents::middleware::{self, TurnContextMiddleware};+use crate::agent::tinyagents::model::{ErrorSlotModel, TurnChatModel};use crate::agent::tinyagents::observability::{IterationCursor, ProviderUsageCarry, SubagentScope, ToolFailureMap, ToolNameMap,};@@ -215,6 +216,17 @@ pub(super) fn assemble_turn_harness(// caller before dispatch, not by harness assembly...} = turn_models;+ // A non-hosted run owns its registry, so its models record into the run's+ // error slot (#6724). A hosted root shares its runtime registry with its+ // sub-agents; there only the resolver's lead model records.+ let slotted = |model: TurnChatModel| -> TurnChatModel {+ if hosted_security_gate {+ model+ } else {+ Arc::new(ErrorSlotModel::new(model, error_slot.clone()))+ }+ };+ let primary = slotted(primary);capability_registry.replace_model(model, primary.clone());harness.register_model(model, primary)@@ -227,6 +239,7 @@ pub(super) fn assemble_turn_harness(// fallback/selection (02.2) chooses among the routes. `build_turn_models`// already skipped the turn's own model, so we don't shadow the default.for (name, route_model) in routes {+ let route_model = slotted(route_model);capability_registry.replace_model(name.as_str(), route_model.clone());harness.register_model(name, route_model);}diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_models.rs b/crates/openhuman-core/src/agent/tinyagents/turn_models.rsindex a72ae7f372..5f4329c5bf 100644--- a/crates/openhuman-core/src/agent/tinyagents/turn_models.rs+++ b/crates/openhuman-core/src/agent/tinyagents/turn_models.rs@@ -105,24 +105,39 @@ impl TurnModels {/// Sub-agents (depth > 0) keep resolving their pin against the tier routes —/// that is how `integrations_agent`'s `hint = "burst"` reaches `hint:burst` —/// and fall back to the primary when the pin names no built route.+///+/// Only the lead's model records into the turn's error slot (#6724). Sub-agents+/// resolve through this same resolver, possibly in parallel, so they get the+/// unwrapped models: a child's attempt must neither clear the lead's recorded+/// failure nor leave its own failure to be re-surfaced as the lead's.pub(crate) struct TurnModelResolver {+ lead: TurnChatModel,primary: TurnChatModel,routes: std::collections::HashMap<String, TurnChatModel>,}impl TurnModelResolver {pub(crate) fn from_turn_models(models: &TurnModels) -> Self {- Self::new(+ let mut resolver = Self::new(models.primary.clone(),models.routes.iter().cloned().collect(),- )+ );+ resolver.lead = Arc::new(ErrorSlotModel::new(+ models.primary.clone(),+ models.error_slot.clone(),+ ));+ resolver}pub(crate) fn new(primary: TurnChatModel,routes: std::collections::HashMap<String, TurnChatModel>,) -> Self {- Self { primary, routes }+ Self {+ lead: primary.clone(),+ primary,+ routes,+ }}}@@ -142,7 +157,7 @@ impl ModelResolver<()> for TurnModelResolver {"[models][resolver] lead keeps the turn's selected primary; definition model pin ignored");}- return Ok(self.primary.clone());+ return Ok(self.lead.clone());}Ok(pin.and_then(|name| self.routes.get(name))@@ -291,24 +306,11 @@ fn build_turn_models_crate(anyhow::Ok((primary, routes, summarizer))})?;- // The primary and every tier route share one slot: a failure on one and a- // successful fallback on another must leave the slot empty.- let error_slot: crate::agent::tinyagents::model::ModelErrorSlot =- Arc::new(std::sync::Mutex::new(None));- let primary: TurnChatModel = Arc::new(ErrorSlotModel::new(primary, error_slot.clone()));- let routes = routes- .into_iter()- .map(|(tier, route)| {- let route: TurnChatModel = Arc::new(ErrorSlotModel::new(route, error_slot.clone()));- (tier, route)- })- .collect();-Ok(TurnModels {primary,routes,summarizer,- error_slot,+ error_slot: Arc::new(std::sync::Mutex::new(None)),provider_id,context_window,native_tools,@@ -495,21 +497,16 @@ impl TurnModelSource {let native_tools = profile.tool_calling;let supports_vision = profile.modalities.image_in;let context_window = context_window.or(profile.max_input_tokens);- let error_slot: crate::agent::tinyagents::model::ModelErrorSlot =- Arc::new(std::sync::Mutex::new(None));- let primary: TurnChatModel = Arc::new(ErrorSlotModel::new(- Arc::new(- ProfileOverrideModel::new(direct.clone(), profile)- .with_request_model(model)- .with_request_temperature(temperature),- ),- error_slot.clone(),- ));+ let primary: TurnChatModel = Arc::new(+ ProfileOverrideModel::new(direct.clone(), profile)+ .with_request_model(model)+ .with_request_temperature(temperature),+ );return Ok(TurnModels {primary,routes: Vec::new(),summarizer: direct.clone(),- error_slot,+ error_slot: Arc::new(std::sync::Mutex::new(None)),provider_id,context_window,native_tools,diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_models_tests.rs b/crates/openhuman-core/src/agent/tinyagents/turn_models_tests.rsindex 2e9ef7eb3f..9eff9dd093 100644--- a/crates/openhuman-core/src/agent/tinyagents/turn_models_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/turn_models_tests.rs@@ -6,7 +6,8 @@ use tinyagents_harness::host::{ModelResolveRequest, ModelResolver};use tinyinference_llm::message::ContentBlock;use tinyinference_llm::model::{ChatModel, ModelRequest, ModelResponse};-use super::TurnModelResolver;+use super::{TurnModelResolver, TurnModels};+use crate::agent::tinyagents::TurnModelSource;/// A stub that answers with its own name so a test can tell which model the/// resolver handed back.@@ -92,3 +93,121 @@ async fn subagent_pin_without_route_falls_back_to_primary() {"openrouter/deepseek/deepseek-v4.1-flash");}++/// Streams the next scripted terminal item on each call.+struct ScriptedTerminalModel(std::sync::Mutex<Vec<tinyinference_llm::model::ModelStreamItem>>);++#[async_trait::async_trait]+impl ChatModel<()> for ScriptedTerminalModel {+ async fn invoke(+ &self,+ _state: &(),+ _request: tinyinference_llm::model::ModelRequest,+ ) -> tinyinference_llm::Result<tinyinference_llm::model::ModelResponse> {+ unreachable!("these tests stream")+ }++ async fn stream(+ &self,+ _state: &(),+ _request: tinyinference_llm::model::ModelRequest,+ ) -> tinyinference_llm::Result<tinyinference_llm::model::ModelStream> {+ let item = self.0.lock().unwrap().remove(0);+ Ok(tinyinference_llm::model::ModelStream::new(Box::pin(+ futures::stream::iter(vec![item]),+ )))+ }+}++fn provider_failure(message: &str) -> tinyinference_llm::model::ModelStreamItem {+ tinyinference_llm::model::ModelStreamItem::ProviderFailed(+ tinyinference_llm::model::ProviderError {+ provider: "OpenHuman".to_string(),+ status: Some(400),+ message: message.to_string(),+ ..Default::default()+ },+ )+}++fn completed() -> tinyinference_llm::model::ModelStreamItem {+ tinyinference_llm::model::ModelStreamItem::Completed(+ serde_json::from_value(serde_json::json!({+ "message": {"content": [], "tool_calls": []}+ }))+ .expect("minimal response"),+ )+}++async fn drain(model: &Arc<dyn ChatModel<()>>) {+ use futures::StreamExt;+ let mut stream = model+ .stream(&(), tinyinference_llm::model::ModelRequest::default())+ .await+ .unwrap();+ while stream.next().await.is_some() {}+}++fn slot_text(models: &TurnModels) -> Option<String> {+ models+ .error_slot+ .lock()+ .unwrap()+ .as_ref()+ .map(|error| error.to_string())+}++/// #6724: sub-agents resolve through the lead's resolver, possibly in+/// parallel. A child's provider failure must not become the lead's run error.+#[tokio::test]+async fn a_sub_agents_provider_failure_is_not_recorded_as_the_leads() {+ let model: Arc<dyn ChatModel<()>> =+ Arc::new(ScriptedTerminalModel(std::sync::Mutex::new(vec![+ provider_failure("CHILD_FAILURE"),+ ])));+ let models = TurnModelSource::from_model(model)+ .build("m", 0.0, None, None)+ .expect("turn models");+ let resolver = TurnModelResolver::from_turn_models(&models);+ let child = resolver+ .resolve(&ModelResolveRequest::new("researcher"))+ .await+ .unwrap();+ drain(&child).await;+ assert_eq!(+ slot_text(&models),+ None,+ "a child failure leaked into the lead's slot"+ );+}++/// #6724: a child's attempt (here a success) must not clear the failure the+/// lead already recorded.+#[tokio::test]+async fn a_sub_agents_success_does_not_clear_the_leads_recorded_failure() {+ let model: Arc<dyn ChatModel<()>> =+ Arc::new(ScriptedTerminalModel(std::sync::Mutex::new(vec![+ provider_failure("LEAD_FAILURE"),+ completed(),+ ])));+ let models = TurnModelSource::from_model(model)+ .build("m", 0.0, None, None)+ .expect("turn models");+ let resolver = TurnModelResolver::from_turn_models(&models);+ let lead = resolver+ .resolve(&ModelResolveRequest::new("orchestrator").as_team_lead())+ .await+ .unwrap();+ drain(&lead).await;+ assert!(slot_text(&models).is_some_and(|text| text.contains("LEAD_FAILURE")));++ let child = resolver+ .resolve(&ModelResolveRequest::new("researcher"))+ .await+ .unwrap();+ drain(&child).await;+ assert!(+ slot_text(&models).is_some_and(|text| text.contains("LEAD_FAILURE")),+ "a child's attempt cleared the lead's recorded failure"+ );+}