Skip to content

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

fix(mirror_observe_tests): correct test assertions for mirror observation

Steven Enamakelcec07d865782
diff --git a/crates/openhuman-core/src/threads/turn_state/mirror_observe_tests.rs b/crates/openhuman-core/src/threads/turn_state/mirror_observe_tests.rs
index e8a35c2100..fc7420671d 100644
--- a/crates/openhuman-core/src/threads/turn_state/mirror_observe_tests.rs
+++ b/crates/openhuman-core/src/threads/turn_state/mirror_observe_tests.rs
@@ -619,3 +619,114 @@ fn thinking_timing_wire_shape_is_camel_case_and_backward_compatible() {
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,
+ });
+
+ 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"));
+}