mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:50:52 +00:00
Expose and persist turn lineage across the app server (#51415)
## Why Clients starting delegated work need to attribute descendant turns to the original turn and retain that attribution through completion and history reads. ## What changed - Accept optional `parentTurnId` and `rootTurnId` in `turn/start`, and expose `rootTurnId` on returned turns and lifecycle notifications. - Default new turns to their own root when none is supplied. Preserve the active turn's root when steering, ignoring incoming lineage fields. - Carry root IDs through completion, interruption, recovery, and fork boundaries, and persist them for paginated history reads. Leave unknown roots null in older history. - Update protocol schemas and generated TypeScript and Python bindings. ## Testing Extend coverage for default and explicit roots, steering without changing lineage, interrupted and recovered turns, history reads after restart in both history modes, nested fork pagination, and compatibility with older database writers. GitOrigin-RevId: f1a570a12bd11742929fd2e8b017e5d35aa07dcb
This commit is contained in:
@@ -44,6 +44,7 @@ fn reasoning(id: &str) -> ThreadItem {
|
||||
fn turn(items: Vec<ThreadItem>) -> Turn {
|
||||
Turn {
|
||||
id: "turn".to_owned(),
|
||||
root_turn_id: None,
|
||||
items,
|
||||
items_view: TurnItemsView::Full,
|
||||
status: TurnStatus::Completed,
|
||||
|
||||
@@ -2357,6 +2357,7 @@ async fn resume_picker_round_trip_preserves_each_threads_input() -> Result<()> {
|
||||
thread_id: target.thread_id.to_string(),
|
||||
turn: codex_app_server_protocol::Turn {
|
||||
id: "turn-with-follow-up".to_string(),
|
||||
root_turn_id: None,
|
||||
items_view: codex_app_server_protocol::TurnItemsView::Full,
|
||||
items: Vec::new(),
|
||||
status: codex_app_server_protocol::TurnStatus::InProgress,
|
||||
|
||||
@@ -47,6 +47,7 @@ async fn usage_notice_preserves_composer_geometry_on_recovery() -> Result<()> {
|
||||
thread_id: ThreadId::new().to_string(),
|
||||
turn: Turn {
|
||||
id: "turn".into(),
|
||||
root_turn_id: None,
|
||||
items_view: TurnItemsView::Full,
|
||||
items: Vec::new(),
|
||||
status: TurnStatus::InProgress,
|
||||
|
||||
@@ -7,6 +7,7 @@ use pretty_assertions::assert_eq;
|
||||
fn turn(id: &str, status: TurnStatus, item_ids: &[&str]) -> Turn {
|
||||
Turn {
|
||||
id: id.to_string(),
|
||||
root_turn_id: None,
|
||||
items: item_ids
|
||||
.iter()
|
||||
.map(|id| ThreadItem::UserMessage {
|
||||
|
||||
@@ -11,6 +11,7 @@ use pretty_assertions::assert_eq;
|
||||
fn turn(id: &str, status: TurnStatus, item_ids: &[&str]) -> Turn {
|
||||
Turn {
|
||||
id: id.to_string(),
|
||||
root_turn_id: None,
|
||||
items: item_ids
|
||||
.iter()
|
||||
.map(|id| ThreadItem::UserMessage {
|
||||
|
||||
@@ -29,6 +29,7 @@ async fn follow_control_click_preserves_draft_caret_and_composer_geometry() -> R
|
||||
thread_id: ThreadId::new().to_string(),
|
||||
turn: codex_app_server_protocol::Turn {
|
||||
id: "turn".into(),
|
||||
root_turn_id: None,
|
||||
items_view: codex_app_server_protocol::TurnItemsView::Full,
|
||||
items: Vec::new(),
|
||||
status: codex_app_server_protocol::TurnStatus::InProgress,
|
||||
|
||||
@@ -79,6 +79,7 @@ async fn configured_ctrl_space_submit_wins_over_transcript_selection() -> Result
|
||||
thread_id: thread_id.to_string(),
|
||||
turn: Turn {
|
||||
id: "turn".into(),
|
||||
root_turn_id: None,
|
||||
items_view: TurnItemsView::Full,
|
||||
items: Vec::new(),
|
||||
status: TurnStatus::InProgress,
|
||||
@@ -185,6 +186,7 @@ fn complete_plan_turn(app: &mut App) {
|
||||
let thread_id = ThreadId::new().to_string();
|
||||
let turn = Turn {
|
||||
id: "plan-turn".into(),
|
||||
root_turn_id: None,
|
||||
items_view: TurnItemsView::Full,
|
||||
items: Vec::new(),
|
||||
status: TurnStatus::InProgress,
|
||||
|
||||
@@ -598,6 +598,7 @@ async fn owned_details_escape_interrupts_work_without_starting_backtrack() -> Re
|
||||
thread_id: thread_id.to_string(),
|
||||
turn: codex_app_server_protocol::Turn {
|
||||
id: "active-turn".to_string(),
|
||||
root_turn_id: None,
|
||||
items_view: codex_app_server_protocol::TurnItemsView::Full,
|
||||
items: Vec::new(),
|
||||
status: codex_app_server_protocol::TurnStatus::InProgress,
|
||||
|
||||
@@ -675,6 +675,7 @@ mod tests {
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn: Turn {
|
||||
id: turn_id.to_string(),
|
||||
root_turn_id: None,
|
||||
items_view: codex_app_server_protocol::TurnItemsView::Full,
|
||||
items: Vec::new(),
|
||||
status: TurnStatus::Completed,
|
||||
|
||||
@@ -45,6 +45,7 @@ use uuid::Uuid;
|
||||
fn turn(status: TurnStatus) -> Turn {
|
||||
Turn {
|
||||
id: "turn".to_string(),
|
||||
root_turn_id: None,
|
||||
items: Vec::new(),
|
||||
items_view: Default::default(),
|
||||
status,
|
||||
|
||||
@@ -4,6 +4,7 @@ use codex_app_server_protocol::TurnItemsView;
|
||||
fn turn(id: &str, status: TurnStatus) -> Turn {
|
||||
Turn {
|
||||
id: id.to_string(),
|
||||
root_turn_id: None,
|
||||
items: Vec::new(),
|
||||
items_view: TurnItemsView::Full,
|
||||
status,
|
||||
|
||||
@@ -7224,6 +7224,7 @@ async fn resizing_empty_transcript_schedules_settled_size_recheck() {
|
||||
fn test_turn(turn_id: &str, status: TurnStatus, items: Vec<ThreadItem>) -> Turn {
|
||||
Turn {
|
||||
id: turn_id.to_string(),
|
||||
root_turn_id: None,
|
||||
items_view: codex_app_server_protocol::TurnItemsView::Full,
|
||||
items,
|
||||
status,
|
||||
@@ -8426,6 +8427,7 @@ async fn prompt_edit_reverts_earlier_and_first_visible_prompts_in_place() -> Res
|
||||
completed_at_ms: 0,
|
||||
})),
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(TurnCompleteEvent {
|
||||
root_turn_id: None,
|
||||
turn_id: turn_id.to_string(),
|
||||
last_agent_message: None,
|
||||
error: None,
|
||||
@@ -8812,6 +8814,7 @@ async fn replay_thread_snapshot_replays_turn_history_in_order() {
|
||||
turns: vec![
|
||||
Turn {
|
||||
id: "turn-1".to_string(),
|
||||
root_turn_id: None,
|
||||
items_view: codex_app_server_protocol::TurnItemsView::Full,
|
||||
items: vec![ThreadItem::UserMessage {
|
||||
id: "user-1".to_string(),
|
||||
@@ -8829,6 +8832,7 @@ async fn replay_thread_snapshot_replays_turn_history_in_order() {
|
||||
},
|
||||
Turn {
|
||||
id: "turn-2".to_string(),
|
||||
root_turn_id: None,
|
||||
items_view: codex_app_server_protocol::TurnItemsView::Full,
|
||||
items: vec![
|
||||
ThreadItem::UserMessage {
|
||||
|
||||
@@ -304,6 +304,7 @@ fn evicted_voice_delegation_marker_still_suppresses_private_replay() {
|
||||
let mut resumed = ThreadEventStore::new(/*capacity*/ 1);
|
||||
resumed.set_turns(vec![Turn {
|
||||
id: "voice-turn".into(),
|
||||
root_turn_id: None,
|
||||
items: vec![voice_request],
|
||||
items_view: codex_app_server_protocol::TurnItemsView::Summary,
|
||||
status: TurnStatus::InProgress,
|
||||
@@ -345,6 +346,7 @@ fn saved_voice_turn_suppresses_reasoning_without_hiding_typed_reasoning() {
|
||||
};
|
||||
let turn = |id: &str, items| Turn {
|
||||
id: id.into(),
|
||||
root_turn_id: None,
|
||||
items,
|
||||
items_view: codex_app_server_protocol::TurnItemsView::Full,
|
||||
status: TurnStatus::Completed,
|
||||
@@ -390,6 +392,7 @@ fn snapshot_keeps_typed_output_before_voice_handoff_in_the_same_turn() {
|
||||
let mut store = ThreadEventStore::new(/*capacity*/ 8);
|
||||
store.set_turns(vec![Turn {
|
||||
id: "shared".into(),
|
||||
root_turn_id: None,
|
||||
items: vec![typed.clone(), marker.clone(), private.clone()],
|
||||
items_view: codex_app_server_protocol::TurnItemsView::Full,
|
||||
status: TurnStatus::InProgress,
|
||||
|
||||
@@ -80,6 +80,7 @@ async fn history_fixture(
|
||||
}));
|
||||
}
|
||||
events.push(EventMsg::TurnComplete(TurnCompleteEvent {
|
||||
root_turn_id: None,
|
||||
turn_id,
|
||||
last_agent_message: None,
|
||||
error: None,
|
||||
|
||||
@@ -95,6 +95,7 @@ pub(super) async fn completed_history_app(
|
||||
})
|
||||
}));
|
||||
events.push(EventMsg::TurnComplete(TurnCompleteEvent {
|
||||
root_turn_id: None,
|
||||
turn_id,
|
||||
last_agent_message: Some(format!("{name} answer")),
|
||||
error: None,
|
||||
|
||||
@@ -299,6 +299,7 @@ async fn switching_agent_threads_preserves_backend_voice_and_routes_pending_spee
|
||||
thread_id: source.to_string(),
|
||||
turn: Turn {
|
||||
id: turn_id.into(),
|
||||
root_turn_id: None,
|
||||
items: vec![answer.clone()],
|
||||
items_view: TurnItemsView::Summary,
|
||||
status: TurnStatus::Completed,
|
||||
@@ -665,6 +666,7 @@ async fn replay_reconciles_only_matching_voice_captions_one_for_one() {
|
||||
.insert(source, records);
|
||||
let voice = Turn {
|
||||
id: "voice-turn".into(),
|
||||
root_turn_id: None,
|
||||
items: vec![
|
||||
test_user_message(
|
||||
"voice-user",
|
||||
@@ -929,6 +931,7 @@ async fn unrendered_buffered_items_do_not_consume_retained_captions() {
|
||||
thread_id: source.to_string(),
|
||||
turn: Turn {
|
||||
id: turn_id.into(),
|
||||
root_turn_id: None,
|
||||
items,
|
||||
items_view: TurnItemsView::Summary,
|
||||
status,
|
||||
@@ -1212,6 +1215,7 @@ async fn rejected_realtime_speech_restores_the_delegated_final_answer() -> Resul
|
||||
thread_id: thread_id.to_string(),
|
||||
turn: Turn {
|
||||
id: "rejected-turn".to_string(),
|
||||
root_turn_id: None,
|
||||
items: vec![answer],
|
||||
items_view: TurnItemsView::Summary,
|
||||
status: TurnStatus::Completed,
|
||||
@@ -1311,6 +1315,7 @@ async fn switching_threads_retains_undelivered_voice_answer_after_replay_evictio
|
||||
thread_id: original.to_string(),
|
||||
turn: Turn {
|
||||
id: "switched-turn".to_string(),
|
||||
root_turn_id: None,
|
||||
items: vec![answer],
|
||||
items_view: TurnItemsView::Summary,
|
||||
status: TurnStatus::Completed,
|
||||
@@ -1391,6 +1396,7 @@ async fn switching_threads_retains_undelivered_voice_answer_after_replay_evictio
|
||||
session: Some(test_thread_session(original, app.config.cwd.to_path_buf())),
|
||||
turns: vec![Turn {
|
||||
id: "replayed-turn".to_string(),
|
||||
root_turn_id: None,
|
||||
items: vec![replayed_item],
|
||||
items_view: TurnItemsView::Summary,
|
||||
status: TurnStatus::Completed,
|
||||
@@ -1593,6 +1599,7 @@ async fn delegated_final_speech_reaches_app_server_once_and_stale_speech_is_reje
|
||||
thread_id: thread_id.to_string(),
|
||||
turn: Turn {
|
||||
id: turn_id.to_string(),
|
||||
root_turn_id: None,
|
||||
items: vec![answer],
|
||||
items_view: TurnItemsView::Summary,
|
||||
status: TurnStatus::Completed,
|
||||
@@ -1670,6 +1677,7 @@ async fn delegated_final_speech_reaches_app_server_once_and_stale_speech_is_reje
|
||||
thread_id: thread_id.to_string(),
|
||||
turn: Turn {
|
||||
id: second_turn.to_string(),
|
||||
root_turn_id: None,
|
||||
items: vec![second_answer],
|
||||
items_view: TurnItemsView::Summary,
|
||||
status: TurnStatus::Completed,
|
||||
|
||||
@@ -18,6 +18,7 @@ fn turn_started_notification(thread_id: ThreadId, turn_id: &str) -> ServerNotifi
|
||||
thread_id: thread_id.to_string(),
|
||||
turn: Turn {
|
||||
id: turn_id.to_string(),
|
||||
root_turn_id: None,
|
||||
items_view: TurnItemsView::Full,
|
||||
items: Vec::new(),
|
||||
status: TurnStatus::InProgress,
|
||||
|
||||
@@ -689,6 +689,7 @@ mod tests {
|
||||
fn test_turn(turn_id: &str, status: TurnStatus, items: Vec<ThreadItem>) -> Turn {
|
||||
Turn {
|
||||
id: turn_id.to_string(),
|
||||
root_turn_id: None,
|
||||
items_view: codex_app_server_protocol::TurnItemsView::Full,
|
||||
items,
|
||||
status,
|
||||
|
||||
@@ -269,6 +269,7 @@ async fn check_thread_title_generation(scenario: TitleScenario) -> color_eyre::R
|
||||
.turns
|
||||
.push(Turn {
|
||||
id: "existing-turn".to_string(),
|
||||
root_turn_id: None,
|
||||
items: vec![title_user_message("user-message", "Fix the login timeout")],
|
||||
items_view: Default::default(),
|
||||
status: TurnStatus::Completed,
|
||||
|
||||
@@ -83,6 +83,7 @@ fn transcript_export_excludes_hidden_review_prompts_and_nested_duplicates() {
|
||||
let duplicate_two = user("duplicate-two", "duplicate review prompt");
|
||||
let turn = |id: &str, items: Vec<ThreadItem>, status| Turn {
|
||||
id: id.to_string(),
|
||||
root_turn_id: None,
|
||||
items,
|
||||
items_view: TurnItemsView::Full,
|
||||
status,
|
||||
|
||||
Reference in New Issue
Block a user