Track root turns across delegated Codex requests (#38232)

## Why

`parent_turn_id` identifies the immediate caller of a nested request, but not the
top-level turn that initiated a multi-level chain of work.

## What changed

- Add `root_turn_id` to turn state, submissions, and Responses API metadata.
- Propagate the root through spawned agents, delegated work, review sessions, and
  turn-triggering inter-agent messages.
- Omit the root when background work has no user turn or combined input makes the
  root ambiguous.

## Testing

Added coverage for nested agent resumes, reviews, mailbox delivery, steered input,
and reserved metadata handling.

GitOrigin-RevId: 60057db2ee81f4efefa946a9f63c74ff98b93929
This commit is contained in:
Eddie Chen authored and copyberry committed 2026-08-12 18:11:13 +00:00
1 parent 9df9ff6ad9
commit 1f4ea79853
38 files changed
+470 -65

No files matched your search

+5
View File
@@ -418,6 +418,7 @@ async fn send_input_errors_when_manager_dropped() {
text_elements: Vec::new(),
}],
/*parent_turn_id*/ None,
/*root_turn_id*/ None,
)
.await
.expect_err("send_input should fail without a manager");
@@ -533,6 +534,7 @@ async fn send_input_errors_when_thread_missing() {
text_elements: Vec::new(),
}],
/*parent_turn_id*/ None,
/*root_turn_id*/ None,
)
.await
.expect_err("send_input should fail for missing thread");
@@ -606,6 +608,7 @@ async fn send_input_submits_user_message() {
text_elements: Vec::new(),
}],
/*parent_turn_id*/ None,
/*root_turn_id*/ None,
)
.await
.expect("send_input should succeed");
@@ -650,6 +653,7 @@ async fn send_inter_agent_communication_without_turn_queues_message_without_trig
communication.clone(),
AgentCommunicationContext::new(AgentCommunicationKind::Message, ThreadId::new()),
/*parent_turn_id*/ None,
/*root_turn_id*/ None,
)
.await
.expect("send_inter_agent_communication should succeed");
@@ -815,6 +819,7 @@ async fn ensure_v2_agent_loaded_reloads_registered_unloaded_agent() {
communication.clone(),
AgentCommunicationContext::new(AgentCommunicationKind::Message, ThreadId::new()),
/*parent_turn_id*/ None,
/*root_turn_id*/ None,
)
.await
.expect("send_inter_agent_communication should succeed after reload");