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
2026-08-12 18:11:13 +00:00
committed by copyberry
parent 9df9ff6ad9
commit 1f4ea79853
38 changed files with 470 additions and 65 deletions
+2 -1
View File
@@ -1374,6 +1374,7 @@ impl ThreadManagerState {
thread_id: ThreadId,
op: Op,
parent_turn_id: Option<String>,
root_turn_id: Option<String>,
) -> CodexResult<String> {
let thread = self.get_thread(thread_id).await?;
if let Some(ops_log) = &self.ops_log
@@ -1384,7 +1385,7 @@ impl ThreadManagerState {
}
thread
.io
.submit_with_trace(op, /*trace*/ None, parent_turn_id)
.submit_with_trace(op, /*trace*/ None, parent_turn_id, root_turn_id)
.await
}