Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

merge: resolve main conflicts for PR 8171

Steven Enamakela0ca390a16ed
diff --cc crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
index 9d8c1dacb8,9599ae2a22..4208096fd9
--- a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
@@@ -432,133 -432,4 +432,135 @@@ fn emit_recovered_unknown_tool_call(sin
});
}
+#[tokio::test]
+async fn unknown_tool_call_projects_exactly_one_failed_timeline_row() {
+ // Production Langfuse showed two ERROR tool observations ~15ms apart for
+ // every unknown-tool call: the bridge synthesised a Started/Completed pair
+ // off `UnknownToolCall` (null output, NotFound copy) and the crate's own
+ // recovered pair produced a second one carrying the error text. Exactly
+ // one row per call, carrying the error text and the NotFound class.
+ let (tx, mut rx) = tokio::sync::mpsc::channel(64);
+ let bridge = OpenhumanEventBridge::new(Some(tx), "mock-model", 10);
+ let sink = EventSink::new();
+ sink.subscribe(bridge.clone());
+
+ emit_recovered_unknown_tool_call(&sink, "c9");
+
+ let mut started = Vec::new();
+ let mut completed = Vec::new();
+ while let Ok(p) = rx.try_recv() {
+ match p {
+ AgentProgress::ToolCallStarted {
+ tool_name,
+ display_label,
+ ..
+ } => started.push((tool_name, display_label)),
+ AgentProgress::ToolCallCompleted {
+ tool_name,
+ success,
+ failure,
+ output,
+ display_label,
+ ..
+ } => completed.push((tool_name, success, failure, output, display_label)),
+ _ => {}
+ }
+ }
+ assert_eq!(started.len(), 1, "exactly one started row: {started:?}");
+ assert_eq!(completed.len(), 1, "exactly one completed row");
+ assert_eq!(started[0].0, "search_files");
+ assert_eq!(
+ started[0].1.as_deref(),
+ Some("Search Files (unavailable)"),
+ "the timeline still says the tool was unavailable"
+ );
+ let (tool_name, success, failure, output, label) = completed.remove(0);
+ assert_eq!(tool_name, "search_files");
+ assert!(!success, "the attempted tool is projected as a failed call");
+ assert_eq!(
+ output, UNKNOWN_TOOL_ANSWER,
+ "the row carries the error text"
+ );
+ assert_eq!(label.as_deref(), Some("Search Files (unavailable)"));
+ // #6277: a tool the agent does not have fails identically on every retry,
+ // so the timeline must not tell the user to "try again / run diagnostics".
+ let failure = failure.expect("the failed row carries a classified failure");
+ assert_eq!(
+ failure.class,
+ tinytools::status::ToolFailureClass::NotFound,
+ "an unavailable tool must be classified NotFound, not Unknown"
+ );
+ assert!(!failure.recoverable);
+}
+
+#[tokio::test]
+async fn unknown_tool_call_alone_projects_no_tool_row() {
+ // The typed event only annotates the call; the crate's recovered pair is
+ // what opens and closes the row.
+ let (tx, mut rx) = tokio::sync::mpsc::channel(64);
+ let bridge = OpenhumanEventBridge::new(Some(tx), "mock-model", 10);
+ let sink = EventSink::new();
+ sink.subscribe(bridge.clone());
+
+ sink.emit(AgentEvent::UnknownToolCall {
+ call_id: "c9".into(),
+ requested_name: "search_files".to_string(),
+ arguments: serde_json::json!({}),
+ recovery: "tool_error".to_string(),
+ });
+ while let Ok(p) = rx.try_recv() {
+ assert!(
+ !matches!(
+ p,
+ AgentProgress::ToolCallStarted { .. } | AgentProgress::ToolCallCompleted { .. }
+ ),
+ "UnknownToolCall must not synthesise its own tool row"
+ );
+ }
+}
+
+#[tokio::test]
+async fn unknown_tool_call_in_a_child_run_projects_one_subagent_row() {
+ let (tx, mut rx) = tokio::sync::mpsc::channel(64);
+ let bridge = OpenhumanEventBridge::with_scope(
+ Some(tx),
+ "mock-model",
+ "managed",
+ 10,
+ Some(super::SubagentScope {
+ agent_id: "researcher".to_string(),
+ task_id: "task-1".to_string(),
+ extended_policy: false,
+ }),
+ Arc::default(),
+ Arc::default(),
+ Arc::default(),
+ Arc::default(),
+ Vec::new(),
+ crate::core::runtime::DispatchCtx::ambient(),
+ );
+ let sink = EventSink::new();
+ sink.subscribe(bridge.clone());
+
+ emit_recovered_unknown_tool_call(&sink, "c10");
+
+ let (mut started, mut completed) = (0, 0);
+ let mut class = None;
+ while let Ok(p) = rx.try_recv() {
+ match p {
+ AgentProgress::SubagentToolCallStarted { .. } => started += 1,
+ AgentProgress::SubagentToolCallCompleted { failure, .. } => {
+ completed += 1;
+ class = failure.map(|f| f.class);
+ }
+ _ => {}
+ }
+ }
+ assert_eq!((started, completed), (1, 1));
+ assert_eq!(class, Some(tinytools::status::ToolFailureClass::NotFound));
+}
+
+#[path = "observability_projection_tests.rs"]
+mod projection_tests;
++
+ include!("observability_tests_tool_rows.rs");
diff --cc crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
index 11fd112b93,74cd31cd88..9a25bc988a
--- a/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
@@@ -379,139 -379,4 +379,141 @@@ fn try_create_local_runtime_returns_non
assert!(try_create_local_runtime_chat_model("chat", &cloud, &EgressLedger::none()).is_none());
}
+#[test]
+fn create_chat_model_routes_plain_bearer_cloud_slug_to_crate_native() {
+ let _guard = crate::inference::inference_test_guard();
+ // DeepSeek is a built-in chat-completions-only Bearer provider: no
+ // `/v1/responses` fallback and no codex-oauth, so it is wire-equivalent and
+ // flips crate-native.
+ let mut config = Config::default();
+ config.cloud_providers.push(deepseek_entry("p_ds"));
+ config.chat_provider = Some("deepseek:deepseek-reasoner".to_string());
+ let (model, model_id) = create_chat_model_with_model_id_in(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ "chat",
+ &config,
+ 0.7,
+ )
+ .expect("bearer cloud create_chat_model must build");
+ assert_eq!(model_id, "deepseek-reasoner");
+ let profile = model
+ .profile()
+ .expect("crate-native cloud model exposes a profile");
+ assert_eq!(profile.provider.as_deref(), Some("deepseek"));
+ // A generic cloud model keeps native tool calling + vision on (unlike the
+ // local runtimes), so this is the crate `OpenAiModel` default profile.
+ assert!(profile.tool_calling);
+}
+
+#[test]
+fn turn_model_route_metadata_uses_post_remap_cloud_model() {
+ let _guard = crate::inference::inference_test_guard();
+ let mut config = Config::default();
+ config.cloud_providers.push(deepseek_entry("p_ds"));
+ config.chat_provider = Some("deepseek:hint:chat".to_string());
+
+ let (_model, provider, resolved_model) = create_turn_chat_model_with_native_tools_and_route(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ "chat",
+ &config,
+ "hint:chat",
+ 0.7,
+ true,
+ &EgressLedger::none(),
+ )
+ .expect("abstract BYOK tier must build");
+
+ assert_eq!(provider, "deepseek");
+ assert_eq!(resolved_model, "deepseek-chat");
+}
+
+#[test]
+fn explicit_cloud_provider_string_routes_to_crate_native_model() {
+ let _guard = crate::inference::inference_test_guard();
+ let mut config = Config::default();
+ config.cloud_providers.push(deepseek_entry("p_ds"));
+ let (model, model_id) = create_chat_model_from_string_with_model_id(
+ "chat",
+ "deepseek:deepseek-reasoner",
+ &config,
+ 0.7,
+ )
+ .expect("explicit cloud model must build");
+ assert_eq!(model_id, "deepseek-reasoner");
+ assert_eq!(
+ model
+ .profile()
+ .and_then(|profile| profile.provider.as_deref()),
+ Some("deepseek")
+ );
+}
+
+#[test]
+fn create_chat_model_routes_anthropic_auth_cloud_slug_to_crate_native() {
+ let _guard = crate::inference::inference_test_guard();
+ // Anthropic-auth cloud slugs are always wire-equivalent (their endpoints have
+ // no `/v1/responses`, so the host's dormant fallback is behavior-neutral).
+ let mut config = Config::default();
+ config
+ .cloud_providers
+ .push(anthropic_entry("p_anth", "anthropic"));
+ config.chat_provider = Some("anthropic:claude-sonnet-4-6".to_string());
+ let (model, model_id) = create_chat_model_with_model_id_in(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ "chat",
+ &config,
+ 0.7,
+ )
+ .expect("anthropic cloud create_chat_model must build");
+ assert_eq!(model_id, "claude-sonnet-4-6");
+ assert_eq!(
+ model.profile().and_then(|p| p.provider.as_deref()),
+ Some("anthropic")
+ );
+ // The native Messages API adapter, not the OpenAI-compat flavour: its
+ // cache identity is `anthropic:<base>:<model>`, while the compat client
+ // would report the provider slug with an OpenAI-shaped identity. Only the
+ // native adapter places `cache_control` breakpoints — Anthropic's compat
+ // endpoint documents prompt caching as unsupported.
+ let identity = model.cache_identity().expect("anthropic identifies itself");
+ assert!(
+ identity.starts_with("anthropic:https://api.anthropic.com/v1:claude-sonnet-4-6"),
+ "expected the native Messages adapter, got identity {identity}"
+ );
+ assert!(model
+ .profile()
+ .is_some_and(|p| p.tool_calling && p.streaming));
+}
+
+/// Text mode (prompt-guided tools) is only implemented on the Chat Completions
+/// adapter, so an Anthropic slug asked for `native_tools = false` keeps the
+/// compat client rather than a native adapter that would ignore the request.
+#[test]
+fn anthropic_auth_cloud_slug_in_text_mode_keeps_the_compat_client() {
+ let _guard = crate::inference::inference_test_guard();
+ let mut config = Config::default();
+ config
+ .cloud_providers
+ .push(anthropic_entry("p_anth", "anthropic"));
+ let (model, model_id) = try_create_cloud_slug_chat_model_from_string_with_native_tools(
+ "chat",
+ "anthropic:claude-sonnet-4-6",
+ &config,
+ false,
+ &EgressLedger::none(),
+ )
+ .expect("anthropic slug resolves")
+ .expect("build");
+ assert_eq!(model_id, "claude-sonnet-4-6");
+ let identity = model.cache_identity().unwrap_or_default();
+ assert!(
+ !identity.starts_with("anthropic:https://"),
+ "text mode must not route to the native adapter, got {identity}"
+ );
+ assert!(model.profile().is_some_and(|p| !p.tool_calling));
+}
+
+#[path = "factory_crate_native_managed_slug_tests.rs"]
+mod managed_slug_tests;
++
+ include!("factory_crate_native_cloud_tests.rs");
diff --cc crates/openhuman-core/src/threads/turn_state/mirror_observe_tests.rs
index 90f1b24dec,f1a2a13bbe..65229d99f0
--- a/crates/openhuman-core/src/threads/turn_state/mirror_observe_tests.rs
+++ b/crates/openhuman-core/src/threads/turn_state/mirror_observe_tests.rs
@@@ -539,5 -539,204 +539,207 @@@ fn subagent_lifecycle_records_and_clear
assert!(s.active_subagent.is_none());
}
+#[path = "mirror_observe_thinking_and_subagent_tests.rs"]
+mod thinking_and_subagent_tests;
++
+ #[test]
+ fn thinking_blocks_record_start_and_end_timing() {
+ // Regression: the "Thought for Ns" label reads these; a coalesced block
+ // must keep its first-delta start and advance its end, and a new round's
+ // block must open with its own start.
+ let (_d, mut m) = fresh("t");
+ m.observe(&AgentProgress::ThinkingDelta {
+ delta: "First ".into(),
+ iteration: 1,
+ });
+ let first_start = match &m.snapshot().transcript[0] {
+ TranscriptItem::Thinking { started_at, .. } => started_at.expect("started_at stamped"),
+ other => panic!("expected thinking, got {other:?}"),
+ };
+ std::thread::sleep(std::time::Duration::from_millis(5));
+ m.observe(&AgentProgress::ThinkingDelta {
+ delta: "round.".into(),
+ iteration: 1,
+ });
+ m.observe(&AgentProgress::ThinkingDelta {
+ delta: "Second round.".into(),
+ iteration: 2,
+ });
+
+ let s = m.snapshot();
+ assert_eq!(s.transcript.len(), 2, "one block per round");
+ match &s.transcript[0] {
+ TranscriptItem::Thinking {
+ started_at,
+ ended_at,
+ text,
+ ..
+ } => {
+ assert_eq!(text, "First round.");
+ assert_eq!(*started_at, Some(first_start), "start is the first delta");
+ let end = ended_at.expect("ended_at stamped");
+ assert!(end > first_start, "end advances on coalesced deltas");
+ }
+ other => panic!("expected thinking, got {other:?}"),
+ }
+ match &s.transcript[1] {
+ TranscriptItem::Thinking {
+ started_at,
+ ended_at,
+ ..
+ } => {
+ let (start, end) = (started_at.unwrap(), ended_at.unwrap());
+ assert!(start >= first_start && end >= start);
+ }
+ other => panic!("expected thinking, got {other:?}"),
+ }
+ }
+
+ #[test]
+ fn thinking_timing_wire_shape_is_camel_case_and_backward_compatible() {
+ // The frontend reads `startedAt` / `endedAt`; rows persisted before timing
+ // existed must still deserialize (as `None`) and must not grow the fields.
+ let item = TranscriptItem::Thinking {
+ round: 1,
+ seq: 0,
+ text: "t".into(),
+ started_at: Some(1_000),
+ ended_at: Some(13_000),
+ };
+ let json = serde_json::to_value(&item).unwrap();
+ assert_eq!(json["kind"], "thinking");
+ assert_eq!(json["startedAt"], 1_000);
+ assert_eq!(json["endedAt"], 13_000);
+
+ let legacy: TranscriptItem =
+ serde_json::from_value(serde_json::json!({"kind":"thinking","round":1,"seq":0,"text":"t"}))
+ .unwrap();
+ match &legacy {
+ TranscriptItem::Thinking {
+ started_at,
+ ended_at,
+ ..
+ } => assert!(started_at.is_none() && ended_at.is_none()),
+ other => panic!("expected thinking, got {other:?}"),
+ }
+ let reserialized = serde_json::to_value(&legacy).unwrap();
+ assert!(reserialized.get("startedAt").is_none());
+ assert!(reserialized.get("endedAt").is_none());
+ }
+
+ // ── C1: parent_call_id / source_tool_name derivation ─────────────────────
+
+ #[test]
+ fn subagent_spawned_derives_source_tool_name_from_the_parent_row() {
+ // Only `spawn_subagent` ever hardcoded a "spawn_subagent" source. Every
+ // other delegation path (`spawn_parallel_agents`, `spawn_async_subagent`,
+ // a synthesized `delegate_researcher`, …) must show its own real tool
+ // name, derived from the parent call's row by `parent_call_id` — never
+ // the historical hardcoded default.
+ let (_d, mut m) = fresh("t");
+ m.observe(&AgentProgress::ToolCallStarted {
+ call_id: "call-parallel".into(),
+ tool_name: "spawn_parallel_agents".into(),
+ arguments: serde_json::json!({}),
+ iteration: 1,
+ display_label: None,
+ display_detail: None,
+ });
+ m.observe(&AgentProgress::SubagentSpawned {
+ agent_id: "researcher".into(),
+ task_id: "sub-1".into(),
+ mode: "typed".into(),
+ dedicated_thread: false,
+ prompt_chars: 4,
+ prompt: "help".into(),
+ worker_thread_id: None,
+ display_name: None,
+ parent_call_id: Some("call-parallel".into()),
+ });
+
+ let entry = m
+ .snapshot()
+ .tool_timeline
+ .iter()
+ .find(|e| e.id == "subagent:sub-1")
+ .cloned()
+ .expect("subagent row created");
+ assert_eq!(
+ entry.source_tool_name.as_deref(),
+ Some("spawn_parallel_agents")
+ );
+ let activity = entry.subagent.expect("subagent activity present");
+ assert_eq!(activity.parent_call_id.as_deref(), Some("call-parallel"));
+ }
+
+ #[test]
+ fn subagent_spawned_falls_back_to_spawn_subagent_without_a_parent_call_id() {
+ // No `parent_call_id` (e.g. the `orchestration::ops` spawn path, which
+ // has no tool-call context to read one from) keeps the historical
+ // default so existing snapshots/consumers don't regress.
+ let (_d, mut m) = fresh("t");
+ m.observe(&AgentProgress::SubagentSpawned {
+ agent_id: "researcher".into(),
+ task_id: "sub-2".into(),
+ mode: "typed".into(),
+ dedicated_thread: false,
+ prompt_chars: 4,
+ prompt: "help".into(),
+ worker_thread_id: None,
+ display_name: None,
+ parent_call_id: None,
+ });
+
+ let entry = m
+ .snapshot()
+ .tool_timeline
+ .iter()
+ .find(|e| e.id == "subagent:sub-2")
+ .cloned()
+ .expect("subagent row created");
+ assert_eq!(entry.source_tool_name.as_deref(), Some("spawn_subagent"));
+ let activity = entry.subagent.expect("subagent activity present");
+ assert_eq!(activity.parent_call_id, None);
+ }
+
+ #[test]
+ fn subagent_completed_persists_capped_output_on_the_activity() {
+ let (_d, mut m) = fresh("t");
+ m.observe(&AgentProgress::SubagentSpawned {
+ agent_id: "researcher".into(),
+ task_id: "sub-3".into(),
+ mode: "typed".into(),
+ dedicated_thread: false,
+ prompt_chars: 4,
+ prompt: "help".into(),
+ worker_thread_id: None,
+ display_name: None,
+ parent_call_id: Some("call-3".into()),
+ });
+ m.observe(&AgentProgress::SubagentCompleted {
+ agent_id: "researcher".into(),
+ task_id: "sub-3".into(),
+ elapsed_ms: 5,
+ iterations: 1,
+ output_chars: 11,
+ usage: None,
+ output: "final answer".into(),
+ worktree_path: None,
+ changed_files: Vec::new(),
+ dirty_status: None,
+ stop: None,
+ });
+
+ let entry = m
+ .snapshot()
+ .tool_timeline
+ .iter()
+ .find(|e| e.id == "subagent:sub-3")
+ .cloned()
+ .expect("subagent row created");
+ let activity = entry.subagent.expect("subagent activity present");
+ assert_eq!(activity.output.as_deref(), Some("final answer"));
+ assert_eq!(activity.parent_call_id.as_deref(), Some("call-3"));
+ }
+
+ include!("mirror_observe_compaction_tests.rs");