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): carry approval context on capabilities
Steven Enamakelc7729108653c
diff --git a/crates/openhuman-core/src/flows/ops.rs b/crates/openhuman-core/src/flows/ops.rsindex c0d231ea51..a89e4f0c27 100644--- a/crates/openhuman-core/src/flows/ops.rs+++ b/crates/openhuman-core/src/flows/ops.rs@@ -57,10 +57,7 @@ use crate::core::Outcome;use crate::flows::bus;use crate::flows::draft_store;use crate::flows::store;-use crate::security::approval::{- ApprovalChatContext, FlowRunContext, APPROVAL_CHAT_CONTEXT, APPROVAL_COPILOT_STREAM_CONTEXT,- APPROVAL_FLOW_RUN_CONTEXT,-};+use crate::security::approval::{ApprovalChatContext, ApprovalTurnContext, FlowRunContext};use tinyflows_catalog::build_registry;use tinyflows_catalog::run_registry;use tinyflows_catalog::types::{diff --git a/crates/openhuman-core/src/flows/ops/execution.rs b/crates/openhuman-core/src/flows/ops/execution.rsindex e413d84c66..40b41b7bfe 100644--- a/crates/openhuman-core/src/flows/ops/execution.rs+++ b/crates/openhuman-core/src/flows/ops/execution.rs@@ -228,8 +228,15 @@ async fn run_flow_body_inner(};// Scope the state store per-flow so two flows never collide on a state key.- let caps =- crate::flows::tinyflows::build_capabilities(config_arc.clone(), format!("flow:{flow_id}"));+ let flow_run = FlowRunContext {+ flow_id: flow_id.to_string(),+ run_id: thread_id.clone(),+ };+ let caps = crate::flows::tinyflows::build_capabilities(+ config_arc.clone(),+ format!("flow:{flow_id}"),+ Some(flow_run),+ );let checkpointer = match crate::flows::tinyflows::open_flow_checkpointer(config) {Ok(checkpointer) => checkpointer,Err(e) => {@@ -293,27 +300,21 @@ async fn run_flow_body_inner(thread_id.clone(),),);- // Scope the flow/run correlation (issue flow-approval-surface, PR2)- // alongside the `Workflow` origin so a tool call the engine dispatches- // can, if it parks in the `ApprovalGate`, stamp its `PendingApproval` with- // `source_context = Flow { flow_id, run_id }` — the origin alone only- // carries `flow_id`. See `approval::gate::APPROVAL_FLOW_RUN_CONTEXT`.- let run = APPROVAL_FLOW_RUN_CONTEXT.scope(- FlowRunContext {- flow_id: flow_id.to_string(),- run_id: thread_id.clone(),- },- with_origin(- origin,- tinyflows::engine::run_with_checkpointer_journaled_observed(- &compiled,- tinyflows::engine::RunInput::new(input).with_inputs(inputs),- &caps,- checkpointer,- &thread_id,- journal.clone(),- &observer,- ),+ // The flow/run correlation (issue flow-approval-surface, PR2) rides the+ // capabilities built above, next to the `Workflow` origin scoped here, so a+ // tool call the engine dispatches can, if it parks in the `ApprovalGate`,+ // stamp its `PendingApproval` with `source_context = Flow { flow_id,+ // run_id }` -- the origin alone only carries `flow_id`.+ let run = with_origin(+ origin,+ tinyflows::engine::run_with_checkpointer_journaled_observed(+ &compiled,+ tinyflows::engine::RunInput::new(input).with_inputs(inputs),+ &caps,+ checkpointer,+ &thread_id,+ journal.clone(),+ &observer,),);let timed = tokio::time::timeout(std::time::Duration::from_secs(FLOW_RUN_TIMEOUT_SECS), run);diff --git a/crates/openhuman-core/src/flows/ops/resume.rs b/crates/openhuman-core/src/flows/ops/resume.rsindex 9e9263a0d8..e6562887e1 100644--- a/crates/openhuman-core/src/flows/ops/resume.rs+++ b/crates/openhuman-core/src/flows/ops/resume.rs@@ -208,8 +208,14 @@ pub async fn flows_resume(}let compiled = tinyflows::compiler::compile(&flow.graph).map_err(|e| e.to_string())?;let config_arc = Arc::new(config.clone());- let caps =- crate::flows::tinyflows::build_capabilities(config_arc.clone(), format!("flow:{flow_id}"));+ let caps = crate::flows::tinyflows::build_capabilities(+ config_arc.clone(),+ format!("flow:{flow_id}"),+ Some(FlowRunContext {+ flow_id: flow_id.to_string(),+ run_id: thread_id.to_string(),+ }),+ );let checkpointer =crate::flows::tinyflows::open_flow_checkpointer(config).map_err(|e| e.to_string())?;@@ -291,26 +297,20 @@ pub async fn flows_resume(// `error` port (recovery branch) or, if it has none, fails the run. The// empty-rejections case is byte-for-byte the prior approve-only resume.//- // Same flow/run correlation scope as `flows_run` (see its comment) — a- // resumed run can dispatch further tool calls that park, and those parks- // need `source_context` too.- let run = APPROVAL_FLOW_RUN_CONTEXT.scope(- FlowRunContext {- flow_id: flow_id.to_string(),- run_id: thread_id.to_string(),- },- with_origin(- origin,- tinyflows::engine::resume_with_checkpointer_journaled_observed(- &compiled,- &caps,- checkpointer,- thread_id,- approvals,- rejections,- journal.clone(),- &observer,- ),+ // Same flow/run correlation as `flows_run` (see its comment), carried by the+ // capabilities above -- a resumed run can dispatch further tool calls that+ // park, and those parks need `source_context` too.+ let run = with_origin(+ origin,+ tinyflows::engine::resume_with_checkpointer_journaled_observed(+ &compiled,+ &caps,+ checkpointer,+ thread_id,+ approvals,+ rejections,+ journal.clone(),+ &observer,),);diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs b/crates/openhuman-core/src/flows/tinyflows/caps/agent.rsindex 5fd2329b32..f988b1fc3e 100644--- a/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs+++ b/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs@@ -68,6 +68,9 @@ use crate::inference::provider::{is_raw_passthrough_model, role_for_model_tier};/// caller's task), so HITL gating still applies to every fanned-out turn.pub struct OpenHumanAgentRunner {pub config: Arc<Config>,+ /// The run's approval context (flow run correlation), handed to the gate+ /// with every acting dispatch.+ pub approval: crate::security::approval::ApprovalTurnContext,}/// Process-wide ceiling on **simultaneous harness agent turns started by flow@@ -449,10 +452,10 @@ impl OpenHumanAgentRunner {> = if let Some(escalated) = escalated_origin {Box::pin(turn_origin::with_origin(escalated,- agent.run_single(&prompt),+ agent.run_single_with_approval(&prompt, None, self.approval.clone()),))} else {- Box::pin(agent.run_single(&prompt))+ Box::pin(agent.run_single_with_approval(&prompt, None, self.approval.clone()))};// A host agent's turn reads its own context (config, domains, tool// groups, session store); the origin task-local is untouched.diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/code.rs b/crates/openhuman-core/src/flows/tinyflows/caps/code.rsindex 4311aa2e02..2fc1a4bed0 100644--- a/crates/openhuman-core/src/flows/tinyflows/caps/code.rs+++ b/crates/openhuman-core/src/flows/tinyflows/caps/code.rs@@ -45,6 +45,9 @@ use tinybox_bus::CommandClass;pub struct OpenHumanCode {pub config: Arc<Config>,pub security: Arc<SecurityPolicy>,+ /// The run's approval context (flow run correlation), handed to the gate+ /// with every acting dispatch.+ pub approval: crate::security::approval::ApprovalTurnContext,}pub(crate) const CODE_RUN_TIMEOUT_SECS: u64 = 60;@@ -68,7 +71,8 @@ impl CodeRunner for OpenHumanCode {let summary = crate::security::approval::summarize_action("flows_code", &action);let redacted = crate::security::approval::redact_args(&action);let (gate_outcome, audit_id) =- gate_call_for_tier(tier_decision, "flows_code", &summary, redacted).await;+ gate_call_for_tier(&self.approval, tier_decision, "flows_code", &summary, redacted)+ .await;if let crate::security::approval::GateOutcome::Deny { reason } = gate_outcome {return Err(EngineError::Capability(reason));}diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/http.rs b/crates/openhuman-core/src/flows/tinyflows/caps/http.rsindex d7ba629b68..70ab5bd416 100644--- a/crates/openhuman-core/src/flows/tinyflows/caps/http.rs+++ b/crates/openhuman-core/src/flows/tinyflows/caps/http.rs@@ -46,6 +46,9 @@ pub struct OpenHumanHttp {pub security: Arc<SecurityPolicy>,pub http_config: HttpRequestConfig,pub http_creds: Arc<HttpCredentialsStore>,+ /// The run's approval context (flow run correlation), handed to the gate+ /// with every acting dispatch.+ pub approval: crate::security::approval::ApprovalTurnContext,}/// Resolves an optional HTTP `connection_ref` to the stored credential to@@ -181,7 +184,8 @@ impl HttpClient for OpenHumanHttp {let summary = crate::security::approval::summarize_action(TOOL_NAME, &request);let redacted = crate::security::approval::redact_args(&request);let (outcome, audit_id) =- gate_call_for_tier(tier_decision, TOOL_NAME, &summary, redacted).await;+ gate_call_for_tier(&self.approval, tier_decision, TOOL_NAME, &summary, redacted)+ .await;if let crate::security::approval::GateOutcome::Deny { reason } = outcome {return Err(EngineError::Capability(reason));}diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/ops.rs b/crates/openhuman-core/src/flows/tinyflows/caps/ops.rsindex e016ed3b08..c76514098c 100644--- a/crates/openhuman-core/src/flows/tinyflows/caps/ops.rs+++ b/crates/openhuman-core/src/flows/tinyflows/caps/ops.rs@@ -382,6 +382,9 @@ pub(crate) async fn resolve_composio_account(pub struct OpenHumanTools {pub config: Arc<Config>,pub security: Arc<SecurityPolicy>,+ /// The run's approval context (flow run correlation), handed to the gate+ /// with every acting dispatch.+ pub approval: crate::security::approval::ApprovalTurnContext,}/// Required-arg preflight for a Composio `tool_call`: fails **before** the@@ -581,6 +584,7 @@ impl ToolInvoker for OpenHumanTools {let ctx = tools::ToolCallCtx {config: &self.config,security: &self.security,+ approval: &self.approval,};match tools::backend_for(slug) {Some(backend) => backend.invoke(&ctx, slug, args, conn).await,@@ -600,7 +604,20 @@ impl ToolInvoker for OpenHumanTools {/// per-flow namespace (e.g. `"flow:<id>"`). This KV namespace is unrelated to/// flow-scoped memory: `OpenHumanMemory` tags memory items with/// `flows::flow_tag`, derived independently from the run's trusted origin.-pub fn build_capabilities(config: Arc<Config>, state_namespace: impl Into<String>) -> Capabilities {+///+/// `flow_run` is the run the capabilities serve: every acting dispatch hands it+/// to the approval gate (with the tool call), so a parked approval is stamped+/// with the exact flow and run. `None` for a run with no flow identity (a dry+/// run, a preview).+pub fn build_capabilities(+ config: Arc<Config>,+ state_namespace: impl Into<String>,+ flow_run: Option<crate::security::approval::FlowRunContext>,+) -> Capabilities {+ let approval = crate::security::approval::ApprovalTurnContext {+ flow_run,+ ..Default::default()+ };let security = Arc::new(SecurityPolicy::from_config(&config.autonomy,&config.workspace_dir,@@ -616,20 +633,24 @@ pub fn build_capabilities(config: Arc<Config>, state_namespace: impl Into<Stringtools: Arc::new(OpenHumanTools {config: config.clone(),security: security.clone(),+ approval: approval.clone(),}),http: Arc::new(OpenHumanHttp {security: security.clone(),http_config,http_creds,+ approval: approval.clone(),}),code: Arc::new(OpenHumanCode {config: config.clone(),security: security.clone(),+ approval: approval.clone(),}),state: crate::flows::tinyflows::state::FlowState::open(&config, state_namespace).into_state_store(),agent: Some(Arc::new(OpenHumanAgentRunner {config: config.clone(),+ approval: approval.clone(),})),// Shell execution needs a dedicated OpenHuman adapter that applies the// host's autonomy and sandbox policy. Keep the capability unavailable@@ -654,6 +675,7 @@ pub fn build_capabilities(config: Arc<Config>, state_namespace: impl Into<Stringcrate::flows::tinyflows::memory_adapter::OpenHumanMemory {config: config.clone(),security,+ approval,},)),resolver: Arc::new(OpenHumanWorkflowResolver { config }),diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio.rs b/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio.rsindex b84254a681..53b09cfadf 100644--- a/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio.rs+++ b/crates/openhuman-core/src/flows/tinyflows/caps/tools/composio.rs@@ -172,7 +172,7 @@ impl ToolBackend for ComposioToolBackend {let (outcome, audit_id) = if tier_decision == GateDecision::Allow {(crate::security::approval::GateOutcome::Allow, None)} else {- super::super::gate_call_for_tier(tier_decision, slug, &summary, redacted).await+ super::super::gate_call_for_tier(ctx.approval, tier_decision, slug, &summary, redacted).await};if let crate::security::approval::GateOutcome::Deny { reason } = outcome {tracing::warn!(diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/tools/mod.rs b/crates/openhuman-core/src/flows/tinyflows/caps/tools/mod.rsindex 9174914d81..e3c28e390e 100644--- a/crates/openhuman-core/src/flows/tinyflows/caps/tools/mod.rs+++ b/crates/openhuman-core/src/flows/tinyflows/caps/tools/mod.rs@@ -50,6 +50,8 @@ pub(crate) struct ToolCallCtx<'a> {pub config: &'a Config,/// The autonomy tier / approval policy in force for this run.pub security: &'a SecurityPolicy,+ /// The run's approval context, handed to the gate with each acting call.+ pub approval: &'a crate::security::approval::ApprovalTurnContext,}/// One `tool_call` slug namespace.diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/tools/native.rs b/crates/openhuman-core/src/flows/tinyflows/caps/tools/native.rsindex 26c8a60918..06cb06d465 100644--- a/crates/openhuman-core/src/flows/tinyflows/caps/tools/native.rs+++ b/crates/openhuman-core/src/flows/tinyflows/caps/tools/native.rs@@ -49,7 +49,8 @@ impl ToolBackend for NativeToolBackend {let summary = crate::security::approval::summarize_action(tool_name, &args);let redacted = crate::security::approval::redact_args(&args);let (outcome, audit_id) =- super::super::gate_call_for_tier(tier_decision, tool_name, &summary, redacted).await;+ super::super::gate_call_for_tier(ctx.approval, tier_decision, tool_name, &summary, redacted)+ .await;if let crate::security::approval::GateOutcome::Deny { reason } = outcome {return Err(EngineError::Capability(reason));}diff --git a/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs b/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rsindex 42a01b97a8..5d1db2d475 100644--- a/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs+++ b/crates/openhuman-core/src/flows/tinyflows/memory_adapter.rs@@ -67,6 +67,8 @@ const LOG_PREFIX: &str = "[memory-node-host]";pub struct OpenHumanMemory {pub(crate) config: Arc<Config>,pub(crate) security: Arc<SecurityPolicy>,+ /// The run's approval context (flow run correlation).+ pub(crate) approval: crate::security::approval::ApprovalTurnContext,}impl OpenHumanMemory {@@ -143,7 +145,8 @@ impl OpenHumanMemory {let summary = summarize_action(&tool_name, action);let redacted = redact_args(action);let (outcome, audit_id) =- gate_call_for_tier(tier_decision, &tool_name, &summary, redacted).await;+ gate_call_for_tier(&self.approval, tier_decision, &tool_name, &summary, redacted)+ .await;if let GateOutcome::Deny { reason } = outcome {tracing::warn!(target: "flows", op, "{LOG_PREFIX} write: approval gate denied");return Err(EngineError::Capability(reason));