Skip to content

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

refactor(web_chat): route subagent progress through shared mapper

Steven Enamakelcc216ad85894
diff --git a/crates/openhuman-core/src/agent/turn_progress_tests.rs b/crates/openhuman-core/src/agent/turn_progress_tests.rs
index 77cfbf4ead..20f4572003 100644
--- a/crates/openhuman-core/src/agent/turn_progress_tests.rs
+++ b/crates/openhuman-core/src/agent/turn_progress_tests.rs
@@ -53,6 +53,45 @@ fn native_progress_mapping_leaves_subagent_lifecycle_to_its_surface() {
assert!(event.is_none(), "native delivery keeps its existing filter");
}
+#[test]
+fn shared_subagent_mapping_uses_the_callers_correlation_context() {
+ let event = subagent_event(
+ AgentProgress::SubagentSpawned {
+ agent_id: "researcher".into(),
+ task_id: "task-web".into(),
+ mode: "typed".into(),
+ dedicated_thread: false,
+ prompt_chars: 4,
+ prompt: "help".into(),
+ worker_thread_id: None,
+ display_name: Some("Researcher".into()),
+ parent_call_id: Some("event-parent-is-not-authoritative".into()),
+ },
+ 3,
+ Some("ledger-parent".into()),
+ )
+ .expect("subagent event has a canonical output");
+
+ let out = expect_subagent(event);
+ assert_eq!(out.state, "spawned");
+ assert_eq!(out.agent_id, "researcher");
+ assert_eq!(out.iteration, Some(3));
+ assert_eq!(out.parent_call_id.as_deref(), Some("ledger-parent"));
+}
+
+#[test]
+fn shared_subagent_mapping_ignores_unrelated_progress() {
+ assert!(subagent_event(
+ AgentProgress::TextDelta {
+ delta: "hello".into(),
+ iteration: 1,
+ },
+ 1,
+ None,
+ )
+ .is_none());
+}
+
#[test]
fn a_started_tool_call_keeps_small_arguments_and_nulls_empty_ones() {
let ChannelOutputEvent::ToolCallStarted { arguments, .. } = tool_started(
diff --git a/crates/openhuman-core/src/web_chat/progress_subagent.rs b/crates/openhuman-core/src/web_chat/progress_subagent.rs
index a9b1c82b1d..c70db7ea53 100644
--- a/crates/openhuman-core/src/web_chat/progress_subagent.rs
+++ b/crates/openhuman-core/src/web_chat/progress_subagent.rs
@@ -1,5 +1,4 @@
-//! The sub-agent arms of [`ProgressProjection::on_event`]: lifecycle, child
-//! tool calls and child deltas, each mirrored into the run ledger.
+//! Surface-specific logging around the shared sub-agent progress mapper.
use tinyagents_harness::progress::AgentProgress;
@@ -13,173 +12,21 @@ impl ProgressProjection {
event: AgentProgress,
ledger_context: ProgressLedgerContext,
) {
- let round = self.round;
- match event {
- AgentProgress::SubagentSpawned {
- agent_id,
- task_id,
- mode,
- dedicated_thread,
- prompt_chars,
- worker_thread_id,
- display_name,
- parent_call_id: _,
- ..
- } => {
- self.surface
- .output(map::sub_spawned(
- &agent_id,
- &task_id,
- round,
- mode,
- dedicated_thread,
- prompt_chars,
- worker_thread_id,
- display_name,
- ledger_context.parent_call_id,
- ))
- .await;
- }
- AgentProgress::SubagentCompleted {
- agent_id,
- task_id,
- elapsed_ms,
- iterations,
- output_chars,
- output,
- usage,
- worktree_path,
- changed_files,
- dirty_status,
- ..
- } => {
- self.surface
- .output(map::sub_completed(
- &agent_id,
- &task_id,
- elapsed_ms,
- iterations,
- output_chars,
- output,
- usage.as_ref(),
- worktree_path,
- changed_files,
- dirty_status,
- ledger_context.parent_call_id,
- ))
- .await;
- }
- AgentProgress::SubagentFailed {
- agent_id,
- task_id,
- error,
- } => {
- log::warn!(
- "[web_channel][bridge] subagent_failed agent_id={agent_id} err={error} client_id={} thread_id={} request_id={}",
- self.ids.client_id,
- self.ids.thread_id,
- self.ids.request_id
- );
- self.surface
- .output(map::sub_failed(
- &agent_id,
- &task_id,
- round,
- error,
- ledger_context.parent_call_id,
- ))
- .await;
- }
- AgentProgress::SubagentAwaitingUser {
- agent_id,
- task_id,
- question,
- worker_thread_id,
- ..
- } => {
- self.surface
- .output(map::sub_awaiting_user(
- &agent_id,
- &task_id,
- round,
- question,
- worker_thread_id,
- ledger_context.parent_call_id,
- ))
- .await;
- }
- AgentProgress::SubagentIterationStarted {
- agent_id,
- task_id,
- iteration,
- max_iterations,
- extended_policy,
- } => {
- self.surface
- .output(map::sub_iteration(
- &agent_id,
- &task_id,
- iteration,
- max_iterations,
- extended_policy,
- ))
- .await;
- }
- AgentProgress::SubagentToolCallStarted {
- agent_id,
- task_id,
- call_id,
- tool_name,
- arguments,
- iteration,
- display_label,
- display_detail,
- } => {
- self.surface
- .output(map::sub_tool_started(
- &agent_id,
- &task_id,
- call_id,
- tool_name,
- arguments,
- iteration,
- display_label,
- display_detail,
- ))
- .await;
- }
- AgentProgress::SubagentToolCallCompleted { .. } => {
- if let Some(output) = map::sub_tool_completed(event) {
- self.surface.output(output).await;
- }
- }
- AgentProgress::SubagentTextDelta {
- agent_id,
- task_id,
- delta,
- iteration,
- } => {
- self.surface
- .output(map::sub_delta(&agent_id, &task_id, false, delta, iteration))
- .await;
- }
- AgentProgress::SubagentThinkingDelta {
- agent_id,
- task_id,
- delta,
- iteration,
- } => {
- self.surface
- .output(map::sub_delta(&agent_id, &task_id, true, delta, iteration))
- .await;
- }
- other => {
- log::debug!(
- "[web_channel][bridge] unprojected event={:?} request_id={}",
- std::mem::discriminant(&other),
- self.ids.request_id,
- );
- }
+ if let AgentProgress::SubagentFailed {
+ agent_id, error, ..
+ } = &event
+ {
+ log::warn!(
+ "[web_channel][bridge] subagent_failed agent_id={agent_id} err={error} client_id={} thread_id={} request_id={}",
+ self.ids.client_id,
+ self.ids.thread_id,
+ self.ids.request_id
+ );
+ }
+
+ if let Some(output) = map::subagent_event(event, self.round, ledger_context.parent_call_id)
+ {
+ self.surface.output(output).await;
}
}
}