Track parent turns for nested Codex requests (#35835)

## What changed

- Propagate the initiating turn ID through agent spawns, follow-up tasks, reviews, and delegated Codex sessions.
- Add `parent_turn_id` to Responses client and turn metadata while keeping it out of external MCP metadata.
- Preserve parent-turn provenance across queued agent messages when their triggering parent is unambiguous.

## Testing

- Cover spawned, resumed, nested, reviewed, delegated, and WebSocket request metadata.
- Verify queued messages do not claim ambiguous or queue-only parent turns.

GitOrigin-RevId: 481fdebbe7df2031880fe259509273cce50b20a8
This commit is contained in:
Eddie Chen authored and copyberry committed 2026-07-28 21:58:33 +00:00
1 parent 12b3e88028
commit 1def0a8925
34 files changed
+635 -165

No files matched your search

@@ -175,6 +175,7 @@ async fn forward_ops_preserves_submission_trace_context() {
),
tracestate: Some("vendor=state".to_string()),
}),
parent_turn_id: Some("parent-turn".to_string()),
};
tx_ops.send(submission.clone()).await.unwrap();
drop(tx_ops);
@@ -186,6 +187,7 @@ async fn forward_ops_preserves_submission_trace_context() {
assert_eq!(submission.id, forwarded.id);
assert_eq!(submission.op, forwarded.op);
assert_eq!(submission.trace, forwarded.trace);
assert_eq!(submission.parent_turn_id, forwarded.parent_turn_id);
timeout(Duration::from_secs(1), forward)
.await