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): update flow creation and update result handling
Steven Enamakel1f3554ecce51
diff --git a/crates/openhuman-core/src/flows/catalogue_tests.rs b/crates/openhuman-core/src/flows/catalogue_tests.rsindex 2faceb966b..6a3bb6ddfc 100644--- a/crates/openhuman-core/src/flows/catalogue_tests.rs+++ b/crates/openhuman-core/src/flows/catalogue_tests.rs@@ -196,6 +196,7 @@ fn a_saved_flow_reaches_the_catalogue_with_its_real_id() {"Weekly Report".to_string(),graph,false,+ true,).expect("flow saves").workflow;@@ -226,7 +227,7 @@ fn entries_are_sorted_by_name_so_the_prompt_prefix_is_stable() {serde_json::json!({ "trigger_kind": "manual" }),)]);for name in ["Zebra", "Alpha", "Mango"] {- super::super::store::create_flow(&config, name.to_string(), graph.clone(), false)+ super::super::store::create_flow(&config, name.to_string(), graph.clone(), false, true).expect("flow saves");}let names: Vec<String> = flow_entries(&config).into_iter().map(|e| e.name).collect();diff --git a/crates/openhuman-core/src/flows/ops/definitions.rs b/crates/openhuman-core/src/flows/ops/definitions.rsindex f9609c68a3..83006a6ff3 100644--- a/crates/openhuman-core/src/flows/ops/definitions.rs+++ b/crates/openhuman-core/src/flows/ops/definitions.rs@@ -56,13 +56,11 @@ pub(crate) async fn flows_create_with_context(require_approval,"[flows] flows_create: persisting new flow");- let result = store::create_flow(config, name, graph, require_approval)+ let result = store::create_flow(config, name, graph, require_approval, true).map_err(|e| e.to_string())?;- let tinyflows_bus::catalog::PutWorkflowResult {- workflow: flow,- born_disabled,- approval_forced,- } = result;+ let flow = result.workflow;+ let born_disabled = result.born_disabled;+ let approval_forced = result.approval_forced;if flow.enabled {tracing::debug!(target: "flows", flow_id = %flow.id, "[flows] flows_create: flow is enabled — binding automatic-dispatch trigger");diff --git a/crates/openhuman-core/src/flows/ops/updates.rs b/crates/openhuman-core/src/flows/ops/updates.rsindex 69788bb4f9..10d938d851 100644--- a/crates/openhuman-core/src/flows/ops/updates.rs+++ b/crates/openhuman-core/src/flows/ops/updates.rs@@ -184,7 +184,7 @@ async fn flows_update_inner(// happened store-side against a fresh read, so this is purely for the// info log / result message wording below and can't desync from what// was actually persisted.- let tinyflows_bus::catalog::PutWorkflowResult {+ let store::FlowWriteResult {workflow: updated,born_disabled: should_disarm,approval_forced,diff --git a/crates/openhuman-core/src/flows/store.rs b/crates/openhuman-core/src/flows/store.rsindex 07a45aa106..5fa03d4e02 100644--- a/crates/openhuman-core/src/flows/store.rs+++ b/crates/openhuman-core/src/flows/store.rs@@ -7,16 +7,34 @@use anyhow::{anyhow, Result};use serde::{de::DeserializeOwned, Serialize};+use std::ops::Deref;use tinyflows_bus::catalog::{self, DeleteWorkflowResult, FlowUpdateError as BusUpdateError, GetRevisionRequest,ListRevisionsRequest, ListWorkflowsResult, PutWorkflowRequest, PutWorkflowResponse,- PutWorkflowResult, SetEnabledRequest, Workflow as Flow, WorkflowRevision,+ SetEnabledRequest, Workflow as Flow, WorkflowRevision,};use tinyflows_bus::catalog::{FlowSuggestion, SuggestionStatus};use crate::config::Config;use crate::modules::tinyflows as module;+/// Host projection of a Catalog write, retaining owner policy flags while+/// dereferencing to the persisted workflow for existing internal callers.+#[derive(Clone, Debug)]+pub(crate) struct FlowWriteResult {+ pub(crate) workflow: Flow,+ pub(crate) born_disabled: bool,+ pub(crate) approval_forced: bool,+}++impl Deref for FlowWriteResult {+ type Target = Flow;++ fn deref(&self) -> &Self::Target {+ &self.workflow+ }+}+pub(crate) fn call_catalog<T, A>(config: &Config, member: &'static str, args: A) -> Result<T>whereT: DeserializeOwned + Send + 'static,@@ -42,9 +60,13 @@ whereserde_json::from_value(serde_json::to_value(value)?).map_err(Into::into)}-fn put_result(response: PutWorkflowResponse) -> Result<PutWorkflowResult> {+fn put_result(response: PutWorkflowResponse) -> Result<FlowWriteResult> {match response {- PutWorkflowResponse::Ok(result) => Ok(result),+ PutWorkflowResponse::Ok(result) => Ok(FlowWriteResult {+ workflow: result.workflow,+ born_disabled: result.born_disabled,+ approval_forced: result.approval_forced,+ }),PutWorkflowResponse::Error(error) => Err(anyhow!(match error {BusUpdateError::NotFound { message }| BusUpdateError::VersionConflict { message, .. }@@ -72,7 +94,8 @@ pub fn create_flow(name: String,graph: Value,require_approval: bool,-) -> Result<PutWorkflowResult> {+ enabled: bool,+) -> Result<FlowWriteResult> {let storage = super::catalog_storage::register_blocking(config)?;let request = PutWorkflowRequest::Create {storage,@@ -82,7 +105,13 @@ pub fn create_flow(};let response: PutWorkflowResponse =call_catalog(config, catalog::members::PUT_WORKFLOW, (request,))?;- put_result(response)+ let mut result = put_result(response)?;+ // This is an explicit caller choice to start disabled. Catalog still+ // authoritatively prevents automatic triggers from being born enabled.+ if !enabled && result.workflow.enabled {+ result.workflow = set_enabled(config, &result.workflow.id, false)?;+ }+ Ok(result)}/// Read one workflow by id.@@ -160,7 +189,7 @@ pub fn update_flow_graph(_enabled_override: Option<bool>,force_disarm_if_automatic: bool,expected_updated_at: Option<&str>,-) -> std::result::Result<PutWorkflowResult, BusUpdateError> {+) -> std::result::Result<FlowWriteResult, BusUpdateError> {let storage = super::catalog_storage::register_blocking(config).map_err(|error| {BusUpdateError::Store {message: error.to_string(),@@ -182,7 +211,11 @@ pub fn update_flow_graph(}})?;match response {- PutWorkflowResponse::Ok(result) => Ok(result),+ PutWorkflowResponse::Ok(result) => Ok(FlowWriteResult {+ workflow: result.workflow,+ born_disabled: result.born_disabled,+ approval_forced: result.approval_forced,+ }),PutWorkflowResponse::Error(error) => Err(error),}}