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): use bus DTOs directly instead of roundtrip conversion
Steven Enamakelb66d8e4c8a20
diff --git a/crates/openhuman-core/src/flows/bus/run_digest.rs b/crates/openhuman-core/src/flows/bus/run_digest.rsindex 70873defb9..584f529711 100644--- a/crates/openhuman-core/src/flows/bus/run_digest.rs+++ b/crates/openhuman-core/src/flows/bus/run_digest.rs@@ -137,13 +137,7 @@ impl FlowRunDigestSubscriber {tracing::warn!(target: "flows", %flow_id, %run_id, "[flows] digest: run row not found — skipping");return;};- let run: FlowRun = match store::roundtrip(wire_run) {- Ok(run) => run,- Err(error) => {- tracing::warn!(target: "flows", %flow_id, %run_id, %error, "[flows] digest: failed to decode run — skipping");- return;- }- };+ let run: FlowRun = wire_run;let digest = render_run_digest(&flow_name, &run);let mut meta = flow_meta(flow_id, &[FLOW_RUN_DIGEST_TAG.to_string()]);diff --git a/crates/openhuman-core/src/flows/draft_store.rs b/crates/openhuman-core/src/flows/draft_store.rsindex 0b4ef29417..fce8b80e77 100644--- a/crates/openhuman-core/src/flows/draft_store.rs+++ b/crates/openhuman-core/src/flows/draft_store.rs@@ -3,8 +3,7 @@use anyhow::Result;use serde_json::Value;use tinyflows_bus::catalog::{- self, CreateDraftRequest, DraftIdRequest, DraftOrigin, FlowDraft, FlowDraft as WireDraft,- UpdateDraftRequest,+ self, CreateDraftRequest, DraftIdRequest, DraftOrigin, FlowDraft, UpdateDraftRequest,};use crate::config::Config;@@ -24,13 +23,13 @@ pub fn create_draft(flow_id,name,graph,- origin: store::roundtrip(origin)?,+ origin,};- store::roundtrip(store::call_catalog::<WireDraft, _>(+ store::call_catalog::<FlowDraft, _>(config,catalog::members::CREATE_DRAFT,(request,),- )?)+ )}/// Read one module-owned draft.@@ -40,9 +39,9 @@ pub fn get_draft(config: &Config, id: &str) -> Result<Option<FlowDraft>> {storage,id: id.to_owned(),};- let draft: Option<WireDraft> =+ let draft: Option<FlowDraft> =store::call_catalog(config, catalog::members::GET_DRAFT, (request,))?;- draft.map(store::roundtrip).transpose()+ Ok(draft)}/// Patch a module-owned draft.@@ -61,19 +60,15 @@ pub fn update_draft(graph,flow_id,};- let draft: WireDraft = store::call_catalog(config, catalog::members::UPDATE_DRAFT, (request,))?;- store::roundtrip(draft)+ store::call_catalog(config, catalog::members::UPDATE_DRAFT, (request,))}/// List module-owned drafts.pub fn list_drafts(config: &Config) -> Result<Vec<FlowDraft>> {let storage = catalog_storage::register_blocking(config)?;- let drafts: Vec<WireDraft> =+ let drafts: Vec<FlowDraft> =store::call_catalog(config, catalog::members::LIST_DRAFTS, (storage,))?;- drafts- .into_iter()- .map(store::roundtrip)- .collect::<Result<Vec<_>>>()+ Ok(drafts)}/// Delete one draft, returning whether a record was removed.diff --git a/crates/openhuman-core/src/flows/ops.rs b/crates/openhuman-core/src/flows/ops.rsindex af3d46f969..978ecfc3cf 100644--- a/crates/openhuman-core/src/flows/ops.rs+++ b/crates/openhuman-core/src/flows/ops.rs@@ -36,11 +36,7 @@ use std::sync::Arc;use serde_json::{json, Value};#[cfg(test)]use tinyflows::model::{NodeKind, WorkflowGraph};-// Generic graph analysis used for UI notes and authoring summaries comes from-// the TinyFlows bus. OpenHuman-specific save and dispatch policy stays here.-// The save/run safety predicates are `tinyflows-catalog`'s: whether a graph-// fires unattended, whether it can act on the world, and whether it has work-// are graph properties. Import them only at their host policy call sites.+// Graphs and Catalog/Runs records cross the module boundary as bus DTOs.use crate::config::Config;use crate::core::Outcome;use crate::flows::bus;@@ -49,10 +45,12 @@ use crate::flows::store;use crate::security::approval::{ApprovalChatContext, ApprovalTurnContext};use crate::security::turn_origin::{with_origin, AgentTurnOrigin};mod build_registry;-use tinyflows_bus::catalog::{FlowRun, FlowSuggestion, SuggestionStatus, Workflow as Flow};+use tinyflows_bus::catalog::{FlowRun, FlowSuggestion, SuggestionStatus};use tinyflows_bus::runs::FlowRunTrigger;use tokio_util::sync::CancellationToken;+pub(crate) use tinyflows_bus::catalog::Workflow as Flow;+/// Overall safety bound on a single `flows_run` / `flows_resume`. Individual/// capabilities have their own timeouts (HTTP, sandbox), but a hung LLM/tooldiff --git a/crates/openhuman-core/src/flows/ops/build_registry.rs b/crates/openhuman-core/src/flows/ops/build_registry.rsindex 4eb08d7f36..3db6c87768 100644--- a/crates/openhuman-core/src/flows/ops/build_registry.rs+++ b/crates/openhuman-core/src/flows/ops/build_registry.rs@@ -36,15 +36,13 @@ pub(super) fn register_build_turn(.lock().unwrap_or_else(|error| error.into_inner()).insert(thread_id.clone(), BuildTurn { request_id, token });- if let Some(displaced) = displaced {- if !displaced.token.is_cancelled() {- tracing::debug!(- target: "flows",- thread_id = %thread_id,- "[flows] cancelling displaced builder turn"- );- displaced.token.cancel();- }+ if let Some(displaced) = displaced.filter(|turn| !turn.token.is_cancelled()) {+ tracing::debug!(+ target: "flows",+ thread_id = %thread_id,+ "[flows] cancelling displaced builder turn"+ );+ displaced.token.cancel();}}@@ -62,17 +60,15 @@ pub(super) fn cancel_build_turn_scoped(thread_id: &str, request_id: Option<&str>);return false;};- if let Some(request_id) = request_id {- if turn.request_id.as_deref() != Some(request_id) {- tracing::debug!(- target: "flows",- thread_id,- request_id,- active_request_id = turn.request_id.as_deref().unwrap_or("<none>"),- "[flows] builder cancellation ignored: request id does not match"- );- return false;- }+ if request_id.is_some_and(|request_id| turn.request_id.as_deref() != Some(request_id)) {+ tracing::debug!(+ target: "flows",+ thread_id,+ request_id = request_id.unwrap_or_default(),+ active_request_id = turn.request_id.as_deref().unwrap_or("<none>"),+ "[flows] builder cancellation ignored: request id does not match"+ );+ return false;}turn.token.cancel();tracing::info!(diff --git a/crates/openhuman-core/src/flows/ops/connections.rs b/crates/openhuman-core/src/flows/ops/connections.rsindex 661d81ca97..220f20fc4e 100644--- a/crates/openhuman-core/src/flows/ops/connections.rs+++ b/crates/openhuman-core/src/flows/ops/connections.rs@@ -262,7 +262,7 @@ pub async fn compute_required_connections(}};- for node in super::super::host_gates::graph_json::nodes(graph) {+ for node in crate::flows::host_gates::nodes(graph) {if node.kind == "tool_call" {if let Some(slug) = node.config.get("slug").and_then(Value::as_str) {// Native OpenHuman tools (`oh:<name>`) need no connection.@@ -276,7 +276,7 @@ pub async fn compute_required_connections(}}// An app_event trigger names its toolkit directly.- if let Some(trigger) = super::super::host_gates::graph_json::nodes(graph)+ if let Some(trigger) = crate::flows::host_gates::nodes(graph).find(|node| node.kind == "trigger"){if let Some(tk) = trigger.config.get("toolkit").and_then(Value::as_str) {diff --git a/crates/openhuman-core/src/flows/ops/definitions.rs b/crates/openhuman-core/src/flows/ops/definitions.rsindex 21414f5fde..f9609c68a3 100644--- a/crates/openhuman-core/src/flows/ops/definitions.rs+++ b/crates/openhuman-core/src/flows/ops/definitions.rs@@ -15,42 +15,11 @@ pub(super) fn publish_flow_changed(flow_id: &str, kind: &str, actor: &str) {/// Creates a new flow from a name and a raw graph JSON value.///-/// Issue B29 (save/enable safety) — two server-side rules apply here,-/// authoritative regardless of what the caller passed, so no creation path-/// (prompt bar, scratch/template modal, proposal "save & enable", copilot-/// `save_workflow`, …) can silently hand the user an armed, unattended-/// automation:-///-/// - **Rule 1** ([`trigger_is_automatic`]): a graph whose trigger fires-/// without a human in the loop (`schedule` / `app_event` / `webhook`)-/// persists **disabled**. The user arms it explicitly via-/// `flows_set_enabled` — the same toggle already used everywhere else. A-/// `manual` trigger (or no trigger-kind discriminator at all) still-/// persists enabled: it only ever runs via an explicit `flows_run`, so-/// there is no surprise, and gating it would just add friction.-///-/// This means a caller that represents an explicit user-arming action-/// (e.g. `WorkflowProposalCard`'s "Save & enable" click,-/// `app/src/components/chat/WorkflowProposalCard.tsx`) must check the-/// returned [`Flow`]'s `enabled` field and follow up with-/// `flows_set_enabled(id, true)` when it comes back `false` — otherwise-/// the button's own label lies to the user. That follow-up call is a-/// legitimate, explicit enable, not the silent copilot auto-arm this rule-/// exists to prevent (the copilot's `save_workflow` path has no such-/// follow-up and stays disabled).-/// - **Rule 2** ([`graph_has_outbound_side_effect`]): a graph containing any-/// `tool_call` / `http_request` / `code` node — the three kinds that can-/// produce a real outbound effect — forces `require_approval: true`,-/// overriding whatever the caller passed. A read-only graph (only-/// `trigger` / `agent` / `transform` / `condition` / data-flow nodes) is-/// unaffected.-///-/// An enabled flow still has its automatic-dispatch side effect bound-/// immediately (e.g. the schedule-trigger cron job registered), reusing the-/// same [`bind_trigger`] helper `flows_set_enabled` uses — but per Rule 1-/// that now only happens for a `manual`-triggered (or trigger-kind-less)-/// flow. Best-effort, same as `flows_set_enabled`: a binding failure is-/// logged, not fatal to create.+/// Catalog.PutWorkflow validates and persists the graph, applies automatic-+/// trigger disarm and outbound-action approval policy, and returns its+/// authoritative `born_disabled` / `approval_forced` results for the host RPC+/// logs. OpenHuman binds the automatic-dispatch trigger only when the saved+/// result is enabled.pub async fn flows_create(config: &Config,name: String,@@ -163,7 +132,7 @@ pub async fn flows_get(config: &Config, id: &str) -> Result<Outcome<Flow>, StrinOk(Outcome::single_log(flow, format!("flow loaded: {id}")))}-/// Loads a saved flow's portable [`WorkflowGraph`] by id, for the+/// Loads a saved flow's portable JSON graph by id, for the/// `sub_workflow`-by-`workflow_id` resolver capability through the compiled/// TinyFlows module's Catalog contract.///diff --git a/crates/openhuman-core/src/flows/ops/drafts.rs b/crates/openhuman-core/src/flows/ops/drafts.rsindex e1d0e5ecb0..0423961576 100644--- a/crates/openhuman-core/src/flows/ops/drafts.rs+++ b/crates/openhuman-core/src/flows/ops/drafts.rs@@ -123,8 +123,7 @@ pub(crate) async fn flows_draft_promote_with_context(match response {tinyflows_bus::catalog::PromoteDraftResponse::Error(error) => Err(error.message),tinyflows_bus::catalog::PromoteDraftResponse::Ok(result) => {- let flow: Flow = crate::flows::store::roundtrip(result.workflow)- .map_err(|error| error.to_string())?;+ let flow: Flow = result.workflow;let mut logs = result.metadata.get("logs")diff --git a/crates/openhuman-core/src/flows/ops/inference_readiness.rs b/crates/openhuman-core/src/flows/ops/inference_readiness.rsindex 074a509010..7f9456ba6e 100644--- a/crates/openhuman-core/src/flows/ops/inference_readiness.rs+++ b/crates/openhuman-core/src/flows/ops/inference_readiness.rs@@ -140,7 +140,7 @@ pub(super) async fn evaluate_inference_readiness(graph: &Value,) -> Option<InferenceReadinessEvaluation> {let mut roles = Vec::new();- for node in crate::flows::host_gates::graph_json::nodes(graph)+ for node in crate::flows::host_gates::nodes(graph).filter(|node| node.kind == "agent"){roles.push((node.id.to_owned(), agent_node_role(config, node.config).await));diff --git a/crates/openhuman-core/src/flows/ops/run.rs b/crates/openhuman-core/src/flows/ops/run.rsindex da7d1d8e5e..247168bce0 100644--- a/crates/openhuman-core/src/flows/ops/run.rs+++ b/crates/openhuman-core/src/flows/ops/run.rs@@ -124,10 +124,8 @@ pub(super) async fn prepare_flow_run().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 graph_json = serde_json::to_value(&flow.graph).map_err(|error| error.to_string())?;+ let flow: Flow = workflow.ok_or_else(|| format!("flow '{flow_id}' not found"))?;+ let graph_json = flow.graph.clone();let analysis = super::validation::validate_over_bus(ctx, config, graph_json).await?;let no_actionable_nodes = !analysis.has_actionable_nodesdiff --git a/crates/openhuman-core/src/flows/ops/run_management.rs b/crates/openhuman-core/src/flows/ops/run_management.rsindex 575332d641..fc948f5cd9 100644--- a/crates/openhuman-core/src/flows/ops/run_management.rs+++ b/crates/openhuman-core/src/flows/ops/run_management.rs@@ -1,7 +1,10 @@use super::*;use tinyflows_bus::catalog::{self as wire, FlowRun as WireFlowRun};-use tinyflows_catalog::run_management as rm;+/// OpenHuman's default explicit run-history retention request. The module+/// owns pruning mechanics and protects live rows; this is the host-selected+/// history cap exposed by the manual prune RPC.+const FLOW_RUN_HISTORY_LIMIT: usize = 100;/// Cancel a workflow run through its owner-scoped Runs.CancelRun operation.pub async fn flows_cancel_run(config: &Config, run_id: &str) -> Result<Outcome<Value>, String> {@@ -9,23 +12,12 @@ pub async fn flows_cancel_run(config: &Config, run_id: &str) -> Result<Outcome<Vlet storage = crate::flows::catalog_storage::register(&ctx, config).await?.storage();- let run = get_run_with_storage(config, storage.clone(), run_id)+ let _run = get_run_with_storage(config, storage.clone(), run_id).await?.ok_or_else(|| format!("flow run '{run_id}' not found"))?;- if rm::is_terminal_run_status(&run.status) {- return Err(rm::already_terminal_error(run_id, &run.status));- }-let (signalled, was_in_flight) =crate::flows::runs_adapter::cancel_run(config, storage.clone(), run_id).await?;if !signalled {- let current = get_run_with_storage(config, storage, run_id).await?;- if current- .as_ref()- .is_some_and(|current| rm::is_terminal_run_status(¤t.status))- {- return Err(rm::settled_concurrently_error(run_id));- }return Err(format!("flow run '{run_id}' cancellation was not accepted"));}@@ -99,7 +91,7 @@ pub async fn flows_list_all_runs(/// Prune terminal run history while retaining the module's standard cap and/// every live or approval-parked run.pub async fn flows_prune_runs(config: &Config, flow_id: &str) -> Result<Outcome<Value>, String> {- let keep = tinyflows_catalog::store::MAX_FLOW_RUNS_PER_FLOW;+ let keep = FLOW_RUN_HISTORY_LIMIT;let ctx = crate::core::runtime::DispatchCtx::ambient();let storage = crate::flows::catalog_storage::register(&ctx, config).await?diff --git a/crates/openhuman-core/src/flows/ops/updates.rs b/crates/openhuman-core/src/flows/ops/updates.rsindex cf2e4d6933..91c051fbc5 100644--- a/crates/openhuman-core/src/flows/ops/updates.rs+++ b/crates/openhuman-core/src/flows/ops/updates.rs@@ -144,6 +144,7 @@ async fn flows_update_inner(existing.graph.clone()}};+ let forced_automatic_disarm = disarm_automatic;// B29 Rule 1 analogue: disarm every manual/none → automatic trigger// transition, unconditionally. `now_auto` is safe to compute here (it// only depends on `graph`, THIS call's own incoming graph — neverdiff --git a/crates/openhuman-core/src/flows/runs_adapter.rs b/crates/openhuman-core/src/flows/runs_adapter.rsindex 718d113960..20a994ffcb 100644--- a/crates/openhuman-core/src/flows/runs_adapter.rs+++ b/crates/openhuman-core/src/flows/runs_adapter.rs@@ -263,10 +263,7 @@ pub(crate) async fn register_resume_bindings().await.map_err(|error| error.wire_message())?;- let flow: Flow = crate::flows::store::roundtrip(- workflow.ok_or_else(|| format!("flow '{flow_id}' not found"))?,- )- .map_err(|error| format!("decode workflow for resume: {error}"))?;+ let flow: Flow = workflow.ok_or_else(|| format!("flow '{flow_id}' not found"))?;if flow.require_approval != require_approval {return Err("workflow approval policy changed during resume".to_string());}diff --git a/crates/openhuman-core/src/flows/store.rs b/crates/openhuman-core/src/flows/store.rsindex 02235743bd..07a45aa106 100644--- a/crates/openhuman-core/src/flows/store.rs+++ b/crates/openhuman-core/src/flows/store.rs@@ -10,12 +10,9 @@ use serde::{de::DeserializeOwned, Serialize};use tinyflows_bus::catalog::{self, DeleteWorkflowResult, FlowUpdateError as BusUpdateError, GetRevisionRequest,ListRevisionsRequest, ListWorkflowsResult, PutWorkflowRequest, PutWorkflowResponse,- PutWorkflowResult,- SetEnabledRequest, Workflow, WorkflowRevision,-};-use tinyflows_bus::catalog::{- Flow as Flow, FlowRevision, FlowSuggestion, SuggestionStatus,+ PutWorkflowResult, SetEnabledRequest, Workflow as Flow, WorkflowRevision,};+use tinyflows_bus::catalog::{FlowSuggestion, SuggestionStatus};use crate::config::Config;use crate::modules::tinyflows as module;@@ -37,10 +34,6 @@ where})}-fn flow_from_wire(workflow: Workflow) -> Result<Flow> {- Ok(workflow)-}-pub(crate) fn roundtrip<T, U>(value: T) -> Result<U>whereT: Serialize,@@ -100,7 +93,7 @@ pub fn get_flow(config: &Config, id: &str) -> Result<Option<Flow>> {catalog::members::GET_WORKFLOW,(storage, id.to_owned()),)?;- workflow.map(flow_from_wire).transpose()+ Ok(workflow)}/// List workflows and their full graphs through the module's catalog client.@@ -116,13 +109,9 @@ pub fn list_flows(config: &Config) -> Result<(Vec<Flow>, usize)> {catalog::members::GET_WORKFLOW,(storage.clone(), summary.id),)?;- match workflow.map(flow_from_wire).transpose() {- Ok(Some(flow)) => flows.push(flow),- Ok(None) => skipped += 1,- Err(error) => {- tracing::warn!(%error, "[flows] catalog returned a workflow that could not be decoded");- skipped += 1;- }+ match workflow {+ Some(flow) => flows.push(flow),+ None => skipped += 1,}}Ok((flows, skipped))@@ -157,7 +146,7 @@ pub fn set_enabled(config: &Config, id: &str, enabled: bool) -> Result<Flow> {enabled,};let workflow: Workflow = call_catalog(config, catalog::members::SET_ENABLED, (request,))?;- flow_from_wire(workflow)+ Ok(workflow)}/// Update a workflow while preserving the module's optimistic concurrency.@@ -199,7 +188,11 @@ pub fn update_flow_graph(}/// List a workflow's committed revisions.-pub fn list_revisions(config: &Config, flow_id: &str, limit: usize) -> Result<Vec<FlowRevision>> {+pub fn list_revisions(+ config: &Config,+ flow_id: &str,+ limit: usize,+) -> Result<Vec<WorkflowRevision>> {let storage = super::catalog_storage::register_blocking(config)?;let request = ListRevisionsRequest {storage,@@ -208,7 +201,7 @@ pub fn list_revisions(config: &Config, flow_id: &str, limit: usize) -> Result<Ve};let revisions: Vec<WorkflowRevision> =call_catalog(config, catalog::members::LIST_REVISIONS, (request,))?;- revisions.into_iter().map(roundtrip).collect()+ Ok(revisions)}/// Read one workflow revision by id.@@ -216,7 +209,7 @@ pub fn revision_by_id(config: &Config,flow_id: &str,revision_id: &str,-) -> Result<Option<FlowRevision>> {+) -> Result<Option<WorkflowRevision>> {let storage = super::catalog_storage::register_blocking(config)?;let request = GetRevisionRequest {storage,@@ -225,20 +218,15 @@ pub fn revision_by_id(};let revision: Option<WorkflowRevision> =call_catalog(config, catalog::members::GET_REVISION, (request,))?;- revision.map(roundtrip).transpose()+ Ok(revision)}/// Upsert module-owned discovery suggestions.pub fn upsert_suggestions(config: &Config, suggestions: &[FlowSuggestion]) -> Result<usize> {let storage = super::catalog_storage::register_blocking(config)?;- let suggestions = suggestions- .iter()- .cloned()- .map(roundtrip)- .collect::<Result<Vec<catalog::FlowSuggestion>>>()?;let request = catalog::UpsertSuggestionsRequest {storage,- suggestions,+ suggestions: suggestions.to_vec(),};call_catalog(config, catalog::members::UPSERT_SUGGESTIONS, (request,))}@@ -250,21 +238,19 @@ pub fn list_suggestions(limit: usize,) -> Result<Vec<FlowSuggestion>> {let storage = super::catalog_storage::register_blocking(config)?;- let status: Option<catalog::SuggestionStatus> = status.map(roundtrip).transpose()?;let request = catalog::ListSuggestionsRequest {storage,status,limit,};- let suggestions: Vec<catalog::FlowSuggestion> =+ let suggestions: Vec<FlowSuggestion> =call_catalog(config, catalog::members::LIST_SUGGESTIONS, (request,))?;- suggestions.into_iter().map(roundtrip).collect()+ Ok(suggestions)}/// Set a suggestion's module-owned lifecycle status.pub fn set_suggestion_status(config: &Config, id: &str, status: SuggestionStatus) -> Result<bool> {let storage = super::catalog_storage::register_blocking(config)?;- let status: catalog::SuggestionStatus = roundtrip(status)?;let request = catalog::SetSuggestionStatusRequest {storage,id: id.to_owned(),