Preserve item timestamps in thread history projections (#35689)

## What changed

- Add optional start and completion timestamps to `ThreadHistoryItemChange`.
- Populate them from canonical `ItemCompleted` records during stateless thread history projection.
- Treat a zero completion timestamp as absent, and leave timestamps unset for legacy builder events that do not provide them.

## Testing

- Cover projected item timestamps, including missing start times and zero completion times.

GitOrigin-RevId: 2187530f489ad3d86b6ab65faaaab1eab5357f1b
This commit is contained in:
Owen Lin authored and copyberry committed 2026-07-28 00:14:22 +00:00
1 parent 8c72d61727
commit 8d6a91b1ff
4 files changed
+61 -4

No files matched your search

@@ -95,6 +95,8 @@ pub fn build_turns_from_rollout_items(items: &[RolloutItem]) -> Vec<Turn> {
pub struct ThreadHistoryItemChange {
pub turn_id: String,
pub item: ThreadItem,
pub started_at_ms: Option<i64>,
pub completed_at_ms: Option<i64>,
}
/// Lightweight turn metadata snapshot for projectors that track turn status without
@@ -1443,9 +1445,13 @@ impl ThreadHistoryBuilder {
fn record_changed_item(&mut self, turn_id: String, item: ThreadItem) {
if let Some(change_set) = self.active_change_set.as_mut() {
change_set
.changed_items
.push(ThreadHistoryItemChange { turn_id, item });
change_set.changed_items.push(ThreadHistoryItemChange {
turn_id,
item,
// Legacy events used by ThreadHistoryBuilder don't have timestamps
started_at_ms: None,
completed_at_ms: None,
});
}
}
@@ -4446,6 +4452,8 @@ mod tests {
text_elements: Vec::new(),
}],
},
started_at_ms: None,
completed_at_ms: None,
}],
changed_turns: vec![ThreadHistoryTurnChange {
turn_id: "rollout-0".into(),
@@ -4494,6 +4502,8 @@ mod tests {
}),
results: None,
}),
started_at_ms: None,
completed_at_ms: None,
}],
changed_turns: Vec::new(),
removed_turn_ids: Vec::new(),
@@ -4525,6 +4535,8 @@ mod tests {
summary: vec!["summary".into()],
content: vec!["raw content".into()],
},
started_at_ms: None,
completed_at_ms: None,
}],
changed_turns: Vec::new(),
removed_turn_ids: Vec::new(),
@@ -4631,6 +4643,8 @@ mod tests {
}),
results: None,
}),
started_at_ms: None,
completed_at_ms: None,
}],
changed_turns: vec![ThreadHistoryTurnChange {
turn_id: "rollout-0".into(),