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(security): prevent approval bypass when gate intercept is missing
Steven Enamakelc904d68749d4
diff --git a/crates/openhuman-core/src/agent/turn_origin.rs b/crates/openhuman-core/src/agent/turn_origin.rsindex e2cc199f2a..1c0d6a8d16 100644--- a/crates/openhuman-core/src/agent/turn_origin.rs+++ b/crates/openhuman-core/src/agent/turn_origin.rs@@ -1,7 +1,7 @@//! Agent turn origin — the trust/routing label attached to every agent//! `run_turn` invocation. Read by [`crate::security::approval::ApprovalGate`]//! and [`crate::tools::agent_policy::ToolPolicyEngine`] to make-//! consistent decisions across web, channel, subconscious, and cron entry+//! consistent decisions across web, channel, cron, and background entry//! points without relying on the *absence* of other task-locals as a signal.//!//! Every entry point that drives the agent loop ([`crate::web_chat`],@@ -54,7 +54,7 @@ pub enum AgentTurnOrigin {message_id: String,},/// Internal automation the user explicitly authorized (cron job the- /// user created, subconscious tick on internal-only memory). `source`+ /// user created, internal background job on local data). `source`/// carries enough info for the gate to apply the right per-source/// allowlist.TrustedAutomation {@@ -88,15 +88,9 @@ pub enum AgentTurnOrigin {pub enum TrustedAutomationSource {/// Cron job created and authorized by the user.Cron,- /// Subconscious tick whose memory context is internal-only.- Subconscious,- /// Subconscious tick whose memory context includes chunks ingested- /// from an external sync source (Gmail / Slack / Notion / etc.).- /// Treated as untrusted: external-effect tool surface blocked.- SubconsciousTainted,- /// Autonomous continuation of a thread goal: the heartbeat injected a turn- /// to keep working an idle `active` goal the user explicitly created.- GoalContinuation,+ /// Internal background job over locally-stored data (e.g. goals+ /// enrichment). No external content reaches its prompt.+ Background,/// A saved, enabled `flows::Flow` (tinyflows workflow) executing via/// `flows::ops::flows_run` / `flows_resume` (issue B2, see/// `my_docs/ohxtf/b2-triggers-trust/01-triggers-and-trust.md` §3). The@@ -111,8 +105,7 @@ pub enum TrustedAutomationSource {Workflow {/// Mirrors `Flow::require_approval`: when `true` the gate does NOT/// auto-allow this trust root — every external_effect call still- /// parks for a real decision (same shape as `GoalContinuation`),- /// letting a user force human review on a specific flow's outbound+ /// parks for a real decision, letting a user force human review on a specific flow's outbound/// actions regardless of the trust root above.require_approval: bool,},@@ -145,8 +138,7 @@ impl AgentTurnOrigin {////// `WebChat`, `ExternalChannel`, and `DirectChat` carry what a human sent./// Every other origin carries text the host wrote for an agent to act on: a- /// `TrustedAutomation` prompt (cron, subconscious, goal continuation,- /// workflow), a `Cli` invocation — which this module documents as+ /// `TrustedAutomation` prompt (cron, background job, workflow), a `Cli` invocation — which this module documents as/// "command-line / **sub-agent** / one-off internal" — or an unscoped/// `Unknown`.///@@ -180,7 +172,7 @@ pub fn current_is_user_authored() -> bool {tokio::task_local! {/// Per-turn agent origin. Scoped by entry points (web channel, channel- /// runtime dispatch, subconscious loop, cron scheduler, CLI) around the+ /// runtime dispatch, cron scheduler, background jobs, CLI) around the/// `run_turn` invocation. Read by the approval gate to make/// origin-aware decisions.pub static AGENT_TURN_ORIGIN: AgentTurnOrigin;@@ -196,8 +188,8 @@ tokio::task_local! {/// streaming), and stacking two task-local scopes plus the agent loop on a/// 2 MiB worker stack reliably blows the test runtime — same shape as the/// fix in PR #3151. Box-pinning here is the single-point remediation that-/// covers every caller (web channel, channel runtime, subconscious, cron,-/// CLI).+/// covers every caller (web channel, channel runtime, cron, background+/// jobs, CLI).pub async fn with_origin<F: std::future::Future>(origin: AgentTurnOrigin, fut: F) -> F::Output {AGENT_TURN_ORIGIN.scope(origin, Box::pin(fut)).await}diff --git a/crates/openhuman-core/src/memory/goals/enrich.rs b/crates/openhuman-core/src/memory/goals/enrich.rsindex 57d2fd5b19..2a6f9febe4 100644--- a/crates/openhuman-core/src/memory/goals/enrich.rs+++ b/crates/openhuman-core/src/memory/goals/enrich.rs@@ -129,8 +129,8 @@ pub async fn enrich_goals(let origin = AgentTurnOrigin::TrustedAutomation {job_id,// Internal curation of locally-stored goals — no external content- // is forwarded to external-effect tools, so the untainted source.- source: TrustedAutomationSource::Subconscious,+ // is forwarded to external-effect tools.+ source: TrustedAutomationSource::Background,};let response = with_origin(origin, agent.run_single(&prompt))diff --git a/crates/openhuman-core/src/security/approval/gate_intercept.rs b/crates/openhuman-core/src/security/approval/gate_intercept.rsindex 29c1838751..80b4a068df 100644--- a/crates/openhuman-core/src/security/approval/gate_intercept.rs+++ b/crates/openhuman-core/src/security/approval/gate_intercept.rs@@ -302,8 +302,7 @@ impl ApprovalGate {"[approval::gate] workflow run has require_approval enabled — parking for \HITL review instead of auto-allowing the trust root");- // Fall through to the parking flow (same shape as- // GoalContinuation): persists a `pending_approvals` audit row+ // Fall through to the parking flow: persists a `pending_approvals` audit row// and publishes `ApprovalRequested`. There is no chat thread to// route the prompt to for a background/triggered flow run yet// (B3 will add a dedicated review surface) — a caller can still@@ -368,7 +367,7 @@ impl ApprovalGate {// that comes from the `APPROVAL_FLOW_RUN_CONTEXT` task-local// `flows::ops::flows_run`/`flows_resume` scope alongside `with_origin`.// `try_with` returns `Err` for every non-flow caller (chat, cron,- // subconscious, CLI, and even a Workflow origin reached without the+ // background jobs, CLI, and even a Workflow origin reached without the// flows module's scope, which "should never happen" but must not// panic), so `source_context` stays `None` there — unchanged chat// behavior.