Lightweight coding agent that runs in your terminal
Rust
Add trace_id to TurnStartedEvent (#23980)
mchen-oai3c83e57bfa88
diff --git a/codex-rs/app-server-protocol/src/protocol/thread_history.rs b/codex-rs/app-server-protocol/src/protocol/thread_history.rsindex 0fbb93f397..c0c7d55528 100644--- a/codex-rs/app-server-protocol/src/protocol/thread_history.rs+++ b/codex-rs/app-server-protocol/src/protocol/thread_history.rs@@ -1393,6 +1393,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: turn_id.to_string(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -1471,6 +1472,7 @@ mod tests {let items = vec![RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-image".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -1806,6 +1808,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-a".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -1866,6 +1869,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-1".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -1978,6 +1982,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-1".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2043,6 +2048,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-1".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2109,6 +2115,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-1".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2199,6 +2206,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-1".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2283,6 +2291,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-1".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2347,6 +2356,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-a".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2367,6 +2377,7 @@ mod tests {}),EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-b".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2441,6 +2452,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-a".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2461,6 +2473,7 @@ mod tests {}),EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-b".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2530,6 +2543,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: turn_id.to_string(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2595,6 +2609,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: turn_id.to_string(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2660,6 +2675,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-a".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2680,6 +2696,7 @@ mod tests {}),EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-b".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2728,6 +2745,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-a".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2748,6 +2766,7 @@ mod tests {}),EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-b".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -2789,6 +2808,7 @@ mod tests {let items = vec![RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-compact".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -3042,6 +3062,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-a".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -3098,6 +3119,7 @@ mod tests {let events = vec![EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-a".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -3156,6 +3178,7 @@ mod tests {let items = vec![RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-a".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -3204,6 +3227,7 @@ mod tests {let items = vec![RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-a".into(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),diff --git a/codex-rs/app-server/src/bespoke_event_handling.rs b/codex-rs/app-server/src/bespoke_event_handling.rsindex efe6c69a32..5f784ea23a 100644--- a/codex-rs/app-server/src/bespoke_event_handling.rs+++ b/codex-rs/app-server/src/bespoke_event_handling.rs@@ -3219,6 +3219,7 @@ mod tests {"turn-1",&EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: "turn-1".to_string(),+ trace_id: None,started_at: Some(42),model_context_window: None,collaboration_mode_kind: Default::default(),@@ -3252,6 +3253,7 @@ mod tests {id: "turn-1".to_string(),msg: EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: "turn-1".to_string(),+ trace_id: None,started_at: Some(42),model_context_window: None,collaboration_mode_kind: Default::default(),@@ -3301,6 +3303,7 @@ mod tests {&event_turn_id,&EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: event_turn_id.clone(),+ trace_id: None,started_at: Some(42),model_context_window: None,collaboration_mode_kind: Default::default(),diff --git a/codex-rs/app-server/src/request_processors/thread_processor_tests.rs b/codex-rs/app-server/src/request_processors/thread_processor_tests.rsindex f4593ab7c4..c6b5541aa2 100644--- a/codex-rs/app-server/src/request_processors/thread_processor_tests.rs+++ b/codex-rs/app-server/src/request_processors/thread_processor_tests.rs@@ -1155,6 +1155,7 @@ mod thread_processor_behavior_tests {"turn-1",&EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: "turn-1".to_string(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),diff --git a/codex-rs/app-server/tests/suite/v2/thread_resume.rs b/codex-rs/app-server/tests/suite/v2/thread_resume.rsindex f21a973f63..6416499663 100644--- a/codex-rs/app-server/tests/suite/v2/thread_resume.rs+++ b/codex-rs/app-server/tests/suite/v2/thread_resume.rs@@ -1431,6 +1431,7 @@ async fn thread_resume_token_usage_replay_ignores_stale_interrupted_tail_turn()"type": "event_msg","payload": serde_json::to_value(EventMsg::TurnStarted(TurnStartedEvent {turn_id: stale_turn_id.to_string(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -1518,6 +1519,7 @@ async fn thread_resume_token_usage_replay_can_belong_to_interrupted_turn() -> Re"type": "event_msg","payload": serde_json::to_value(EventMsg::TurnStarted(TurnStartedEvent {turn_id: interrupted_turn_id.to_string(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -1835,6 +1837,7 @@ async fn thread_resume_and_read_interrupt_incomplete_rollout_turn_when_thread_is"type": "event_msg","payload": serde_json::to_value(EventMsg::TurnStarted(TurnStartedEvent {turn_id: turn_id.to_string(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),diff --git a/codex-rs/core/src/agent/control_tests.rs b/codex-rs/core/src/agent/control_tests.rsindex 54114f05d1..ed39df1548 100644--- a/codex-rs/core/src/agent/control_tests.rs+++ b/codex-rs/core/src/agent/control_tests.rs@@ -271,6 +271,7 @@ async fn get_status_returns_not_found_without_manager() {async fn on_event_updates_status_from_task_started() {let status = agent_status_from_event(&EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-1".to_string(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: ModeKind::Default,diff --git a/codex-rs/core/src/compact.rs b/codex-rs/core/src/compact.rsindex b5802268d3..f2bded8d06 100644--- a/codex-rs/core/src/compact.rs+++ b/codex-rs/core/src/compact.rs@@ -100,6 +100,7 @@ pub(crate) async fn run_compact_task() -> CodexResult<()> {let start_event = EventMsg::TurnStarted(TurnStartedEvent {turn_id: turn_context.sub_id.clone(),+ trace_id: turn_context.trace_id.clone(),started_at: turn_context.turn_timing_state.started_at_unix_secs().await,model_context_window: turn_context.model_context_window(),collaboration_mode_kind: turn_context.collaboration_mode.mode,diff --git a/codex-rs/core/src/compact_remote.rs b/codex-rs/core/src/compact_remote.rsindex 30d1e5f0e8..969da47544 100644--- a/codex-rs/core/src/compact_remote.rs+++ b/codex-rs/core/src/compact_remote.rs@@ -62,6 +62,7 @@ pub(crate) async fn run_remote_compact_task() -> CodexResult<()> {let start_event = EventMsg::TurnStarted(TurnStartedEvent {turn_id: turn_context.sub_id.clone(),+ trace_id: turn_context.trace_id.clone(),started_at: turn_context.turn_timing_state.started_at_unix_secs().await,model_context_window: turn_context.model_context_window(),collaboration_mode_kind: turn_context.collaboration_mode.mode,diff --git a/codex-rs/core/src/compact_remote_v2.rs b/codex-rs/core/src/compact_remote_v2.rsindex 251d37b35c..37e44021bc 100644--- a/codex-rs/core/src/compact_remote_v2.rs+++ b/codex-rs/core/src/compact_remote_v2.rs@@ -78,6 +78,7 @@ pub(crate) async fn run_remote_compact_task() -> CodexResult<()> {let start_event = EventMsg::TurnStarted(TurnStartedEvent {turn_id: turn_context.sub_id.clone(),+ trace_id: turn_context.trace_id.clone(),started_at: turn_context.turn_timing_state.started_at_unix_secs().await,model_context_window: turn_context.model_context_window(),collaboration_mode_kind: turn_context.collaboration_mode.mode,diff --git a/codex-rs/core/src/session/rollout_reconstruction_tests.rs b/codex-rs/core/src/session/rollout_reconstruction_tests.rsindex fc2811710a..11b8651ae6 100644--- a/codex-rs/core/src/session/rollout_reconstruction_tests.rs+++ b/codex-rs/core/src/session/rollout_reconstruction_tests.rs@@ -122,6 +122,7 @@ async fn record_initial_history_resumed_hydrates_previous_turn_settings_from_lifRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -189,6 +190,7 @@ async fn reconstruct_history_rollback_keeps_history_and_metadata_in_sync_for_comRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: first_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -218,6 +220,7 @@ async fn reconstruct_history_rollback_keeps_history_and_metadata_in_sync_for_comRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: rolled_back_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -289,6 +292,7 @@ async fn reconstruct_history_rollback_keeps_history_and_metadata_in_sync_for_incRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: first_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -318,6 +322,7 @@ async fn reconstruct_history_rollback_keeps_history_and_metadata_in_sync_for_incRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: incomplete_turn_id,+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -381,6 +386,7 @@ async fn reconstruct_history_rollback_skips_non_user_turns_for_history_and_metadRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: first_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -410,6 +416,7 @@ async fn reconstruct_history_rollback_skips_non_user_turns_for_history_and_metadRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: second_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -438,6 +445,7 @@ async fn reconstruct_history_rollback_skips_non_user_turns_for_history_and_metadRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: standalone_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -501,6 +509,7 @@ async fn reconstruct_history_rollback_counts_inter_agent_assistant_turns() {RolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: first_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -530,6 +539,7 @@ async fn reconstruct_history_rollback_counts_inter_agent_assistant_turns() {RolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: assistant_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -590,6 +600,7 @@ async fn reconstruct_history_rollback_clears_history_and_metadata_when_exceedingRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: only_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -643,6 +654,7 @@ async fn record_initial_history_resumed_rollback_skips_only_user_turns() {RolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: user_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -671,6 +683,7 @@ async fn record_initial_history_resumed_rollback_skips_only_user_turns() {RolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: standalone_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -716,6 +729,7 @@ async fn record_initial_history_resumed_rollback_drops_incomplete_user_turn_compRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: previous_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -743,6 +757,7 @@ async fn record_initial_history_resumed_rollback_drops_incomplete_user_turn_compRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: incomplete_turn_id,+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -875,6 +890,7 @@ async fn reconstruct_history_legacy_compaction_without_replacement_history_clearRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: current_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -939,6 +955,7 @@ async fn record_initial_history_resumed_turn_context_after_compaction_reestablisRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: previous_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -1043,6 +1060,7 @@ async fn record_initial_history_resumed_aborted_turn_without_id_clears_active_tuRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: previous_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -1070,6 +1088,7 @@ async fn record_initial_history_resumed_aborted_turn_without_id_clears_active_tuRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: aborted_turn_id,+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -1151,6 +1170,7 @@ async fn record_initial_history_resumed_unmatched_abort_preserves_active_turn_foRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: previous_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -1178,6 +1198,7 @@ async fn record_initial_history_resumed_unmatched_abort_preserves_active_turn_foRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: current_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -1268,6 +1289,7 @@ async fn record_initial_history_resumed_trailing_incomplete_turn_compaction_cleaRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: previous_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -1295,6 +1317,7 @@ async fn record_initial_history_resumed_trailing_incomplete_turn_compaction_cleaRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: incomplete_turn_id,+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -1346,6 +1369,7 @@ async fn record_initial_history_resumed_trailing_incomplete_turn_preserves_turn_RolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: current_turn_id,+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -1420,6 +1444,7 @@ async fn record_initial_history_resumed_replaced_incomplete_compacted_turn_clearRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: previous_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -1447,6 +1472,7 @@ async fn record_initial_history_resumed_replaced_incomplete_compacted_turn_clearRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: compacted_incomplete_turn_id,+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -1470,6 +1496,7 @@ async fn record_initial_history_resumed_replaced_incomplete_compacted_turn_clearRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: replacing_turn_id,+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,diff --git a/codex-rs/core/src/session/tests.rs b/codex-rs/core/src/session/tests.rsindex d4d0c28660..df7559a7d9 100644--- a/codex-rs/core/src/session/tests.rs+++ b/codex-rs/core/src/session/tests.rs@@ -267,8 +267,24 @@ fn skill_message(text: &str) -> ResponseItem {}#[tokio::test]-async fn regular_turn_emits_turn_started_without_waiting_for_startup_prewarm() {- let (sess, tc, rx) = make_session_and_context_with_rx().await;+async fn regular_turn_emits_turn_started_with_trace_id_without_waiting_for_startup_prewarm() {+ let _trace_test_context = install_test_tracing("codex-core-tests");+ let request_parent = W3cTraceContext {+ traceparent: Some("00-00000000000000000000000000000011-0000000000000022-01".into()),+ tracestate: Some("vendor=value".into()),+ };+ let request_span = info_span!("app_server.request");+ assert!(set_parent_from_w3c_trace_context(+ &request_span,+ &request_parent+ ));+ let (sess, tc, rx) = make_session_and_context_with_rx()+ .instrument(request_span)+ .await;+ assert_eq!(+ tc.trace_id.as_deref(),+ Some("00000000000000000000000000000011")+ );let (_tx, startup_prewarm_rx) = tokio::sync::oneshot::channel::<()>();let handle = tokio::spawn(async move {let _ = startup_prewarm_rx.await;@@ -294,10 +310,11 @@ async fn regular_turn_emits_turn_started_without_waiting_for_startup_prewarm() {.await.expect("expected turn started event without waiting for startup prewarm").expect("channel open");- assert!(matches!(- first.msg,- EventMsg::TurnStarted(TurnStartedEvent { turn_id, .. }) if turn_id == tc.sub_id- ));+ let EventMsg::TurnStarted(turn_started) = first.msg else {+ panic!("expected turn started event");+ };+ assert_eq!(turn_started.turn_id, tc.sub_id);+ assert_eq!(turn_started.trace_id, tc.trace_id);sess.abort_all_tasks(TurnAbortReason::Interrupted).await;}@@ -2378,6 +2395,7 @@ async fn record_initial_history_forked_hydrates_previous_turn_settings() {RolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -2573,6 +2591,7 @@ async fn thread_rollback_recomputes_previous_turn_settings_and_reference_contextRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: first_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -2600,6 +2619,7 @@ async fn thread_rollback_recomputes_previous_turn_settings_and_reference_contextRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: rolled_back_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -2684,6 +2704,7 @@ async fn thread_rollback_restores_cleared_reference_context_item_after_compactioRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: first_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -2709,6 +2730,7 @@ async fn thread_rollback_restores_cleared_reference_context_item_after_compactioRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: compact_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -2728,6 +2750,7 @@ async fn thread_rollback_restores_cleared_reference_context_item_after_compactioRolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: rolled_back_turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -2783,6 +2806,7 @@ async fn thread_rollback_persists_marker_and_replays_cumulatively() {RolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: "turn-1".to_string(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -2808,6 +2832,7 @@ async fn thread_rollback_persists_marker_and_replays_cumulatively() {RolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: "turn-2".to_string(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,@@ -2833,6 +2858,7 @@ async fn thread_rollback_persists_marker_and_replays_cumulatively() {RolloutItem::EventMsg(EventMsg::TurnStarted(codex_protocol::protocol::TurnStartedEvent {turn_id: "turn-3".to_string(),+ trace_id: None,started_at: None,model_context_window: Some(128_000),collaboration_mode_kind: ModeKind::Default,diff --git a/codex-rs/core/src/tasks/regular.rs b/codex-rs/core/src/tasks/regular.rsindex 50414df278..531d5d7da7 100644--- a/codex-rs/core/src/tasks/regular.rs+++ b/codex-rs/core/src/tasks/regular.rs@@ -51,6 +51,7 @@ impl SessionTask for RegularTask {// not wait on startup prewarm resolution.let event = EventMsg::TurnStarted(TurnStartedEvent {turn_id: ctx.sub_id.clone(),+ trace_id: ctx.trace_id.clone(),started_at: ctx.turn_timing_state.started_at_unix_secs().await,model_context_window: ctx.model_context_window(),collaboration_mode_kind: ctx.collaboration_mode.mode,diff --git a/codex-rs/core/src/tasks/user_shell.rs b/codex-rs/core/src/tasks/user_shell.rsindex 23f3882eda..2ce4056957 100644--- a/codex-rs/core/src/tasks/user_shell.rs+++ b/codex-rs/core/src/tasks/user_shell.rs@@ -114,6 +114,7 @@ pub(crate) async fn execute_user_shell_command(// freshly reinjected context before the summary/replacement history is applied.let event = EventMsg::TurnStarted(TurnStartedEvent {turn_id: turn_context.sub_id.clone(),+ trace_id: turn_context.trace_id.clone(),started_at: turn_context.turn_timing_state.started_at_unix_secs().await,model_context_window: turn_context.model_context_window(),collaboration_mode_kind: turn_context.collaboration_mode.mode,diff --git a/codex-rs/core/src/thread_manager_tests.rs b/codex-rs/core/src/thread_manager_tests.rsindex 255a8336b9..c79a6859d7 100644--- a/codex-rs/core/src/thread_manager_tests.rs+++ b/codex-rs/core/src/thread_manager_tests.rs@@ -187,6 +187,7 @@ fn out_of_range_truncation_drops_pre_user_active_turn_prefix() {RolloutItem::ResponseItem(assistant_msg("a1")),RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-2".to_string(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),@@ -1307,6 +1308,7 @@ async fn interrupted_fork_snapshot_preserves_explicit_turn_id() {InitialHistory::Forked(vec![RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {turn_id: "turn-explicit".to_string(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: Default::default(),diff --git a/codex-rs/core/tests/suite/resume_warning.rs b/codex-rs/core/tests/suite/resume_warning.rsindex d2bdcd1d32..51242ede2a 100644--- a/codex-rs/core/tests/suite/resume_warning.rs+++ b/codex-rs/core/tests/suite/resume_warning.rs@@ -50,6 +50,7 @@ fn resume_history(history: vec![RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {turn_id: turn_id.clone(),+ trace_id: None,started_at: None,model_context_window: None,collaboration_mode_kind: ModeKind::Default,diff --git a/codex-rs/external-agent-sessions/src/export.rs b/codex-rs/external-agent-sessions/src/export.rsindex 3682a4f7f8..01220c07c1 100644--- a/codex-rs/external-agent-sessions/src/export.rs+++ b/codex-rs/external-agent-sessions/src/export.rs@@ -67,6 +67,7 @@ fn rollout_items_from_messages(messages: &[ConversationMessage]) -> Vec<RolloutIitems.push(RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {turn_id: turn_id.clone(),+ trace_id: None,started_at: message.timestamp,model_context_window: None,collaboration_mode_kind: Default::default(),diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rsindex b0f34bae4d..7d955f1d1f 100644--- a/codex-rs/protocol/src/protocol.rs+++ b/codex-rs/protocol/src/protocol.rs@@ -1850,6 +1850,10 @@ pub struct TurnCompleteEvent {#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]pub struct TurnStartedEvent {pub turn_id: String,+ // Persist for rollout consumers that correlate turns with telemetry traces.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ #[ts(optional)]+ pub trace_id: Option<String>,/// Unix timestamp (in seconds) when the turn started.#[serde(default, skip_serializing_if = "Option::is_none")]#[ts(type = "number | null", optional)]