Report completed sub-agent activity on parent turns (#40437)

## Why

A Multi-Agent V2 child can finish after the parent turn that spawned it, so its
successful completion needs to remain associated with that parent turn in
notifications and history.

## What changed

- Add `completed` to `SubAgentActivityKind` and emit the corresponding started
  and completed item events on the spawning parent turn when a child succeeds.
- Persist completed activity as a canonical turn item in both legacy and
  paginated history, and expose it through app-server history and schemas.
- Render completed activity as terminal in the TUI without counting it as a
  separate tool call or tool-runtime event.

## Testing

- Cover successful completion in legacy and paginated history, late updates to
  completed parent turns, TUI rendering, analytics, and rollout tracing.
- Verify that terminal child errors do not emit completed activity.

GitOrigin-RevId: 6c71eb8b10e7327611c6af84f70e294e27d94d02
This commit is contained in:
jif authored and copyberry committed 2026-08-24 17:07:21 +00:00
1 parent 7781f0a5a8
commit b705b6b076
40 files changed
+466 -39

No files matched your search

@@ -173,6 +173,7 @@ fn activity_summary(item: &ThreadItem) -> Option<String> {
SubAgentActivityKind::Started => "Started",
SubAgentActivityKind::Interacted => "Contacted",
SubAgentActivityKind::Interrupted => "Interrupted",
SubAgentActivityKind::Completed => "Completed",
};
return bounded_summary(&format!("{action} {agent_path}"));
}
@@ -1,5 +1,5 @@
---
source: tui/src/chatwidget/tests.rs
source: tui/src/chatwidget/tests/app_server.rs
expression: rendered
---
• Interacted with `/root/researcher`
• Completed `/root/researcher`
@@ -963,7 +963,7 @@ async fn live_app_server_sub_agent_activity_renders_once() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
let activity = AppServerThreadItem::SubAgentActivity {
id: "activity-1".to_string(),
kind: codex_app_server_protocol::SubAgentActivityKind::Interacted,
kind: codex_app_server_protocol::SubAgentActivityKind::Completed,
agent_thread_id: ThreadId::new().to_string(),
agent_path: "/root/researcher".to_string(),
};
+23 -1
View File
@@ -291,7 +291,7 @@ pub(crate) fn sub_agent_activity_display(item: &ThreadItem) -> Option<SubAgentAc
let is_running_hint = match kind {
SubAgentActivityKind::Started => true,
SubAgentActivityKind::Interacted => return None,
SubAgentActivityKind::Interrupted => false,
SubAgentActivityKind::Interrupted | SubAgentActivityKind::Completed => false,
};
Some(SubAgentActivityDisplay {
thread_id: parse_thread_id(agent_thread_id)?,
@@ -318,6 +318,7 @@ pub(crate) fn sub_agent_activity_summary(kind: SubAgentActivityKind, agent_path:
SubAgentActivityKind::Started => format!("Started `{agent_path}`"),
SubAgentActivityKind::Interacted => format!("Interacted with `{agent_path}`"),
SubAgentActivityKind::Interrupted => format!("Interrupted `{agent_path}`"),
SubAgentActivityKind::Completed => format!("Completed `{agent_path}`"),
}
}
@@ -326,6 +327,7 @@ fn sub_agent_activity_title(kind: SubAgentActivityKind, agent_path: &str) -> Lin
SubAgentActivityKind::Started => ("Started ", agent_path),
SubAgentActivityKind::Interacted => ("Interacted with ", agent_path),
SubAgentActivityKind::Interrupted => ("Interrupted ", agent_path),
SubAgentActivityKind::Completed => ("Completed ", agent_path),
};
title_spans_line(vec![
Span::from(prefix).bold(),
@@ -691,6 +693,26 @@ mod tests {
assert_eq!(sub_agent_activity_display(&item), None);
}
#[test]
fn completed_sub_agent_activity_stops_running_liveness() {
let thread_id = ThreadId::new();
let item = ThreadItem::SubAgentActivity {
id: "activity-1".to_string(),
kind: SubAgentActivityKind::Completed,
agent_thread_id: thread_id.to_string(),
agent_path: "/root/child".to_string(),
};
assert_eq!(
sub_agent_activity_display(&item),
Some(SubAgentActivityDisplay {
thread_id,
agent_path: "/root/child".to_string(),
is_running_hint: false,
})
);
}
#[test]
fn collab_events_snapshot() {
let sender_thread_id = ThreadId::from_string("00000000-0000-0000-0000-000000000001")