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(flows): resolve flow definitions through the dispatch catalog scope
Steven Enamakeleeafe1249649
diff --git a/crates/openhuman-core/src/flows/caps_host/binding_tests.rs b/crates/openhuman-core/src/flows/caps_host/binding_tests.rsindex 0018b15315..0371ea567e 100644--- a/crates/openhuman-core/src/flows/caps_host/binding_tests.rs+++ b/crates/openhuman-core/src/flows/caps_host/binding_tests.rs@@ -1,6 +1,6 @@use super::*;-use super::binding::CapsHostBinding;+use super::binding::{AgentRunRegistry, CapsHostBinding};use crate::config::Config;use crate::core::runtime::{ComponentSet, CoreContext, DispatchCtx, DomainSet};use std::sync::Arc;@@ -25,7 +25,7 @@ fn binding(ctx: DispatchCtx, temp: &TempDir) -> CapsHostBinding {)),approval: Default::default(),cancellation: tokio_util::sync::CancellationToken::new(),- agent_runs: tokio::sync::Mutex::new(std::collections::HashMap::new()),+ agent_runs: tokio::sync::Mutex::new(AgentRunRegistry::default()),}}diff --git a/crates/openhuman-core/src/flows/caps_host/service_agent.rs b/crates/openhuman-core/src/flows/caps_host/service_agent.rsindex cb16ea5e83..01c9b5ee29 100644--- a/crates/openhuman-core/src/flows/caps_host/service_agent.rs+++ b/crates/openhuman-core/src/flows/caps_host/service_agent.rs@@ -83,7 +83,7 @@ pub(crate) async fn run_agent(});let result = tokio::select! {biased;- _ = cancellation.cancelled() => Err("workflow run was cancelled".to_owned()),+ _ = cancellation.cancelled() => Err("agent run was cancelled".to_owned()),result = turn => result.map_err(|error| error.to_string()),};let _ = progress.await;diff --git a/crates/openhuman-core/src/flows/caps_host/service_tests.rs b/crates/openhuman-core/src/flows/caps_host/service_tests.rsnew file mode 100644index 0000000000..fb0fa35578--- /dev/null+++ b/crates/openhuman-core/src/flows/caps_host/service_tests.rs@@ -0,0 +1,67 @@+use super::*;++use super::super::binding::AgentRunRegistry;++fn state() -> Arc<tokio::sync::Mutex<super::super::agent::AgentRunState>> {+ Arc::new(tokio::sync::Mutex::new(+ super::super::agent::AgentRunState::default(),+ ))+}++#[tokio::test]+async fn cancel_before_run_admission_tombstones_id_and_prevents_task_start() {+ let mut registry = AgentRunRegistry::default();+ registry.cancel("request-1".into());+ let cancellation = tokio_util::sync::CancellationToken::new();++ let admission = registry+ .admit("request-1".into(), state(), cancellation.clone())+ .unwrap();++ assert!(!admission.start_task);+ assert!(admission.cancelled_before_admission);+ assert!(cancellation.is_cancelled());+}++#[tokio::test]+async fn cancel_after_run_admission_cancels_the_existing_invocation() {+ let mut registry = AgentRunRegistry::default();+ let cancellation = tokio_util::sync::CancellationToken::new();+ let admission = registry+ .admit("request-1".into(), state(), cancellation.clone())+ .unwrap();+ assert!(admission.start_task);++ registry.cancel("request-1".into());++ assert!(cancellation.is_cancelled());+}++#[tokio::test]+async fn duplicate_agent_run_request_returns_the_original_handle_without_restarting() {+ let mut registry = AgentRunRegistry::default();+ let first_state = state();+ let first = registry+ .admit(+ "request-1".into(),+ Arc::clone(&first_state),+ tokio_util::sync::CancellationToken::new(),+ )+ .unwrap();++ let duplicate = registry+ .admit("request-1".into(), state(), tokio_util::sync::CancellationToken::new())+ .unwrap();++ assert!(first.start_task);+ assert!(!duplicate.start_task);+ assert_eq!(duplicate.entry.handle, first.entry.handle);+ assert!(Arc::ptr_eq(&duplicate.entry.state, &first_state));+}++#[test]+fn malformed_agent_request_ids_are_rejected() {+ assert!(!valid_agent_request_id(""));+ assert!(!valid_agent_request_id(&"x".repeat(129)));+ assert!(valid_agent_request_id("client-request-1"));+}diff --git a/crates/openhuman-core/src/flows/ops/run.rs b/crates/openhuman-core/src/flows/ops/run.rsindex 496ac5a1bd..ede536989a 100644--- a/crates/openhuman-core/src/flows/ops/run.rs+++ b/crates/openhuman-core/src/flows/ops/run.rs@@ -116,9 +116,22 @@ pub(super) async fn prepare_flow_run(flow_id: &str,_inputs: &serde_json::Map<String, Value>,) -> Result<PreparedFlowRun, String> {- let flow = store::get_flow(config, flow_id)- .map_err(|error| error.to_string())?- .ok_or_else(|| format!("flow '{flow_id}' not found"))?;+ // Resolve the definition through the dispatch's captured CatalogStorage+ // scope. `store::get_flow` is a synchronous ambient-scope convenience API+ // and must not choose the acting identity for an explicitly dispatched run.+ let catalog = crate::flows::catalog_storage::register(ctx, config).await?;+ let proxy = crate::modules::tinyflows::catalog_proxy(config).await?;+ let workflow: Option<tinyflows_bus::catalog::Workflow> = proxy+ .call(+ tinyflows_bus::catalog::members::GET_WORKFLOW,+ (catalog.storage(), flow_id.to_owned()),+ )+ .await+ .map_err(|error| error.wire_message())?;+ let flow: Flow = store::roundtrip(+ workflow.ok_or_else(|| format!("flow '{flow_id}' not found"))?,+ )+ .map_err(|error| format!("decode workflow for run: {error}"))?;let no_actionable_nodes = !graph_has_actionable_nodes(&flow.graph);if no_actionable_nodes {tracing::warn!(