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
2026-07-28 21:58:33 +00:00
committed by copyberry
parent 12b3e88028
commit 1def0a8925
34 changed files with 635 additions and 165 deletions
+5 -2
View File
@@ -275,7 +275,9 @@ impl CodexThread {
op: Op,
trace: Option<W3cTraceContext>,
) -> CodexResult<String> {
self.io.submit_with_trace(op, trace).await
self.io
.submit_with_trace(op, trace, /*parent_turn_id*/ None)
.await
}
pub async fn submit_user_input_with_client_user_message_id(
@@ -427,7 +429,8 @@ impl CodexThread {
}
/// Use sparingly: this is intended to be removed soon.
pub async fn submit_with_id(&self, sub: Submission) -> CodexResult<()> {
pub async fn submit_with_id(&self, mut sub: Submission) -> CodexResult<()> {
sub.parent_turn_id = None;
self.io.submit_with_id(sub).await
}