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
chore: files changed crates/openhuman-core/src/security/approval/gate_intercept.rs,crates/openhuman-
Steven Enamakel587bd4a7f443
diff --git a/crates/openhuman-core/src/agent/progress_tracing/collector/generation_tests.rs b/crates/openhuman-core/src/agent/progress_tracing/collector/generation_tests.rsnew file mode 100644index 0000000000..32700b5ea1--- /dev/null+++ b/crates/openhuman-core/src/agent/progress_tracing/collector/generation_tests.rs@@ -0,0 +1,77 @@+use super::*;++#[test]+fn model_label_skips_an_empty_provider() {+ assert_eq!(model_label("managed", "chat-v1"), "managed.chat-v1");+ assert_eq!(+ model_label("", "openrouter/deepseek/deepseek-v4-flash"),+ "openrouter/deepseek/deepseek-v4-flash"+ );+ assert_eq!(model_label(" ", "m"), "m");+}++#[test]+fn resolve_model_falls_back_for_an_empty_name() {+ assert_eq!(resolve_model("gpt-4o", Some("other")), "gpt-4o");+ assert_eq!(resolve_model("", Some("deepseek")), "deepseek");+ assert_eq!(resolve_model(" ", None), "unknown");+}++#[test]+fn prompt_inclusive_usage_is_kept() {+ // deepseek/OpenRouter route: input already counts the cache read.+ let usage = normalize_usage(66_732, 484, 64_768, 0);+ assert!(!usage.widened);+ assert_eq!(usage.input_total, 66_732);+ assert_eq!(usage.input_uncached, 1_964);+ assert_eq!(usage.total, 67_216);+}++#[test]+fn uncached_only_input_is_widened() {+ // Claude Code route: Anthropic's raw `input_tokens` is the uncached+ // remainder, so the reported total used to be smaller than the cache read.+ let usage = normalize_usage(12, 300, 40_000, 2_000);+ assert!(usage.widened);+ assert_eq!(usage.input_total, 42_012);+ assert_eq!(usage.input_uncached, 12);+ assert_eq!(usage.cache_read, 40_000);+ assert_eq!(usage.cache_creation, 2_000);+ assert_eq!(usage.total, 42_312);+ assert_eq!(+ usage.total,+ usage.input_uncached + usage.cache_read + usage.cache_creation + usage.output+ );+}++#[test]+fn placeholder_cost_for_unpriced_model_is_dropped() {+ let model = "acme/never-heard-of-it";+ let placeholder = crate::agent::cost::estimate_call_cost_usd(+ model,+ &BilledUsage::from_counts(1_000, 100).with_cached_input_tokens(200),+ );+ assert!(placeholder > 0.0);+ assert_eq!(+ effective_cost(model, 1_000, 100, 200, placeholder),+ (0.0, CostSource::Unpriced)+ );+ // A provider charge is not the placeholder and is kept.+ assert_eq!(+ effective_cost(model, 1_000, 100, 200, 0.5),+ (0.5, CostSource::Priced)+ );+ // Free variants are a known zero price.+ assert_eq!(+ effective_cost("x/y:free", 1_000, 100, 0, 0.0),+ (0.0, CostSource::Priced)+ );+}++#[test]+fn single_delta_at_completion_is_unstreamed() {+ assert!(is_unstreamed(4_990, 1_000, 5_000));+ assert!(!is_unstreamed(1_300, 1_000, 5_000));+ // A fast call is not second-guessed.+ assert!(!is_unstreamed(1_050, 1_000, 1_060));+}diff --git a/crates/openhuman-core/src/agent/progress_tracing/journal_replay_tests.rs b/crates/openhuman-core/src/agent/progress_tracing/journal_replay_tests.rsnew file mode 100644index 0000000000..4113035a2b--- /dev/null+++ b/crates/openhuman-core/src/agent/progress_tracing/journal_replay_tests.rs@@ -0,0 +1,52 @@+use super::*;+use tinyagents_harness::terminal::TerminalReason;++#[test]+fn user_message_text_reads_the_last_user_message_in_both_shapes() {+ let role_tagged = serde_json::json!([+ {"role": "system", "content": "You are OpenHuman."},+ {"role": "user", "content": "first question"},+ {"role": "assistant", "content": "answer"},+ {"role": "user", "content": "follow-up"}+ ]);+ assert_eq!(user_message_text(&role_tagged), "follow-up");++ let crate_tagged = serde_json::json!([+ {"system": {"content": [{"text": "sys"}]}},+ {"user": {"content": [{"text": "build me a workflow"}, {"image": {}}]}}+ ]);+ assert_eq!(user_message_text(&crate_tagged), "build me a workflow");+}++#[test]+fn user_message_text_falls_back_without_a_user_message() {+ assert_eq!(user_message_text(&serde_json::json!("plain")), "plain");+ assert_eq!(+ user_message_text(&serde_json::json!({"content": "obj"})),+ "obj"+ );+}++#[test]+fn failure_outcome_maps_terminal_class() {+ let cancelled = TerminalOutcome::new(TerminalReason::Cancelled, "user stopped");+ assert_eq!(+ turn_outcome_for_failure("ignored", Some(&cancelled)),+ TurnOutcome::Cancelled {+ reason: Some("user stopped".into())+ }+ );+ let timeout = TerminalOutcome::new(TerminalReason::Timeout, "deadline");+ assert_eq!(+ turn_outcome_for_failure("ignored", Some(&timeout)),+ TurnOutcome::TimedOut {+ message: "deadline".into()+ }+ );+ assert_eq!(+ turn_outcome_for_failure("provider down", None),+ TurnOutcome::Failed {+ message: "provider down".into()+ }+ );+}diff --git a/crates/openhuman-core/src/security/approval/gate_intercept.rs b/crates/openhuman-core/src/security/approval/gate_intercept.rsindex 5d07530977..718dee0c19 100644--- a/crates/openhuman-core/src/security/approval/gate_intercept.rs+++ b/crates/openhuman-core/src/security/approval/gate_intercept.rs@@ -250,13 +250,28 @@ impl ApprovalGate {} => Some((thread_id.clone(), client_id.clone())),_ => None,};- if chat_ctx.is_none() && origin_chat_route.is_some() {+ // The fallback is taken exactly when the park runs on a task detached+ // from the chat turn that shows it — an async-delegated sub-agent. Such+ // a park can outlive that turn (the parent replies "I've asked the+ // image agent…" and its `chat_done` fires while the child still waits+ // here), so the surface is told the card is `detached`: the frontend+ // keeps it across the parent's turn end instead of clearing it as a+ // park that "cannot outlive its turn" — the clear that left every+ // async `image_agent` / `video_agent` approval invisible until it+ // expired at 600s.+ let detached = !forced && chat_ctx.is_none() && origin_chat_route.is_some();+ if detached {tracing::debug!(tool = tool_name,"[approval::gate] APPROVAL_CHAT_CONTEXT absent on a WebChat turn — routing the \- approval via the origin's thread/client (async-delegated sub-agent path, #5499)"+ approval via the origin's thread/client (async-delegated sub-agent path, #5499); \+ marking the card detached so it survives the parent turn's end");}+ // Any park raised inside a sub-agent run — detached or inline — gets+ // the shorter `SUBAGENT_APPROVAL_TTL` window.+ let subagent_park = !forced+ && (detached || crate::agent::harness::spawn_depth_context::current_spawn_depth() > 0);let chat_thread_id = chat_ctx.as_ref().map(|c| c.thread_id.clone())@@ -412,7 +427,8 @@ impl ApprovalGate {// waiting 180s, so a core restart or an `expire_stale` sweep mid-park// could leave the row "actionable" for the wrong window (CodeRabbit// + Codex review on PR #5112).- let effective_ttl = Self::resolve_park_ttl(self.effective_ttl(), copilot_stream);+ let effective_ttl =+ Self::resolve_park_ttl(self.effective_ttl(), copilot_stream, subagent_park);let expires_at = Some(now + chrono::Duration::from_std(effective_ttl).unwrap_or_default());// Correlation context (flow-approval-surface, PR2): a Workflow-origin@@ -480,6 +496,7 @@ impl ApprovalGate {tool_call_id: tool_call_id.map(str::to_string),forced,agent_id: agent_id.clone(),+ detached,},);if let Err(err) = store::insert_pending(&self.config, &pending, &self.session_id) {@@ -520,6 +537,7 @@ impl ApprovalGate {tool_call_id: tool_call_id.map(str::to_string),expires_at: expires_at.map(|t| t.to_rfc3339()),agent_id: agent_id.clone(),+ detached,});// Flow-origin surface bridge (flow-approval-surface, PR3): a flow run@@ -597,6 +615,14 @@ impl ApprovalGate {COPILOT_APPROVAL_TTL");}+ if subagent_park {+ tracing::debug!(+ tool = tool_name,+ detached,+ ttl_secs = effective_ttl.as_secs(),+ "[approval::gate] sub-agent park — clamping park window to SUBAGENT_APPROVAL_TTL"+ );+ }// Optional caller-supplied park bound (issue #4756). A caller// (`composio_connect`) can cap how long the gate parks so a turndiff --git a/crates/openhuman-core/src/security/approval/gate_intercept_decision.rs b/crates/openhuman-core/src/security/approval/gate_intercept_decision.rsindex 737d15cdb7..6eae5a8982 100644--- a/crates/openhuman-core/src/security/approval/gate_intercept_decision.rs+++ b/crates/openhuman-core/src/security/approval/gate_intercept_decision.rs@@ -172,8 +172,10 @@ impl ApprovalGate {GateOutcome::Deny {reason: format!("{POLICY_DENIED_MARKER} Approval for '{tool_name}' timed out after \- {}s. Do not re-request the same call this turn; take a different \- approach or stop.",+ {}s: {APPROVAL_UNANSWERED_PHRASE}, so it was not run. Tell the \+ user it was not done because the approval was not answered, and \+ that they can ask again to retry. Do not re-request the same call \+ this turn.",effective_ttl.as_secs()),},