mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Preserve root turn attribution in turn-start events (#44611)
## Why Persisted turn-start events lack the originating root turn ID, so they cannot directly associate child turns with the root turn that initiated them. ## What changed - Add optional `root_turn_id` to `TurnStartedEvent`. Use the inherited root turn ID when available, otherwise the turn's own ID. - Centralize turn-start emission for regular turns, shell commands, and manual compaction so they record attribution consistently. - Carry attribution into `ThreadHistoryTurnChange` when processing turn-start events and retain it through completion in the history builder. - Keep older records compatible by defaulting missing attribution to `None`. ## Testing Add coverage for root and child turn attribution, persistence when tool collisions fail a turn before sampling, history change propagation, and deserialization of older turn-start records. GitOrigin-RevId: 54a80b828ca7d1c4c19f13d468c01d052e1b9130
This commit is contained in:
@@ -2174,6 +2174,10 @@ pub struct TurnCompleteEvent {
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]
|
||||
pub struct TurnStartedEvent {
|
||||
pub turn_id: String,
|
||||
/// ID of the originating turn in the root thread; equals `turn_id` for root turns.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub root_turn_id: Option<String>,
|
||||
// Persist for rollout consumers that correlate turns with telemetry traces.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
@@ -4468,6 +4472,16 @@ mod tests {
|
||||
use tempfile::NamedTempFile;
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[test]
|
||||
fn old_turn_started_records_have_no_root_attribution() {
|
||||
let event: TurnStartedEvent = serde_json::from_value(serde_json::json!({
|
||||
"turn_id": "old-turn",
|
||||
"model_context_window": null
|
||||
}))
|
||||
.unwrap();
|
||||
assert_eq!(event.root_turn_id, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn review_decision_denied_round_trip() -> Result<()> {
|
||||
let decision = ReviewDecision::Denied {
|
||||
|
||||
Reference in New Issue
Block a user