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
refactor(flows): share owner config resolution across bus subscribers
Steven Enamakele8f41fca992a
diff --git a/crates/openhuman-core/src/flows/bus/dedup_commit.rs b/crates/openhuman-core/src/flows/bus/dedup_commit.rsindex 764788b6a8..0240e10972 100644--- a/crates/openhuman-core/src/flows/bus/dedup_commit.rs+++ b/crates/openhuman-core/src/flows/bus/dedup_commit.rs@@ -222,6 +222,8 @@ impl DedupCommitSubscriber {}async fn handle_finished(&self, flow_id: &str, run_id: &str, status: &str) {+ // As the flow's owner: its own configuration (`super::owner`).+ let config = super::owner::config_for_scope(&config);let node_ids = self.dedup_node_ids(flow_id);if node_ids.is_empty() {tracing::trace!(target: "flows", %flow_id, %run_id, %status, "[dedup-commit] no dedup nodes in this flow — nothing to settle");@@ -246,7 +248,7 @@ impl DedupCommitSubscriber {tracing::trace!(target: "flows", %flow_id, %run_id, "[dedup-commit] acquired per-flow commit lock");self.maybe_test_delay().await;- let state = FlowState::open(&self.config, format!("flow:{flow_id}"));+ let state = FlowState::open(&config, format!("flow:{flow_id}"));for node_id in node_ids {self.settle_node(&state, &node_id, success, flow_id, run_id);}diff --git a/crates/openhuman-core/src/flows/bus/owner.rs b/crates/openhuman-core/src/flows/bus/owner.rsindex 79d31f76c5..ceb5ae9096 100644--- a/crates/openhuman-core/src/flows/bus/owner.rs+++ b/crates/openhuman-core/src/flows/bus/owner.rs@@ -92,6 +92,19 @@ pub(super) async fn as_owner<F: std::future::Future<Output = ()>>(}}+/// The configuration to handle a flow event under: the acting agent's own+/// when the handler runs as one ([`as_owner`]) — its provider, access+/// policy, memory and action directory — else `registered`, the one the+/// subscriber was registered with.+pub(super) fn config_for_scope(registered: &std::sync::Arc<Config>) -> std::sync::Arc<Config> {+ let acting = crate::core::runtime::CoreContext::current()+ .is_some_and(|context| context.session_agent().is_some());+ match acting.then(crate::core::runtime::CoreContext::current_embedder_config) {+ Some(Some(config)) => std::sync::Arc::new(config),+ _ => std::sync::Arc::clone(registered),+ }+}+/// Forgets a cached owner (a removed flow's id may be reused).pub(super) fn forget(flow_id: &str) {OWNERSdiff --git a/crates/openhuman-core/src/flows/bus/run_digest.rs b/crates/openhuman-core/src/flows/bus/run_digest.rsindex 418c78a8d5..595d8fb8a8 100644--- a/crates/openhuman-core/src/flows/bus/run_digest.rs+++ b/crates/openhuman-core/src/flows/bus/run_digest.rs@@ -60,16 +60,18 @@ impl FlowRunDigestSubscriber {}async fn handle_finished(&self, flow_id: &str, run_id: &str, status: &str) {+ // As the flow's owner: its own configuration (`super::owner`).+ let config = super::owner::config_for_scope(&config);if status != "completed" && status != "completed_with_warnings" {tracing::trace!(target: "flows", %flow_id, %run_id, %status, "[flows] digest: ignoring non-success terminal status");return;}- if !crate::memory::memory_is_on(&self.config) {+ if !crate::memory::memory_is_on(&config) {tracing::debug!(target: "flows", %flow_id, %run_id, "[flows] digest: memory is off — skipping");return;}- let flow_name = match store::get_flow(&self.config, flow_id) {+ let flow_name = match store::get_flow(&config, flow_id) {Ok(Some(flow)) => flow.name,Ok(None) => {tracing::debug!(target: "flows", %flow_id, %run_id, "[flows] digest: flow no longer exists — skipping");@@ -81,7 +83,7 @@ impl FlowRunDigestSubscriber {}};- let run = match store::get_flow_run(&self.config, run_id) {+ let run = match store::get_flow_run(&config, run_id) {Ok(Some(run)) => run,Ok(None) => {tracing::warn!(target: "flows", %flow_id, %run_id, "[flows] digest: run row not found — skipping");@@ -99,7 +101,7 @@ impl FlowRunDigestSubscriber {// A machine-written run summary: searchable, but no facts or// beliefs about the user are derived from it.meta.derive = Some(false);- match crate::memory::ops::store_item(&self.config, StoreItem::document(digest, meta)).await+ match crate::memory::ops::store_item(&config, StoreItem::document(digest, meta)).await{Ok(receipt) => {tracing::debug!(target: "flows", %flow_id, %run_id, replayed = receipt.replayed, "[flows] digest: run digest stored");@@ -114,7 +116,7 @@ impl FlowRunDigestSubscriber {}}- match enforce_retention_cap(&self.config, flow_id, DIGEST_RETENTION_CAP).await {+ match enforce_retention_cap(&config, flow_id, DIGEST_RETENTION_CAP).await {Ok(0) => {}Ok(forgotten) => {tracing::debug!(target: "flows", %flow_id, forgotten, "[flows] digest: retention sweep forgot stale digests");diff --git a/crates/openhuman-core/src/flows/bus/trigger.rs b/crates/openhuman-core/src/flows/bus/trigger.rsindex 8b4b52ad7c..530616458d 100644--- a/crates/openhuman-core/src/flows/bus/trigger.rs+++ b/crates/openhuman-core/src/flows/bus/trigger.rs@@ -111,17 +111,9 @@ impl FlowTriggerSubscriber {})}- /// The configuration to handle an event under: the acting agent's own- /// when the handler runs as one (`super::owner`, `crate::storage::agents`)- /// — its provider, access policy and action directory — else the one this- /// subscriber was registered with.+ /// The configuration to handle an event under (`super::owner::config_for_scope`).pub(super) fn config_for_scope(&self) -> Arc<Config> {- let acting = crate::core::runtime::CoreContext::current()- .is_some_and(|context| context.session_agent().is_some());- match acting.then(crate::core::runtime::CoreContext::current_embedder_config) {- Some(Some(config)) => Arc::new(config),- _ => Arc::clone(&self.config),- }+ super::owner::config_for_scope(&self.config)}/// `DomainEvent::FlowScheduleTick` — a `flow`-type cron job fired. Loads