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): validate admitted run id and clean up finished sessions
Steven Enamakel009ae5d9e7b1
diff --git a/crates/openhuman-core/src/flows/runs_adapter.rs b/crates/openhuman-core/src/flows/runs_adapter.rsindex 04c2ca7a3c..9f68ab5ef6 100644--- a/crates/openhuman-core/src/flows/runs_adapter.rs+++ b/crates/openhuman-core/src/flows/runs_adapter.rs@@ -79,14 +79,7 @@ pub(crate) async fn register_bindings(run_id: &str,) -> Result<Arc<RunBindings>, String> {let catalog = catalog_storage::register(ctx, config).await?;- register_with_catalog(- ctx,- config,- flow,- run_id,- catalog,- )- .await+ register_with_catalog(ctx, config, flow, run_id, catalog).await}async fn register_with_catalog(@@ -172,6 +165,10 @@ pub(crate) async fn start_run(return Err(error.wire_message());}};+ if started.run_id != run_id {+ session::remove(&session);+ return Err("TinyFlows admitted a different run id".to_string());+ }if started.already_running {session::remove(&session);return Err(format!("flow run '{run_id}' is already running"));@@ -290,7 +287,6 @@ pub(crate) async fn resume_and_wait({return Err("resume bindings do not match the owner-scoped request".to_string());}- let key = RunKey::new(&storage, &request.run_id);let proxy = module::runs_proxy(config).await?;let (session, inserted) = match session::get(&storage, &request.run_id) {Some(session) => (session, false),@@ -337,7 +333,7 @@ pub(crate) async fn resume_and_wait(session.replace_flow(candidate.flow.clone()).await;session.set_trigger(FlowRunTrigger::Resume);session.mark_resumed();- session.replace_bindings(candidate).await;+ session.replace_bindings(candidate);session.start_polling(proxy);wait_for_outcome(&mut receiver, &request.run_id, baseline).await}@@ -427,7 +423,9 @@ pub(crate) async fn after_recovery(let storage = catalog.storage();if let Some(session) = session::get(&storage, run_id) {let proxy = module::runs_proxy(config).await?;- let _ = session.drain(&proxy, true).await?;+ if session.drain(&proxy, true).await? {+ session::remove(&session);+ }return Ok(());}@@ -464,7 +462,6 @@ pub(crate) async fn after_recovery(.flow_id;projection::project_recovered_finished(&key, &flow_id, run_id, event);}- cursor = event.seq;}if page.done || page.events.is_empty() || page.next_cursor <= cursor {break;diff --git a/crates/openhuman-core/src/flows/runs_adapter/session.rs b/crates/openhuman-core/src/flows/runs_adapter/session.rsindex 30d6c9352b..630d78f2dc 100644--- a/crates/openhuman-core/src/flows/runs_adapter/session.rs+++ b/crates/openhuman-core/src/flows/runs_adapter/session.rs@@ -129,7 +129,7 @@ impl RunSession {.unwrap_or_else(std::sync::PoisonError::into_inner)}- pub(super) async fn replace_bindings(&self, bindings: Arc<RunBindings>) {+ pub(super) fn replace_bindings(&self, bindings: Arc<RunBindings>) {*self.bindings.write()@@ -183,10 +183,6 @@ impl RunSession {self.live_actor.load(std::sync::atomic::Ordering::Acquire)}- pub(super) fn is_live_actor(&self) -> bool {- self.live_actor.load(std::sync::atomic::Ordering::Acquire)- }-pub(super) fn key(&self) -> RunKey {let bindings = self.bindingsdiff --git a/crates/openhuman-core/src/modules/tinyflows.rs b/crates/openhuman-core/src/modules/tinyflows.rsindex 37d9906454..374e39f3b0 100644--- a/crates/openhuman-core/src/modules/tinyflows.rs+++ b/crates/openhuman-core/src/modules/tinyflows.rs@@ -267,7 +267,8 @@ mod imp {path: String,object: impl tinybus::service::Interface + 'static,) -> Result<ServedObjectRegistration, String> {- let announces_caps_host = object.name().as_str() == tinyflows_bus::runs::CAPS_INTERFACE;+ let object_interface = tinybus::service::Interface::name(&object);+ let announces_caps_host = object_interface.as_str() == tinyflows_bus::runs::CAPS_INTERFACE;let runtime = runtime::runtime().await.map_err(|error| format!("the module bus is unavailable: {error}"))?;