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

+3 -1
View File
@@ -887,6 +887,7 @@ async fn run_review_on_session(
.and_then(|environment| environment.cwd().to_abs_path().ok())
.unwrap_or_else(|| params.parent_context.turn().config.cwd.clone());
let parent_turn = params.parent_context.turn();
let submission = review_session.io.submit_with_trace(
Op::UserInput {
items: prompt_items.items,
@@ -915,7 +916,8 @@ async fn run_review_on_session(
},
},
/*trace*/ None,
Some(params.parent_context.turn().sub_id.clone()),
Some(parent_turn.sub_id.clone()),
parent_turn.turn_metadata_state.root_turn_id(),
);
let submit_result = run_before_review_deadline(
deadline,