mirror of
https://github.com/openai/codex.git
synced 2026-12-06 01:10:58 +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:
@@ -2130,6 +2130,10 @@ pub struct ContextCompactedEvent;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]
|
||||
pub struct TurnCompleteEvent {
|
||||
/// Resolved causal root for this turn; absent on older or synthetic events.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub root_turn_id: Option<String>,
|
||||
pub turn_id: String,
|
||||
pub last_agent_message: Option<String>,
|
||||
/// Terminal error details when the turn completed unsuccessfully.
|
||||
@@ -4225,6 +4229,10 @@ pub struct Chunk {
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]
|
||||
pub struct TurnAbortedEvent {
|
||||
/// Resolved causal root for this turn; absent on older or synthetic events.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub root_turn_id: Option<String>,
|
||||
pub turn_id: Option<String>,
|
||||
pub reason: TurnAbortReason,
|
||||
/// Optional error describing why the turn was interrupted.
|
||||
@@ -6103,9 +6111,12 @@ mod tests {
|
||||
|
||||
match event {
|
||||
EventMsg::TurnAborted(TurnAbortedEvent {
|
||||
turn_id, reason, ..
|
||||
turn_id,
|
||||
root_turn_id,
|
||||
reason,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(turn_id, None);
|
||||
assert_eq!((turn_id, root_turn_id), (None, None));
|
||||
assert_eq!(reason, TurnAbortReason::Interrupted);
|
||||
}
|
||||
_ => panic!("expected turn_aborted event"),
|
||||
|
||||
@@ -208,16 +208,23 @@ pub struct TurnStartOptions {
|
||||
///
|
||||
/// Started and Steered only mean Core accepted the input for turn processing. They
|
||||
/// do not wait for user-prompt hooks, updating the in-memory model context,
|
||||
/// rollout persistence, or sampling.
|
||||
/// rollout persistence, or sampling. The returned root is the accepted turn's
|
||||
/// resolved causal root, including when steering preserves an existing turn.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum TurnInputSubmission {
|
||||
/// Core started a turn. Persistent thread settings and start options were applied.
|
||||
Started { turn_id: String },
|
||||
Started {
|
||||
turn_id: String,
|
||||
root_turn_id: String,
|
||||
},
|
||||
/// Core steered an active turn. Persistent thread settings were applied for
|
||||
/// subsequent turns. No new turn was created, so lineage metadata was not
|
||||
/// recorded. If the request included `final_output_json_schema`, the active
|
||||
/// turn already used the same schema.
|
||||
Steered { turn_id: String },
|
||||
Steered {
|
||||
turn_id: String,
|
||||
root_turn_id: String,
|
||||
},
|
||||
/// Core rejected the input without applying settings or start options.
|
||||
NotSubmitted { reason: NotSubmittedReason },
|
||||
}
|
||||
@@ -226,7 +233,10 @@ pub enum TurnInputSubmission {
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum StartIfIdleSubmission {
|
||||
/// Core started a turn. Persistent thread settings and start options were applied.
|
||||
Started { turn_id: String },
|
||||
Started {
|
||||
turn_id: String,
|
||||
root_turn_id: String,
|
||||
},
|
||||
/// Core rejected the input without applying settings or start options.
|
||||
NotSubmitted { reason: NotSubmittedReason },
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user