mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Keep rejected audio file IDs out of protocol events (#63667)
## Why Codex needs rejected audio file IDs when reconstructing a session so later model requests can omit those attachments. Clients only need the turn error. ## What changed Store rejected audio file IDs as rollout metadata and restore them from that metadata when replaying history. Keep the existing JSONL layout under `error.rejected_audio_file_ids` so older versions can still read newly written rollouts. ## Testing Add a regression test that round-trips a legacy rollout entry and verifies that serializing the protocol event omits the rejected IDs. GitOrigin-RevId: 982dd85d0037cebee056caf61d70988762e42767
This commit is contained in:
@@ -540,7 +540,9 @@ impl ThreadHistoryBuilder {
|
||||
self.current_rollout_index = self.next_rollout_index;
|
||||
self.next_rollout_index += 1;
|
||||
match item {
|
||||
RolloutItem::EventMsg(event) => self.handle_event(event),
|
||||
RolloutItem::EventMsg { event, .. } => {
|
||||
self.handle_event(event);
|
||||
}
|
||||
RolloutItem::Compacted(payload) => self.handle_compacted(payload),
|
||||
RolloutItem::ResponseItem(item) => self.handle_response_item(&item.item),
|
||||
RolloutItem::InterAgentCommunication(_)
|
||||
@@ -4922,7 +4924,6 @@ mod tests {
|
||||
misalignment: None,
|
||||
message: "Selected model is at capacity. Please try a different model.".into(),
|
||||
codex_error_info: Some(CodexErrorInfo::PolicyCapacityUnavailable),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
completed_at: Some(20),
|
||||
duration_ms: Some(10_000),
|
||||
@@ -5334,7 +5335,6 @@ mod tests {
|
||||
misalignment: None,
|
||||
message: "rollback failed".into(),
|
||||
codex_error_info: Some(CodexErrorInfo::ThreadRollbackFailed),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
];
|
||||
|
||||
@@ -5382,7 +5382,6 @@ mod tests {
|
||||
misalignment: None,
|
||||
message: "request-level failure".into(),
|
||||
codex_error_info: Some(CodexErrorInfo::BadRequest),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
];
|
||||
|
||||
@@ -5441,7 +5440,6 @@ mod tests {
|
||||
codex_error_info: Some(CodexErrorInfo::ResponseStreamDisconnected {
|
||||
http_status_code: Some(502),
|
||||
}),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
EventMsg::TurnComplete(TurnCompleteEvent {
|
||||
root_turn_id: None,
|
||||
@@ -5507,7 +5505,6 @@ mod tests {
|
||||
misalignment: None,
|
||||
message: "Selected model is at capacity. Please try a different model.".into(),
|
||||
codex_error_info: Some(CodexErrorInfo::ServerOverloaded),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
completed_at: Some(20),
|
||||
duration_ms: Some(10_000),
|
||||
|
||||
@@ -20,7 +20,10 @@ use crate::protocol::v2::TurnStatus;
|
||||
/// can preserve the first and latest timestamps for repeated item snapshots independently.
|
||||
pub fn project_rollout_line(line: &RolloutLine) -> ThreadHistoryChangeSet {
|
||||
match &line.item {
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event)) => ThreadHistoryChangeSet {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} => ThreadHistoryChangeSet {
|
||||
changed_turns: vec![ThreadHistoryTurnMetadata {
|
||||
turn_id: event.turn_id.clone(),
|
||||
root_turn_id: event.root_turn_id.clone(),
|
||||
@@ -32,7 +35,10 @@ pub fn project_rollout_line(line: &RolloutLine) -> ThreadHistoryChangeSet {
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)) => ThreadHistoryChangeSet {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnComplete(event),
|
||||
..
|
||||
} => ThreadHistoryChangeSet {
|
||||
changed_turns: vec![ThreadHistoryTurnMetadata {
|
||||
turn_id: event.turn_id.clone(),
|
||||
root_turn_id: event.root_turn_id.clone(),
|
||||
@@ -48,7 +54,10 @@ pub fn project_rollout_line(line: &RolloutLine) -> ThreadHistoryChangeSet {
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnAborted(event),
|
||||
..
|
||||
} => {
|
||||
let Some(turn_id) = event.turn_id.as_ref() else {
|
||||
return ThreadHistoryChangeSet::default();
|
||||
};
|
||||
@@ -65,7 +74,10 @@ pub fn project_rollout_line(line: &RolloutLine) -> ThreadHistoryChangeSet {
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event)) => ThreadHistoryChangeSet {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} => ThreadHistoryChangeSet {
|
||||
changed_items: vec![ThreadHistoryItemChange {
|
||||
turn_id: event.turn_id.clone(),
|
||||
item: ThreadItem::from(event),
|
||||
@@ -84,7 +96,7 @@ pub fn project_rollout_line(line: &RolloutLine) -> ThreadHistoryChangeSet {
|
||||
| RolloutItem::RealtimeItem(_)
|
||||
| RolloutItem::RetainedContext(_)
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::EventMsg(_) => ThreadHistoryChangeSet::default(),
|
||||
| RolloutItem::EventMsg { .. } => ThreadHistoryChangeSet::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use codex_history::RolloutEventMetadata;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::items::AgentMessageContent;
|
||||
use codex_protocol::items::AgentMessageItem;
|
||||
@@ -79,11 +80,10 @@ fn projects_failed_turn_completion_as_snapshot() {
|
||||
misalignment: None,
|
||||
message: "request failed".to_string(),
|
||||
codex_error_info: None,
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
};
|
||||
|
||||
let changes = project(RolloutItem::EventMsg(EventMsg::TurnComplete(
|
||||
TurnCompleteEvent {
|
||||
let changes = project(RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnComplete(TurnCompleteEvent {
|
||||
root_turn_id: None,
|
||||
turn_id: "turn-1".to_string(),
|
||||
last_agent_message: None,
|
||||
@@ -92,8 +92,11 @@ fn projects_failed_turn_completion_as_snapshot() {
|
||||
completed_at: Some(20),
|
||||
duration_ms: Some(10_000),
|
||||
time_to_first_token_ms: None,
|
||||
},
|
||||
)));
|
||||
}),
|
||||
metadata: Some(RolloutEventMetadata {
|
||||
rejected_audio_file_ids: vec!["file_rejected".into()],
|
||||
}),
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
changes,
|
||||
|
||||
@@ -513,8 +513,14 @@ impl ExternalAgentSessionImporter {
|
||||
let (created_at, updated_at) = rollout_items
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event)) => event.started_at,
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)) => event.completed_at,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} => event.started_at,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnComplete(event),
|
||||
..
|
||||
} => event.completed_at,
|
||||
_ => None,
|
||||
})
|
||||
.fold(None, |chronology: Option<(i64, i64)>, timestamp| {
|
||||
|
||||
@@ -39,19 +39,22 @@ impl ThreadRequestProcessor {
|
||||
};
|
||||
// The snapshot has complete recorded input, but the old process may have
|
||||
// completed or replaced its turn during the shutdown grace period.
|
||||
let Some(start) = history
|
||||
.iter()
|
||||
.rposition(|item| matches!(item, RolloutItem::EventMsg(EventMsg::TurnStarted(_))))
|
||||
else {
|
||||
let Some(start) = history.iter().rposition(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(_),
|
||||
..
|
||||
}
|
||||
)
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
if !matches!(&history[start], RolloutItem::EventMsg(EventMsg::TurnStarted(event))
|
||||
if !matches!(&history[start], RolloutItem::EventMsg { event: EventMsg::TurnStarted(event), .. }
|
||||
if event.turn_id == saved.turn_id)
|
||||
|| history[start..].iter().any(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)) => {
|
||||
event.turn_id == saved.turn_id
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(event)) => event
|
||||
|| history[start..].iter().any(|item| match item.event_msg() {
|
||||
Some(EventMsg::TurnComplete(event)) => event.turn_id == saved.turn_id,
|
||||
Some(EventMsg::TurnAborted(event)) => event
|
||||
.turn_id
|
||||
.as_ref()
|
||||
.is_none_or(|turn_id| turn_id == &saved.turn_id),
|
||||
|
||||
@@ -22,7 +22,11 @@ impl PersistedResumeSettings {
|
||||
// owner is known, including a legacy update following that owner's checkpoint.
|
||||
let mut latest_legacy = None;
|
||||
for item in history.iter().rev() {
|
||||
let RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) = item else {
|
||||
let RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} = item
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
match event.thread_id {
|
||||
@@ -68,7 +72,10 @@ fn latest_persisted_resume_settings(history: &[RolloutItem]) -> Option<Persisted
|
||||
approvals_reviewer: turn_context.approvals_reviewer.or_else(|| {
|
||||
history[..index].iter().rev().find_map(|item| match item {
|
||||
RolloutItem::TurnContext(turn_context) => turn_context.approvals_reviewer,
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) => Some(
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} => Some(
|
||||
event
|
||||
.thread_settings
|
||||
.requested_approvals_reviewer
|
||||
@@ -83,7 +90,10 @@ fn latest_persisted_resume_settings(history: &[RolloutItem]) -> Option<Persisted
|
||||
turn_context.active_permission_profile.as_ref(),
|
||||
),
|
||||
}),
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} => {
|
||||
let settings = &event.thread_settings;
|
||||
Some(PersistedResumeSettings {
|
||||
approval_policy: settings.approval_policy,
|
||||
@@ -125,7 +135,11 @@ pub(super) fn latest_persisted_model_settings(
|
||||
};
|
||||
let mut crossed_foreign_snapshot = false;
|
||||
for item in history.history.iter().rev() {
|
||||
let RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) = item else {
|
||||
let RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} = item
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
match event.thread_id {
|
||||
|
||||
@@ -251,7 +251,11 @@ fn an_unattributed_snapshot_restores_only_portable_read_only_permissions() {
|
||||
PersistedResumeSettings::from_history(std::slice::from_ref(&item), thread_id),
|
||||
Some(expected)
|
||||
);
|
||||
let RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) = &mut item else {
|
||||
let RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} = &mut item
|
||||
else {
|
||||
unreachable!("fixture must be a settings update");
|
||||
};
|
||||
event.thread_settings.permission_profile = PermissionProfile::Disabled;
|
||||
|
||||
@@ -74,9 +74,15 @@ fn latest_token_usage_turn_id_from_rollout_items(
|
||||
rollout_items: &[RolloutItem],
|
||||
turns: &[Turn],
|
||||
) -> Option<String> {
|
||||
let token_count_index = rollout_items
|
||||
.iter()
|
||||
.rposition(|item| matches!(item, RolloutItem::EventMsg(EventMsg::TokenCount(_))))?;
|
||||
let token_count_index = rollout_items.iter().rposition(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TokenCount(_),
|
||||
..
|
||||
}
|
||||
)
|
||||
})?;
|
||||
let mut builder = ThreadHistoryBuilder::new();
|
||||
for item in &rollout_items[..token_count_index] {
|
||||
builder.handle_rollout_item(item);
|
||||
|
||||
@@ -1234,9 +1234,10 @@ async fn resume_reloads_config_when_saved_workspace_roots_change(
|
||||
);
|
||||
let expected_thread_id = ThreadId::from_string(&thread_id)?;
|
||||
let latest_roots = items.into_iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
if event.thread_id == Some(expected_thread_id) =>
|
||||
{
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} if event.thread_id == Some(expected_thread_id) => {
|
||||
Some(event.thread_settings.runtime_workspace_roots)
|
||||
}
|
||||
_ => None,
|
||||
|
||||
@@ -2080,7 +2080,7 @@ async fn thread_fork_freezes_active_paginated_turn_as_interrupted(
|
||||
[
|
||||
RolloutLine { item: RolloutItem::SessionMeta(_), .. },
|
||||
RolloutLine {
|
||||
item: RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(_)),
|
||||
item: RolloutItem::EventMsg { event: EventMsg::ThreadSettingsApplied(_), .. },
|
||||
..
|
||||
},
|
||||
RolloutLine {
|
||||
@@ -2088,7 +2088,7 @@ async fn thread_fork_freezes_active_paginated_turn_as_interrupted(
|
||||
..
|
||||
},
|
||||
RolloutLine {
|
||||
item: RolloutItem::EventMsg(EventMsg::TurnAborted(aborted)),
|
||||
item: RolloutItem::EventMsg { event: EventMsg::TurnAborted(aborted), .. },
|
||||
..
|
||||
},
|
||||
] if matches!(
|
||||
|
||||
@@ -869,9 +869,10 @@ async fn thread_resume_restores_startup_and_updated_runtime_workspace_roots() ->
|
||||
.into_iter()
|
||||
.rev()
|
||||
.filter_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) => {
|
||||
Some(event.thread_settings.runtime_workspace_roots)
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} => Some(event.thread_settings.runtime_workspace_roots),
|
||||
_ => None,
|
||||
})
|
||||
.take(/*n*/ 3)
|
||||
@@ -1056,15 +1057,14 @@ sandbox = "unelevated"
|
||||
let expected_thread_id = ThreadId::from_string(&thread_id)?;
|
||||
let (items, _, _) = RolloutRecorder::load_rollout_items(&path).await?;
|
||||
let persisted = items.into_iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
if event.thread_id == Some(expected_thread_id) =>
|
||||
{
|
||||
Some((
|
||||
event.thread_settings.cwd,
|
||||
event.thread_settings.runtime_workspace_roots,
|
||||
event.thread_settings.permission_profile,
|
||||
))
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} if event.thread_id == Some(expected_thread_id) => Some((
|
||||
event.thread_settings.cwd,
|
||||
event.thread_settings.runtime_workspace_roots,
|
||||
event.thread_settings.permission_profile,
|
||||
)),
|
||||
_ => None,
|
||||
});
|
||||
let (persisted_cwd, persisted_roots, permission_profile) =
|
||||
@@ -1569,8 +1569,10 @@ async fn thread_resume_preserves_goal_first_and_fork_approvals_reviewer() -> Res
|
||||
items
|
||||
.into_iter()
|
||||
.filter_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) =>
|
||||
event.thread_id,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} => event.thread_id,
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
@@ -1844,10 +1846,12 @@ async fn thread_resume_preserves_acknowledged_model_effort_and_approvals_reviewe
|
||||
);
|
||||
let (items, _, _) = RolloutRecorder::load_rollout_items(&rollout_path).await?;
|
||||
let mode = items.iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
if event
|
||||
.thread_id
|
||||
.is_some_and(|id| id.to_string() == thread_id) =>
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} if event
|
||||
.thread_id
|
||||
.is_some_and(|id| id.to_string() == thread_id) =>
|
||||
{
|
||||
Some(event.thread_settings.collaboration_mode.clone())
|
||||
}
|
||||
@@ -1902,7 +1906,10 @@ async fn thread_resume_restores_collaboration_mode_from_legacy_turn_context() ->
|
||||
let (items, _, _) = RolloutRecorder::load_rollout_items(&fixture.rollout_file_path).await?;
|
||||
assert!(!items.iter().any(|item| matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(_))
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(_),
|
||||
..
|
||||
}
|
||||
)));
|
||||
let mut mcp = TestAppServer::builder()
|
||||
.with_codex_home(codex_home.path())
|
||||
@@ -5280,7 +5287,7 @@ async fn thread_resume_checkpoints_settings_without_advancing_recency() -> Resul
|
||||
let (items, _, _) = RolloutRecorder::load_rollout_items(&rollout.rollout_file_path).await?;
|
||||
assert!(items.iter().any(|item| matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
RolloutItem::EventMsg { event: EventMsg::ThreadSettingsApplied(event), .. }
|
||||
if event.thread_id == Some(expected_thread_id)
|
||||
)));
|
||||
|
||||
@@ -6443,9 +6450,10 @@ async fn thread_resume_with_overrides_preserves_recency_and_checkpoints_model()
|
||||
let expected_thread_id = ThreadId::from_string(&resumed_thread.id)?;
|
||||
let (items, _, _) = RolloutRecorder::load_rollout_items(&rollout_file_path).await?;
|
||||
let persisted_model = items.iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
if event.thread_id == Some(expected_thread_id) =>
|
||||
{
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} if event.thread_id == Some(expected_thread_id) => {
|
||||
Some(event.thread_settings.model.as_str())
|
||||
}
|
||||
_ => None,
|
||||
@@ -6494,7 +6502,10 @@ async fn thread_resume_does_not_checkpoint_unchanged_settings() -> Result<()> {
|
||||
let settings_before_resume = items
|
||||
.into_iter()
|
||||
.filter_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) => Some(event),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} => Some(event),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@@ -6513,7 +6524,10 @@ async fn thread_resume_does_not_checkpoint_unchanged_settings() -> Result<()> {
|
||||
let settings_after_resume = items
|
||||
.into_iter()
|
||||
.filter_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) => Some(event),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} => Some(event),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@@ -306,11 +306,10 @@ async fn thread_revert_preserves_fork_cutoff_after_cold_resume() -> Result<()> {
|
||||
.collect::<Result<Vec<_>, _>>()?
|
||||
.into_iter()
|
||||
.find_map(|line| match line.item {
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(turn))
|
||||
if turn.turn_id == parent_turns[1] =>
|
||||
{
|
||||
line.ordinal
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(turn),
|
||||
..
|
||||
} if turn.turn_id == parent_turns[1] => line.ordinal,
|
||||
_ => None,
|
||||
})
|
||||
.expect("inherited turn start ordinal");
|
||||
|
||||
@@ -567,7 +567,6 @@ async fn on_event_updates_status_from_task_complete() {
|
||||
misalignment: None,
|
||||
message: "denied".to_string(),
|
||||
codex_error_info: None,
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
AgentStatus::Errored("denied".to_string()),
|
||||
),
|
||||
@@ -592,7 +591,6 @@ async fn on_event_updates_status_from_error() {
|
||||
misalignment: None,
|
||||
message: "boom".to_string(),
|
||||
codex_error_info: None,
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}));
|
||||
|
||||
let expected = AgentStatus::Errored("boom".to_string());
|
||||
@@ -2563,9 +2561,10 @@ async fn spawn_agent_fork_from_paginated_parent_uses_model_context_prefix(
|
||||
!copied_prefix.iter().any(|line| {
|
||||
matches!(
|
||||
&line.item,
|
||||
RolloutItem::EventMsg(
|
||||
EventMsg::ItemCompleted(_) | EventMsg::ThreadSettingsApplied(_)
|
||||
)
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(_) | EventMsg::ThreadSettingsApplied(_),
|
||||
..
|
||||
}
|
||||
)
|
||||
}),
|
||||
"copied non-structural presentation and metadata records should not enter the child rollout"
|
||||
|
||||
@@ -57,12 +57,13 @@ fn sanitize_forked_rollout_item(
|
||||
|| history_mode == ThreadHistoryMode::Paginated
|
||||
&& matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(
|
||||
EventMsg::ItemCompleted(_)
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(_)
|
||||
| EventMsg::TokenCount(_)
|
||||
| EventMsg::ThreadGoalUpdated(_)
|
||||
| EventMsg::ThreadSettingsApplied(_)
|
||||
)
|
||||
| EventMsg::ThreadSettingsApplied(_),
|
||||
..
|
||||
}
|
||||
)
|
||||
{
|
||||
return false;
|
||||
@@ -164,9 +165,10 @@ pub(crate) fn sanitize_referenced_agent_fork(
|
||||
let boundary = history
|
||||
.iter()
|
||||
.position(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) => {
|
||||
event.thread_id == Some(thread_id)
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} => event.thread_id == Some(thread_id),
|
||||
// A bounded context scan can begin at a child-owned compaction, omitting
|
||||
// the original startup event. Its catalog snapshot identifies its owner.
|
||||
RolloutItem::Compacted(checkpoint) => checkpoint
|
||||
@@ -283,7 +285,7 @@ fn keep_forked_rollout_item(item: &RolloutItem, preserve_context_baselines: bool
|
||||
RolloutItem::TokenUsageRecord(_) => false,
|
||||
RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::Compacted(_)
|
||||
| RolloutItem::EventMsg(_)
|
||||
| RolloutItem::EventMsg { .. }
|
||||
| RolloutItem::SessionMeta(_) => true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,6 @@ use codex_protocol::openai_models::InputModality;
|
||||
use codex_protocol::protocol::InterAgentCommunication;
|
||||
use codex_protocol::protocol::TokenUsage;
|
||||
use codex_protocol::protocol::TokenUsageInfo;
|
||||
use codex_protocol::protocol::TurnCompleteEvent;
|
||||
use codex_protocol::protocol::TurnContextItem;
|
||||
use codex_protocol::protocol::WorldStateItem;
|
||||
use codex_thread_context_ids::ThreadContextIds;
|
||||
@@ -855,14 +854,6 @@ impl ContextManager {
|
||||
&self.items
|
||||
}
|
||||
|
||||
/// Apply the durable failed-turn record without rewriting retained user history.
|
||||
pub(crate) fn record_rejected_file_audio(&mut self, event: &TurnCompleteEvent) {
|
||||
let Some(error) = &event.error else {
|
||||
return;
|
||||
};
|
||||
self.extend_rejected_audio_file_ids(error.rejected_audio_file_ids.iter().cloned());
|
||||
}
|
||||
|
||||
pub(crate) fn extend_rejected_audio_file_ids(&mut self, ids: impl IntoIterator<Item = String>) {
|
||||
let mut ids = ids.into_iter().peekable();
|
||||
if ids.peek().is_none() {
|
||||
|
||||
@@ -816,7 +816,6 @@ async fn wait_for_guardian_review_ignores_prior_turn_errors() {
|
||||
misalignment: None,
|
||||
message: "stale guardian error".to_string(),
|
||||
codex_error_info: None,
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
})
|
||||
.await
|
||||
@@ -865,7 +864,6 @@ async fn wait_for_guardian_review_preserves_structured_session_error() {
|
||||
misalignment: None,
|
||||
message: "temporary failure".to_string(),
|
||||
codex_error_info: Some(CodexErrorInfo::ServerOverloaded),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
})
|
||||
.await
|
||||
|
||||
@@ -717,7 +717,6 @@ pub(crate) async fn run_legacy_after_agent_hook(
|
||||
misalignment: None,
|
||||
message,
|
||||
codex_error_info: Some(CodexErrorInfo::Other),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
});
|
||||
sess.send_event(turn_context, event).await;
|
||||
true
|
||||
|
||||
@@ -3760,7 +3760,6 @@ async fn send_conversation_error(
|
||||
misalignment: None,
|
||||
message,
|
||||
codex_error_info: Some(codex_error_info),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
})
|
||||
.await;
|
||||
|
||||
@@ -300,7 +300,6 @@ pub async fn compact(sess: &Arc<Session>, sub_id: String) {
|
||||
misalignment: None,
|
||||
message,
|
||||
codex_error_info: Some(CodexErrorInfo::BadRequest),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
})
|
||||
};
|
||||
if let Err(error) = sess.tx_event.try_send(Event { id: sub_id, msg }) {
|
||||
@@ -353,7 +352,6 @@ pub async fn set_thread_memory_mode(sess: &Arc<Session>, sub_id: String, mode: T
|
||||
misalignment: None,
|
||||
message: err.to_string(),
|
||||
codex_error_info: Some(CodexErrorInfo::Other),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
};
|
||||
sess.send_event_raw(event).await;
|
||||
@@ -513,7 +511,6 @@ pub async fn shutdown(sess: &Arc<Session>, sub_id: String) -> bool {
|
||||
misalignment: None,
|
||||
message: "Failed to shutdown thread persistence".to_string(),
|
||||
codex_error_info: Some(CodexErrorInfo::Other),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
};
|
||||
sess.send_event_raw(event).await;
|
||||
@@ -563,7 +560,6 @@ pub async fn review(
|
||||
misalignment: None,
|
||||
message: err.to_string(),
|
||||
codex_error_info: Some(CodexErrorInfo::Other),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
};
|
||||
sess.send_event(&turn_context, event.msg).await;
|
||||
@@ -729,7 +725,6 @@ pub(super) async fn submission_loop(
|
||||
misalignment: None,
|
||||
message: err.to_string(),
|
||||
codex_error_info: Some(CodexErrorInfo::Other),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
})
|
||||
.await;
|
||||
@@ -870,7 +865,6 @@ pub(super) async fn submission_loop(
|
||||
misalignment: None,
|
||||
message,
|
||||
codex_error_info: Some(CodexErrorInfo::BadRequest),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
})
|
||||
.await;
|
||||
|
||||
@@ -89,6 +89,7 @@ use codex_features::Feature;
|
||||
use codex_features::Features;
|
||||
use codex_features::unstable_features_warning_event;
|
||||
use codex_history::HistoryInitialization;
|
||||
use codex_history::RolloutEventMetadata;
|
||||
use codex_history::RolloutItem;
|
||||
use codex_hooks::Hooks;
|
||||
use codex_hooks::HooksConfig;
|
||||
@@ -238,6 +239,7 @@ use crate::config::StartedNetworkProxy;
|
||||
use crate::config::resolve_web_search_mode_for_turn;
|
||||
use crate::context_manager::ContextManager;
|
||||
use crate::context_manager::HistoryReplacement;
|
||||
use crate::context_manager::rejected_audio::RejectedAudioFileIds;
|
||||
use crate::thread_rollout_truncation::initial_history_has_prior_user_turns;
|
||||
use codex_config::CONFIG_TOML_FILE;
|
||||
use codex_config::ConfigLayerSource;
|
||||
@@ -1858,10 +1860,10 @@ impl Session {
|
||||
let turn_context = self.new_default_turn().await;
|
||||
let rollout_items = resumed_history.history;
|
||||
if matches!(
|
||||
rollout_items.iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(event) => agent_status_from_event(event),
|
||||
_ => None,
|
||||
}),
|
||||
rollout_items
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|item| { item.event_msg().and_then(agent_status_from_event) }),
|
||||
Some(AgentStatus::Interrupted)
|
||||
) {
|
||||
self.agent_status.send_replace(AgentStatus::Interrupted);
|
||||
@@ -1902,11 +1904,10 @@ impl Session {
|
||||
let thread_id = self.thread_id();
|
||||
let current_settings = self.thread_settings_snapshot().await;
|
||||
let persisted_settings = rollout_items.iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
if event.thread_id == Some(thread_id) =>
|
||||
{
|
||||
Some(&event.thread_settings)
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} if event.thread_id == Some(thread_id) => Some(&event.thread_settings),
|
||||
_ => None,
|
||||
});
|
||||
// Persist changed effective settings even when no turn follows the resume.
|
||||
@@ -2170,7 +2171,10 @@ impl Session {
|
||||
|
||||
fn last_token_info_from_rollout(rollout_items: &[RolloutItem]) -> Option<TokenUsageInfo> {
|
||||
rollout_items.iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::TokenCount(ev)) => ev.info.clone(),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TokenCount(ev),
|
||||
..
|
||||
} => ev.info.clone(),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
@@ -2789,7 +2793,7 @@ impl Session {
|
||||
}
|
||||
|
||||
/// Persist the event to rollout and send it to clients.
|
||||
pub(crate) async fn send_event(&self, turn_context: &TurnContext, mut msg: EventMsg) {
|
||||
pub(crate) async fn send_event(&self, turn_context: &TurnContext, msg: EventMsg) {
|
||||
crate::agent::turn_metrics::record_terminal_event(turn_context, &msg);
|
||||
if let Some((item_id, started_at_ms)) = msg.command_approval_start() {
|
||||
// The client can see the command before execution. Keep its first start
|
||||
@@ -2799,30 +2803,33 @@ impl Session {
|
||||
.record_item_started(item_id.to_owned(), started_at_ms)
|
||||
.await;
|
||||
}
|
||||
if let EventMsg::TurnComplete(completed) = &msg
|
||||
let metadata = if let EventMsg::TurnComplete(completed) = &msg
|
||||
&& completed.error.is_some()
|
||||
&& let Some(rejected) = turn_context.extension_data.remove::<RejectedAudioFileIds>()
|
||||
{
|
||||
let file_ids = Arc::unwrap_or_clone(rejected).0;
|
||||
self.state
|
||||
.lock()
|
||||
.await
|
||||
.history
|
||||
.record_rejected_file_audio(completed);
|
||||
}
|
||||
if let EventMsg::Error(error) = &mut msg
|
||||
.extend_rejected_audio_file_ids(file_ids.iter().cloned());
|
||||
Some(RolloutEventMetadata {
|
||||
rejected_audio_file_ids: file_ids,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let EventMsg::Error(error) = &msg
|
||||
&& error
|
||||
.codex_error_info
|
||||
.as_ref()
|
||||
.is_some_and(CodexErrorInfo::affects_turn_status)
|
||||
{
|
||||
let mut terminal_error = turn_context.terminal_error.lock().await;
|
||||
if let Some(previous) = terminal_error.as_ref() {
|
||||
for file_id in &previous.rejected_audio_file_ids {
|
||||
if !error.rejected_audio_file_ids.contains(file_id) {
|
||||
error.rejected_audio_file_ids.push(file_id.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
terminal_error.replace(error.clone());
|
||||
turn_context
|
||||
.terminal_error
|
||||
.lock()
|
||||
.await
|
||||
.replace(error.clone());
|
||||
}
|
||||
let legacy_source = msg.clone();
|
||||
self.services
|
||||
@@ -2853,7 +2860,7 @@ impl Session {
|
||||
.analytics_events_client
|
||||
.track_guardian_session_event(self.thread_id, &event);
|
||||
}
|
||||
self.send_event_raw(event).await;
|
||||
Box::pin(self.send_event_raw_with_persistence(event, /*persist*/ true, metadata)).await;
|
||||
self.maybe_publish_terminal_agent_result(turn_context, &legacy_source)
|
||||
.await;
|
||||
self.maybe_mirror_event_text_to_realtime(&legacy_source)
|
||||
@@ -3028,7 +3035,12 @@ impl Session {
|
||||
|
||||
pub(crate) async fn send_event_raw(&self, event: Event) {
|
||||
// Keep event persistence out of callers' stack frames.
|
||||
Box::pin(self.send_event_raw_with_persistence(event, /*persist*/ true)).await;
|
||||
Box::pin(
|
||||
self.send_event_raw_with_persistence(
|
||||
event, /*persist*/ true, /*metadata*/ None,
|
||||
),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Delivers an event without creating a local rollout for a thread that has not materialized.
|
||||
@@ -3041,10 +3053,16 @@ impl Session {
|
||||
true
|
||||
}
|
||||
};
|
||||
self.send_event_raw_with_persistence(event, persist).await;
|
||||
self.send_event_raw_with_persistence(event, persist, /*metadata*/ None)
|
||||
.await;
|
||||
}
|
||||
|
||||
async fn send_event_raw_with_persistence(&self, event: Event, persist: bool) {
|
||||
async fn send_event_raw_with_persistence(
|
||||
&self,
|
||||
event: Event,
|
||||
persist: bool,
|
||||
metadata: Option<RolloutEventMetadata>,
|
||||
) {
|
||||
let flush_guardian_completion = persist
|
||||
&& matches!(event.msg, EventMsg::TurnComplete(_))
|
||||
&& self.is_private_guardian_reviewer().await;
|
||||
@@ -3076,7 +3094,10 @@ impl Session {
|
||||
}
|
||||
// Persist the event into rollout storage; the store applies its persistence policy.
|
||||
if persist {
|
||||
let rollout_items = vec![RolloutItem::EventMsg(event.msg.clone())];
|
||||
let rollout_items = vec![RolloutItem::EventMsg {
|
||||
event: event.msg.clone(),
|
||||
metadata,
|
||||
}];
|
||||
self.persist_rollout_items(&rollout_items).await;
|
||||
}
|
||||
self.services
|
||||
|
||||
@@ -321,7 +321,6 @@ impl Session {
|
||||
misalignment: None,
|
||||
message: format!("failed to submit turn input: {reason:?}"),
|
||||
codex_error_info: Some(CodexErrorInfo::BadRequest),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
})
|
||||
.await;
|
||||
|
||||
@@ -245,11 +245,12 @@ impl ContextManager {
|
||||
.extend(metadata.rejected_audio_file_ids.iter().cloned());
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(completed)) => {
|
||||
if let Some(error) = &completed.error {
|
||||
rejected_audio_file_ids
|
||||
.extend(error.rejected_audio_file_ids.iter().cloned());
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
metadata: Some(metadata),
|
||||
..
|
||||
} => {
|
||||
rejected_audio_file_ids
|
||||
.extend(metadata.rejected_audio_file_ids.iter().cloned());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -284,7 +285,10 @@ impl ContextManager {
|
||||
.iter()
|
||||
.rev()
|
||||
.filter_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event)) => Some(event.turn_id.as_str()),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} => Some(event.turn_id.as_str()),
|
||||
RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SessionMeta(_)
|
||||
| RolloutItem::ResponseItem(_)
|
||||
@@ -297,14 +301,17 @@ impl ContextManager {
|
||||
| RolloutItem::TokenUsageRecord(_)
|
||||
| RolloutItem::RealtimeItem(_)
|
||||
| RolloutItem::Compacted(_)
|
||||
| RolloutItem::EventMsg(_) => None,
|
||||
| RolloutItem::EventMsg { .. } => None,
|
||||
})
|
||||
.peekable();
|
||||
let last_started_turn_id = replay_items
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event)) => Some(event.turn_id.clone()),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} => Some(event.turn_id.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.or_else(|| resume_metadata.and_then(|metadata| metadata.last_started_turn_id.clone()));
|
||||
@@ -362,11 +369,17 @@ impl ContextManager {
|
||||
});
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(rollback)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadRolledBack(rollback),
|
||||
..
|
||||
} => {
|
||||
pending_rollback_turns = pending_rollback_turns
|
||||
.saturating_add(usize::try_from(rollback.num_turns).unwrap_or(usize::MAX));
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnComplete(event),
|
||||
..
|
||||
} => {
|
||||
// Stop hooks can finish after a newer turn has started.
|
||||
if !turn_ids_are_compatible(preceding_turn_id, Some(event.turn_id.as_str())) {
|
||||
late_completed_turn_ids.insert(event.turn_id.as_str());
|
||||
@@ -381,7 +394,10 @@ impl ContextManager {
|
||||
active_segment.turn_id = Some(event.turn_id.clone());
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnAborted(event),
|
||||
..
|
||||
} => {
|
||||
if !turn_ids_are_compatible(preceding_turn_id, event.turn_id.as_deref()) {
|
||||
continue;
|
||||
}
|
||||
@@ -398,7 +414,10 @@ impl ContextManager {
|
||||
});
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(_)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(_),
|
||||
..
|
||||
} => {
|
||||
let active_segment =
|
||||
active_segment.get_or_insert_with(ActiveReplaySegment::default);
|
||||
active_segment.counts_as_user_turn = true;
|
||||
@@ -435,7 +454,10 @@ impl ContextManager {
|
||||
active_segment.get_or_insert_with(ActiveReplaySegment::default);
|
||||
active_segment.world_state_replay.push(item);
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} => {
|
||||
started_turn_ids.next();
|
||||
// Startup can be suspended before any input or context is written.
|
||||
// Explicit start attribution is authoritative, including unknown fields.
|
||||
@@ -486,7 +508,7 @@ impl ContextManager {
|
||||
active_segment.get_or_insert_with(ActiveReplaySegment::default);
|
||||
active_segment.counts_as_user_turn = true;
|
||||
}
|
||||
RolloutItem::EventMsg(_)
|
||||
RolloutItem::EventMsg { .. }
|
||||
| RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SessionMeta(_)
|
||||
| RolloutItem::RealtimeItem(_)
|
||||
@@ -617,10 +639,13 @@ impl ContextManager {
|
||||
history.restore_retained_context(Some(&retained_context));
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(rollback)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadRolledBack(rollback),
|
||||
..
|
||||
} => {
|
||||
history.drop_last_n_user_turns(rollback.num_turns);
|
||||
}
|
||||
RolloutItem::EventMsg(_)
|
||||
RolloutItem::EventMsg { .. }
|
||||
| RolloutItem::TurnContext(_)
|
||||
| RolloutItem::WorldState(_)
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
@@ -669,7 +694,7 @@ impl ContextManager {
|
||||
| RolloutItem::TokenUsageRecord(_)
|
||||
| RolloutItem::RetainedContext(_)
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::EventMsg(_) => {
|
||||
| RolloutItem::EventMsg { .. } => {
|
||||
unreachable!("only world-state replay items are collected")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1673,7 +1673,10 @@ async fn bounded_replay_matches_full_replay_after_empty_turn_compactions(
|
||||
wake_items.retain(|item| {
|
||||
!matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(_) | EventMsg::TurnComplete(_))
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(_) | EventMsg::TurnComplete(_),
|
||||
..
|
||||
}
|
||||
)
|
||||
});
|
||||
wake_items.push(RolloutItem::EventMsg(EventMsg::TurnAborted(
|
||||
@@ -1793,14 +1796,22 @@ async fn reconstruct_attribution_ignores_previous_turn_terminal(evidence: Attrib
|
||||
current_context.turn_id = Some(expected.turn_id.clone());
|
||||
current_context.root_turn_id = expected.root_turn_id.clone();
|
||||
let mut rollout = completed_user_turn_rollout(turn_context.to_turn_context_item(), Vec::new());
|
||||
let RolloutItem::EventMsg(EventMsg::TurnStarted(start)) = &mut rollout[0] else {
|
||||
let RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(start),
|
||||
..
|
||||
} = &mut rollout[0]
|
||||
else {
|
||||
panic!("expected previous turn start");
|
||||
};
|
||||
start.turn_attribution = Some(older_attribution.clone());
|
||||
let mut late_terminal = rollout.pop().expect("previous turn completion");
|
||||
let mut current = completed_user_turn_rollout(current_context, Vec::new());
|
||||
current.pop().expect("current turn completion");
|
||||
let RolloutItem::EventMsg(EventMsg::TurnStarted(start)) = &mut current[0] else {
|
||||
let RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(start),
|
||||
..
|
||||
} = &mut current[0]
|
||||
else {
|
||||
panic!("expected current turn start");
|
||||
};
|
||||
start.turn_attribution = Some(expected.clone());
|
||||
|
||||
@@ -1789,7 +1789,9 @@ impl Session {
|
||||
mcp_runtime.restore_resource_origin_checkpoint(checkpoint);
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(event) => mcp_runtime.observe_event(event),
|
||||
RolloutItem::EventMsg { event, .. } => {
|
||||
mcp_runtime.observe_event(event);
|
||||
}
|
||||
RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SessionMeta(_)
|
||||
| RolloutItem::ResponseItem(_)
|
||||
|
||||
@@ -4047,7 +4047,7 @@ async fn start_new_context_window_persists_checkpoint_state(clear_tools: bool) {
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::TokenUsageRecord(_)
|
||||
| RolloutItem::RealtimeItem(_)
|
||||
| RolloutItem::EventMsg(_) => None,
|
||||
| RolloutItem::EventMsg { .. } => None,
|
||||
});
|
||||
let mut expected_history = live_history.annotated_items().to_vec();
|
||||
// Compaction's parallel metadata vector represents absent entries as default metadata.
|
||||
@@ -4152,7 +4152,7 @@ async fn record_initial_history_assigns_and_persists_id_for_forked_response_item
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::TokenUsageRecord(_)
|
||||
| RolloutItem::RealtimeItem(_)
|
||||
| RolloutItem::EventMsg(_) => None,
|
||||
| RolloutItem::EventMsg { .. } => None,
|
||||
});
|
||||
let persisted_item = persisted_item.expect("forked response item should be persisted");
|
||||
assert_eq!(
|
||||
@@ -5926,9 +5926,10 @@ async fn settings_checkpoint_waits_for_accepted_settings_persistence() {
|
||||
let snapshots = items
|
||||
.into_iter()
|
||||
.filter_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) => {
|
||||
Some((event.thread_id, event.thread_settings))
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} => Some((event.thread_id, event.thread_settings)),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@@ -6150,7 +6151,10 @@ async fn compaction_persists_resume_metadata_and_companion_records() {
|
||||
RolloutItem::Compacted(compacted),
|
||||
RolloutItem::WorldState(saved_world_state),
|
||||
RolloutItem::TurnContext(saved_turn_context),
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(saved_settings)),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(saved_settings),
|
||||
..
|
||||
},
|
||||
] = compaction_items.as_slice()
|
||||
else {
|
||||
panic!("unexpected compaction records: {compaction_items:#?}");
|
||||
|
||||
@@ -1023,7 +1023,6 @@ pub(crate) async fn run_turn(
|
||||
message: "Invalid image in your last message. Please remove it and try again."
|
||||
.to_string(),
|
||||
codex_error_info: Some(error),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
});
|
||||
sess.send_event(&turn_context, event).await;
|
||||
break;
|
||||
@@ -1052,16 +1051,11 @@ pub(crate) async fn run_turn(
|
||||
.await;
|
||||
sess.track_turn_codex_error(turn_context.as_ref(), &e);
|
||||
let mut error_event = e.to_error_event(/*message_prefix*/ None);
|
||||
if let Some(rejected) = turn_context
|
||||
.extension_data
|
||||
.remove::<rejected_audio::RejectedAudioFileIds>()
|
||||
{
|
||||
error_event
|
||||
.rejected_audio_file_ids
|
||||
.extend(Arc::unwrap_or_clone(rejected).0);
|
||||
}
|
||||
if matches!(e.details(), CodexErrorDetails::InvalidAudioInput { .. })
|
||||
|| !error_event.rejected_audio_file_ids.is_empty()
|
||||
|| turn_context
|
||||
.extension_data
|
||||
.get::<rejected_audio::RejectedAudioFileIds>()
|
||||
.is_some()
|
||||
{
|
||||
error_event.message.push_str(
|
||||
" Please remove or replace the affected audio attachment and try again.",
|
||||
|
||||
@@ -1264,7 +1264,6 @@ impl Session {
|
||||
misalignment: None,
|
||||
message: message.clone(),
|
||||
codex_error_info: Some(CodexErrorInfo::BadRequest),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
})
|
||||
.await;
|
||||
|
||||
@@ -756,7 +756,6 @@ async fn admission_revalidates_constraints_before_committing(kind: TurnStartKind
|
||||
misalignment: None,
|
||||
message: expected_message,
|
||||
codex_error_info: Some(CodexErrorInfo::BadRequest),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}]
|
||||
);
|
||||
assert_eq!(session.thread_settings_snapshot().await, desired_settings);
|
||||
|
||||
@@ -359,7 +359,6 @@ async fn send_user_shell_error(session: &Session, turn_context: &TurnContext, me
|
||||
misalignment: None,
|
||||
message: message.to_string(),
|
||||
codex_error_info: None,
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -3493,8 +3493,8 @@ fn snapshot_turn_state(history: &InitialHistory) -> SnapshotTurnState {
|
||||
SnapshotTurnState {
|
||||
ends_mid_turn: !rollout_items[last_user_position + 1..].iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(_) | EventMsg::TurnAborted(_))
|
||||
item.event_msg(),
|
||||
Some(EventMsg::TurnComplete(_) | EventMsg::TurnAborted(_))
|
||||
)
|
||||
}),
|
||||
active_turn_id: None,
|
||||
|
||||
@@ -4276,7 +4276,7 @@ async fn interrupted_fork_snapshot_preserves_explicit_turn_id() {
|
||||
assert!(rollout_items.iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(TurnAbortedEvent {
|
||||
RolloutItem::EventMsg { event: EventMsg::TurnAborted(TurnAbortedEvent {
|
||||
root_turn_id: None,
|
||||
turn_id: Some(turn_id),
|
||||
started_at: None,
|
||||
@@ -4284,7 +4284,7 @@ async fn interrupted_fork_snapshot_preserves_explicit_turn_id() {
|
||||
error: None,
|
||||
completed_at: None,
|
||||
duration_ms: None,
|
||||
})) if turn_id == "turn-explicit"
|
||||
}), .. } if turn_id == "turn-explicit"
|
||||
)
|
||||
}));
|
||||
}
|
||||
@@ -4419,10 +4419,13 @@ async fn interrupted_fork_snapshot_uses_persisted_mid_turn_history_without_live_
|
||||
.filter(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(TurnAbortedEvent {
|
||||
reason: TurnAbortReason::Interrupted,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnAborted(TurnAbortedEvent {
|
||||
reason: TurnAbortReason::Interrupted,
|
||||
..
|
||||
}),
|
||||
..
|
||||
}))
|
||||
}
|
||||
)
|
||||
})
|
||||
.count(),
|
||||
|
||||
@@ -57,7 +57,10 @@ pub(crate) fn user_message_positions_in_rollout(items: &[RolloutItem]) -> Vec<us
|
||||
{
|
||||
user_positions.push(idx);
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(rollback)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadRolledBack(rollback),
|
||||
..
|
||||
} => {
|
||||
let num_turns = usize::try_from(rollback.num_turns).unwrap_or(usize::MAX);
|
||||
let new_len = user_positions.len().saturating_sub(num_turns);
|
||||
user_positions.truncate(new_len);
|
||||
@@ -122,7 +125,7 @@ pub fn truncate_rollout_after_turn_id(
|
||||
.position(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event))
|
||||
RolloutItem::EventMsg { event: EventMsg::TurnStarted(event), .. }
|
||||
if event.turn_id == last_turn_id
|
||||
)
|
||||
})
|
||||
@@ -143,7 +146,14 @@ pub fn truncate_rollout_after_turn_id(
|
||||
.enumerate()
|
||||
.skip(target_start_index.saturating_add(1))
|
||||
.find_map(|(index, item)| {
|
||||
matches!(item, RolloutItem::EventMsg(EventMsg::TurnStarted(_))).then_some(index)
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(_),
|
||||
..
|
||||
}
|
||||
)
|
||||
.then_some(index)
|
||||
})
|
||||
.unwrap_or(items.len());
|
||||
items.truncate(cut_index);
|
||||
@@ -158,7 +168,7 @@ pub fn truncate_rollout_before_turn_id(
|
||||
let cut_index = items.iter().position(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event))
|
||||
RolloutItem::EventMsg { event: EventMsg::TurnStarted(event), .. }
|
||||
if event.turn_id == before_turn_id
|
||||
)
|
||||
});
|
||||
@@ -180,12 +190,17 @@ pub fn truncate_rollout_before_turn_id(
|
||||
};
|
||||
|
||||
// A persisted turn boundary proves the turn exists unless a later rollback removes it.
|
||||
if items[cut_index + 1..]
|
||||
if items[cut_index + 1..].iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadRolledBack(_),
|
||||
..
|
||||
}
|
||||
)
|
||||
}) && !build_turns_from_rollout_items(&items)
|
||||
.iter()
|
||||
.any(|item| matches!(item, RolloutItem::EventMsg(EventMsg::ThreadRolledBack(_))))
|
||||
&& !build_turns_from_rollout_items(&items)
|
||||
.iter()
|
||||
.any(|turn| turn.id == before_turn_id)
|
||||
.any(|turn| turn.id == before_turn_id)
|
||||
{
|
||||
return Err(CodexErr::InvalidRequest(format!(
|
||||
"beforeTurnId '{before_turn_id}' was not found in the source thread"
|
||||
|
||||
@@ -309,7 +309,7 @@ async fn root_turn_suspension_preserves_unfinished_turn_history(fail_child_write
|
||||
codex_rollout::parse_rollout_line(line)
|
||||
.expect("parse child rollout")
|
||||
.item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(_))
|
||||
RolloutItem::EventMsg { event: EventMsg::TurnAborted(_), .. }
|
||||
)));
|
||||
let rollout_path = codex.rollout_path().expect("rollout path");
|
||||
let rollout = tokio::fs::read_to_string(&rollout_path)
|
||||
@@ -325,7 +325,10 @@ async fn root_turn_suspension_preserves_unfinished_turn_history(fail_child_write
|
||||
.collect::<Vec<_>>();
|
||||
assert!(items.iter().all(|item| !matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(_) | EventMsg::TurnComplete(_))
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnAborted(_) | EventMsg::TurnComplete(_),
|
||||
..
|
||||
}
|
||||
)));
|
||||
test.thread_manager
|
||||
.remove_thread(&test.session_configured.thread_id)
|
||||
@@ -583,7 +586,13 @@ async fn graceful_suspend_preserves_a_finishing_child_result(
|
||||
assert_eq!(
|
||||
history
|
||||
.iter()
|
||||
.filter(|item| matches!(item, RolloutItem::EventMsg(EventMsg::TurnStarted(_))))
|
||||
.filter(|item| matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(_),
|
||||
..
|
||||
}
|
||||
))
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
|
||||
@@ -269,7 +269,11 @@ async fn child_turn_start_preserves_root_attribution() -> Result<()> {
|
||||
})
|
||||
.await?;
|
||||
for item in history.items {
|
||||
if let codex_history::RolloutItem::EventMsg(EventMsg::TurnStarted(event)) = item {
|
||||
if let codex_history::RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} = item
|
||||
{
|
||||
starts.push((thread_id, event));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,9 +457,10 @@ async fn interrupt_during_completion_preserves_running_status(
|
||||
.collect::<std::result::Result<Vec<_>, _>>()?
|
||||
.into_iter()
|
||||
.filter_map(|line| match line.item {
|
||||
RolloutItem::EventMsg(
|
||||
event @ (EventMsg::TurnComplete(_) | EventMsg::TurnAborted(_)),
|
||||
) => Some(event),
|
||||
RolloutItem::EventMsg {
|
||||
event: event @ (EventMsg::TurnComplete(_) | EventMsg::TurnAborted(_)),
|
||||
..
|
||||
} => Some(event),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@@ -4895,9 +4895,10 @@ async fn auto_compact_persists_rollout_entries() {
|
||||
turn_context_count += 1;
|
||||
}
|
||||
RolloutItem::Compacted(_) => saw_compaction = true,
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(applied))
|
||||
if saw_compaction && checkpoint.is_none() =>
|
||||
{
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(applied),
|
||||
..
|
||||
} if saw_compaction && checkpoint.is_none() => {
|
||||
checkpoint = Some((applied.thread_id, applied.thread_settings));
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -339,11 +339,10 @@ async fn terminated_cell_persists_failure_and_excludes_late_reply_from_context()
|
||||
.collect::<Result<Vec<_>, _>>()?
|
||||
.into_iter()
|
||||
.filter_map(|line| match line.item {
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event))
|
||||
if event.item.id() == original =>
|
||||
{
|
||||
Some(event)
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} if event.item.id() == original => Some(event),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -205,7 +205,10 @@ async fn generated_image_ui_item_is_file_backed_in_rollout() -> Result<()> {
|
||||
.collect::<Vec<_>>();
|
||||
let image =
|
||||
rollout.iter().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event)) => match &event.item {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} => match &event.item {
|
||||
codex_protocol::items::TurnItem::Extension(ExtensionItem::ImageGeneration(
|
||||
image,
|
||||
)) if image.id == image_call_id => Some(image),
|
||||
|
||||
@@ -234,7 +234,13 @@ async fn guardian_saves_each_completed_review_before_releasing_its_action() -> a
|
||||
.history
|
||||
.items
|
||||
.iter()
|
||||
.filter(|item| matches!(item, RolloutItem::EventMsg(EventMsg::TurnComplete(_))))
|
||||
.filter(|item| matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnComplete(_),
|
||||
..
|
||||
}
|
||||
))
|
||||
.count(),
|
||||
review,
|
||||
"the first save after inference must include turn completion"
|
||||
|
||||
@@ -1346,7 +1346,10 @@ async fn guardian_session_prewarms_and_is_reused_for_first_review(
|
||||
let guardian_context_windows = guardian_rollout
|
||||
.into_iter()
|
||||
.filter_map(|line| match line.item {
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event)) => Some(event.model_context_window),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} => Some(event.model_context_window),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@@ -212,7 +212,6 @@ async fn guardian_circuit_breaker_notifies_parent(action: CircuitBreakAction) ->
|
||||
(action == CircuitBreakAction::Strict).then_some(ErrorEvent {
|
||||
message: warning.clone(),
|
||||
codex_error_info: Some(CodexErrorInfo::TooManyDenials),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
misalignment: None,
|
||||
}),
|
||||
AgentStatus::Interrupted,
|
||||
|
||||
@@ -598,8 +598,10 @@ async fn uploaded_images_preserve_user_message_display_history() -> anyhow::Resu
|
||||
let rollout_text = read_rollout_text(&rollout_path).await?;
|
||||
let mut persisted_user_items = Vec::new();
|
||||
for line in rollout_text.lines() {
|
||||
if let RolloutItem::EventMsg(EventMsg::ItemCompleted(event)) =
|
||||
codex_rollout::parse_rollout_line(line)?.item
|
||||
if let RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} = codex_rollout::parse_rollout_line(line)?.item
|
||||
&& let TurnItem::UserMessage(item) = event.item
|
||||
{
|
||||
persisted_user_items.push(item);
|
||||
|
||||
@@ -383,9 +383,10 @@ async fn web_search_item_is_emitted() -> anyhow::Result<()> {
|
||||
.collect::<Result<Vec<_>, _>>()?
|
||||
.into_iter()
|
||||
.find_map(|line| match line.item {
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event))
|
||||
if matches!(&event.item, TurnItem::WebSearch(item) if item.id == begin.call_id) =>
|
||||
{
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} if matches!(&event.item, TurnItem::WebSearch(item) if item.id == begin.call_id) => {
|
||||
Some(event)
|
||||
}
|
||||
_ => None,
|
||||
@@ -687,11 +688,10 @@ async fn plan_mode_keeps_only_unfinished_ids_across_model_requests(
|
||||
.collect::<Result<Vec<_>, _>>()?
|
||||
.into_iter()
|
||||
.filter_map(|line| match line.item {
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event))
|
||||
if matches!(event.item, TurnItem::Plan(_)) =>
|
||||
{
|
||||
Some(event)
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} if matches!(event.item, TurnItem::Plan(_)) => Some(event),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@@ -227,7 +227,10 @@ async fn owner_cancellation_closes_agent_and_preserves_history_and_parent() -> a
|
||||
.await?;
|
||||
assert!(history.items.iter().any(|item| matches!(
|
||||
item,
|
||||
codex_history::RolloutItem::EventMsg(EventMsg::TurnComplete(_))
|
||||
codex_history::RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnComplete(_),
|
||||
..
|
||||
}
|
||||
)));
|
||||
|
||||
let parent_response = responses::mount_sse_once(
|
||||
|
||||
@@ -212,9 +212,10 @@ async fn mcp_app_ui_survives_tool_events_and_resume(
|
||||
.items
|
||||
.into_iter()
|
||||
.filter_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::McpToolCallEnd(end)) if end.call_id == call_id => {
|
||||
Some(EventMsg::McpToolCallEnd(end))
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::McpToolCallEnd(end),
|
||||
..
|
||||
} if end.call_id == call_id => Some(EventMsg::McpToolCallEnd(end)),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@@ -1761,9 +1762,10 @@ async fn apps_default_approval_prompts_for_writes_but_not_reads(
|
||||
.collect::<serde_json::Result<Vec<_>>>()?
|
||||
.into_iter()
|
||||
.filter_map(|line| match line.item {
|
||||
RolloutItem::EventMsg(EventMsg::McpToolCallEnd(event))
|
||||
if event.call_id == read_call_id || event.call_id == write_call_id =>
|
||||
{
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::McpToolCallEnd(event),
|
||||
..
|
||||
} if event.call_id == read_call_id || event.call_id == write_call_id => {
|
||||
Some((event.call_id, event.read_only_hint))
|
||||
}
|
||||
_ => None,
|
||||
|
||||
@@ -1917,7 +1917,7 @@ async fn unattributed_network_request_uses_active_turn_environment_fallback(
|
||||
})
|
||||
.await?;
|
||||
if history.items.iter().any(|item| {
|
||||
matches!(item, RolloutItem::EventMsg(EventMsg::TurnComplete(event)) if event.error.is_some())
|
||||
matches!(item, RolloutItem::EventMsg { event: EventMsg::TurnComplete(event), .. } if event.error.is_some())
|
||||
}) {
|
||||
return Ok::<(), anyhow::Error>(());
|
||||
}
|
||||
|
||||
@@ -1233,7 +1233,10 @@ async fn any_new_input_interrupts_sleep(input: WaitInput) {
|
||||
.lines()
|
||||
.filter_map(|line| codex_rollout::parse_rollout_line(line).ok())
|
||||
.filter_map(|line| match line.item {
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event)) => match event.item {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} => match event.item {
|
||||
TurnItem::Extension(ExtensionItem::Sleep(item)) => Some(item),
|
||||
_ => None,
|
||||
},
|
||||
|
||||
@@ -644,9 +644,9 @@ async fn hangup_timeout_aborts_a_turn_with_an_allowing_steer_hook() -> Result<()
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(history.items.iter().filter(|item| matches!(item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(aborted)) if aborted.turn_id.as_deref() == Some(turn_id.as_str())
|
||||
RolloutItem::EventMsg { event: EventMsg::TurnAborted(aborted), .. } if aborted.turn_id.as_deref() == Some(turn_id.as_str())
|
||||
) || matches!(item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(completed)) if completed.turn_id == turn_id
|
||||
RolloutItem::EventMsg { event: EventMsg::TurnComplete(completed), .. } if completed.turn_id == turn_id
|
||||
)).count(), 1);
|
||||
let session = store
|
||||
.load_realtime_session(test.session_configured.thread_id, "hook-timeout".to_owned())
|
||||
|
||||
@@ -2177,7 +2177,7 @@ async fn interrupt_during_mcp_startup_preserves_user_input_in_history(
|
||||
.iter()
|
||||
.any(|item| matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(applied))
|
||||
RolloutItem::EventMsg { event: EventMsg::ThreadSettingsApplied(applied), .. }
|
||||
if applied.thread_id == Some(fixture.session_configured.thread_id)
|
||||
))
|
||||
);
|
||||
|
||||
@@ -681,10 +681,6 @@ async fn rejected_uploaded_audio_does_not_poison_follow_up_or_resume(
|
||||
.message
|
||||
.contains("remove or replace the affected audio attachment")
|
||||
);
|
||||
assert_eq!(
|
||||
error.rejected_audio_file_ids,
|
||||
vec!["file_rejected".to_string()],
|
||||
);
|
||||
let mock = mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
@@ -896,7 +892,6 @@ async fn ambiguous_multi_audio_rejection_preserves_all_audio_on_follow_up_and_re
|
||||
.message
|
||||
.contains("remove or replace the affected audio attachment")
|
||||
);
|
||||
assert!(error.rejected_audio_file_ids.is_empty());
|
||||
test.submit_text_turn("Retry with the retained recordings.")
|
||||
.await?;
|
||||
let resumed = builder().restart_with_auto_env(&server, &test).await?;
|
||||
@@ -978,10 +973,10 @@ async fn unknown_file_after_two_recordings_were_accepted(
|
||||
"Recall the recordings.",
|
||||
)]))
|
||||
.await?;
|
||||
let error = wait_for_event_match(&test.codex, |event| match event {
|
||||
EventMsg::TurnComplete(done) => done.error.clone(),
|
||||
_ => None,
|
||||
})
|
||||
wait_for_event(
|
||||
&test.codex,
|
||||
|event| matches!(event, EventMsg::TurnComplete(done) if done.error.is_some()),
|
||||
)
|
||||
.await;
|
||||
{
|
||||
let resolves = store
|
||||
@@ -991,14 +986,6 @@ async fn unknown_file_after_two_recordings_were_accepted(
|
||||
assert_eq!(resolves.get("file_a"), Some(&2));
|
||||
assert_eq!(resolves.get("file_b"), Some(&2));
|
||||
}
|
||||
assert_eq!(
|
||||
error.rejected_audio_file_ids,
|
||||
if confirmed {
|
||||
vec!["file_b"]
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
);
|
||||
test.codex
|
||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![text(
|
||||
"Continue in this chat.",
|
||||
@@ -1103,12 +1090,11 @@ async fn persistently_invalid_recording_is_removed_on_follow_up_and_resume(
|
||||
recording("file_bad_b"),
|
||||
]))
|
||||
.await?;
|
||||
let error = wait_for_event_match(&test.codex, |event| match event {
|
||||
EventMsg::TurnComplete(done) => done.error.clone(),
|
||||
_ => None,
|
||||
})
|
||||
wait_for_event(
|
||||
&test.codex,
|
||||
|event| matches!(event, EventMsg::TurnComplete(done) if done.error.is_some()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(error.rejected_audio_file_ids, ["file_bad_b"]);
|
||||
test.submit_text_turn("Continue without the rejected upload.")
|
||||
.await?;
|
||||
let resumed = builder().restart_with_auto_env(&server, &test).await?;
|
||||
@@ -1180,12 +1166,11 @@ async fn paginated_resume_filters_audio_rejected_before_and_after_compaction() -
|
||||
recording(id),
|
||||
]))
|
||||
.await?;
|
||||
let error = wait_for_event_match(&test.codex, |event| match event {
|
||||
EventMsg::TurnComplete(completed) => completed.error.clone(),
|
||||
_ => None,
|
||||
})
|
||||
wait_for_event(
|
||||
&test.codex,
|
||||
|event| matches!(event, EventMsg::TurnComplete(completed) if completed.error.is_some()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(error.rejected_audio_file_ids, [id]);
|
||||
if id == "file_A" {
|
||||
test.codex.submit(Op::Compact).await?;
|
||||
wait_for_event(&test.codex, |event| {
|
||||
@@ -1311,18 +1296,11 @@ async fn instant_interrupt_preserves_delayed_http_audio_rejection() -> Result<()
|
||||
)
|
||||
.await?;
|
||||
release.send(())?;
|
||||
let completed = wait_for_event_match(&test.codex, |event| match event {
|
||||
EventMsg::TurnComplete(completed) => Some(completed.clone()),
|
||||
_ => None,
|
||||
})
|
||||
wait_for_event(
|
||||
&test.codex,
|
||||
|event| matches!(event, EventMsg::TurnComplete(completed) if completed.error.is_some()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
completed
|
||||
.error
|
||||
.expect("terminal rejection of A")
|
||||
.rejected_audio_file_ids,
|
||||
["file_A"]
|
||||
);
|
||||
mount_sse_sequence(
|
||||
&server,
|
||||
vec![
|
||||
@@ -1448,18 +1426,11 @@ async fn provider_rejection_preserves_a_different_queued_audio_file() -> Result<
|
||||
)
|
||||
.await?;
|
||||
release.send(()).expect("release rejection");
|
||||
let completed = wait_for_event_match(&test.codex, |event| match event {
|
||||
EventMsg::TurnComplete(completed) => Some(completed.clone()),
|
||||
_ => None,
|
||||
})
|
||||
wait_for_event(
|
||||
&test.codex,
|
||||
|event| matches!(event, EventMsg::TurnComplete(completed) if completed.error.is_some()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
completed
|
||||
.error
|
||||
.as_ref()
|
||||
.map(|error| error.rejected_audio_file_ids.clone()),
|
||||
Some(vec!["file_a_rejected".to_string()])
|
||||
);
|
||||
|
||||
test.submit_text_turn("Continue with queued recording B.")
|
||||
.await?;
|
||||
|
||||
@@ -48,9 +48,10 @@ fn assert_checkpoints(test: &TestCodex, expected: &[ThreadSettingsSnapshot]) ->
|
||||
let snapshots: Vec<_> = rollout
|
||||
.into_iter()
|
||||
.filter_map(|line| match line.item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(applied))
|
||||
if applied.thread_id == Some(test.session_configured.thread_id) =>
|
||||
{
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(applied),
|
||||
..
|
||||
} if applied.thread_id == Some(test.session_configured.thread_id) => {
|
||||
Some(applied.thread_settings)
|
||||
}
|
||||
_ => None,
|
||||
@@ -302,7 +303,10 @@ async fn settings_notifications_keep_their_commit_across_postcommit_work(
|
||||
RolloutItem::TurnContext(context) => {
|
||||
Some((context.model.as_str(), context.approval_policy))
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(applied)) => Some((
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(applied),
|
||||
..
|
||||
} => Some((
|
||||
applied.thread_settings.model.as_str(),
|
||||
applied.thread_settings.approval_policy,
|
||||
)),
|
||||
@@ -385,9 +389,10 @@ async fn compaction_checkpoints_settings_changed_during_its_model_request() -> R
|
||||
.iter()
|
||||
.skip_while(|line| !matches!(line.item, RolloutItem::Compacted(_)))
|
||||
.find_map(|line| match &line.item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(applied)) => {
|
||||
Some((applied.thread_id, &applied.thread_settings))
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(applied),
|
||||
..
|
||||
} => Some((applied.thread_id, &applied.thread_settings)),
|
||||
_ => None,
|
||||
});
|
||||
assert_eq!(
|
||||
|
||||
@@ -98,7 +98,7 @@ async fn compaction_preserves_updated_summary(mode: CompactionMode) -> Result<()
|
||||
.iter()
|
||||
.skip_while(|line| !matches!(line.item, RolloutItem::Compacted(_)))
|
||||
.skip(/*n*/ 1)
|
||||
.take_while(|line| !matches!(line.item, RolloutItem::EventMsg(_)))
|
||||
.take_while(|line| !matches!(line.item, RolloutItem::EventMsg { .. }))
|
||||
.find_map(|line| match &line.item {
|
||||
RolloutItem::TurnContext(context) => Some(context.summary),
|
||||
_ => None,
|
||||
|
||||
@@ -2451,15 +2451,19 @@ async fn multi_agent_v2_spawn_sends_agent_message_to_child(
|
||||
.get_rollout_items()
|
||||
.iter()
|
||||
.find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(completed)) => match &completed.item {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(completed),
|
||||
..
|
||||
} => match &completed.item {
|
||||
TurnItem::SubAgentActivity(activity) if activity.id == SPAWN_CALL_ID => {
|
||||
Some((activity.model.clone(), activity.reasoning_effort.clone()))
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
RolloutItem::EventMsg(EventMsg::SubAgentActivity(activity))
|
||||
if activity.event_id == SPAWN_CALL_ID =>
|
||||
{
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::SubAgentActivity(activity),
|
||||
..
|
||||
} if activity.event_id == SPAWN_CALL_ID => {
|
||||
Some((activity.model.clone(), activity.reasoning_effort.clone()))
|
||||
}
|
||||
_ => None,
|
||||
@@ -2938,7 +2942,7 @@ async fn plaintext_multi_agent_v2_completion_sends_agent_message(
|
||||
assert!(
|
||||
!rollout.get_rollout_items().iter().any(|item| matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::SubAgentActivity(activity))
|
||||
RolloutItem::EventMsg { event: EventMsg::SubAgentActivity(activity), .. }
|
||||
if activity.kind == SubAgentActivityKind::Completed
|
||||
)),
|
||||
"legacy completed activity should not be persisted without its parent turn ID"
|
||||
@@ -2947,14 +2951,16 @@ async fn plaintext_multi_agent_v2_completion_sends_agent_message(
|
||||
.get_rollout_items()
|
||||
.iter()
|
||||
.find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(completed))
|
||||
if matches!(
|
||||
&completed.item,
|
||||
TurnItem::SubAgentActivity(SubAgentActivityItem {
|
||||
kind: SubAgentActivityKind::Completed,
|
||||
..
|
||||
})
|
||||
) =>
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(completed),
|
||||
..
|
||||
} if matches!(
|
||||
&completed.item,
|
||||
TurnItem::SubAgentActivity(SubAgentActivityItem {
|
||||
kind: SubAgentActivityKind::Completed,
|
||||
..
|
||||
})
|
||||
) =>
|
||||
{
|
||||
Some(completed)
|
||||
}
|
||||
|
||||
@@ -176,11 +176,10 @@ async fn strict_tool_collisions_fail_the_turn_before_sampling(
|
||||
})
|
||||
.await?;
|
||||
let attribution = history.items.iter().find_map(|item| match item {
|
||||
codex_history::RolloutItem::EventMsg(EventMsg::TurnStarted(event))
|
||||
if event.turn_id == completed.turn_id =>
|
||||
{
|
||||
event.root_turn_id.as_deref()
|
||||
}
|
||||
codex_history::RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} if event.turn_id == completed.turn_id => event.root_turn_id.as_deref(),
|
||||
_ => None,
|
||||
});
|
||||
assert_eq!(attribution, Some("root-turn"));
|
||||
|
||||
@@ -184,9 +184,10 @@ async fn interrupted_one_shot_launch_failure_completes_and_persists() -> Result<
|
||||
let persisted_completions = items
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event)) if event.item.id() == CALL_ID => {
|
||||
Some(event)
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} if event.item.id() == CALL_ID => Some(event),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@@ -257,7 +257,6 @@ impl<H: ReviewHost> SynchronousApprovalReviewer for ReviewRequest<'_, H> {
|
||||
ErrorEvent {
|
||||
message,
|
||||
codex_error_info: Some(CodexErrorInfo::TooManyDenials),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
misalignment: None,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -377,7 +377,11 @@ fn review_original(
|
||||
}
|
||||
message.complete
|
||||
}
|
||||
RolloutItem::SessionMeta(_) | RolloutItem::EventMsg(EventMsg::ThreadRolledBack(_)) => {
|
||||
RolloutItem::SessionMeta(_)
|
||||
| RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadRolledBack(_),
|
||||
..
|
||||
} => {
|
||||
anyhow::bail!("evidence history was replaced");
|
||||
}
|
||||
RolloutItem::RetainedContext(RetainedContextEvent::AcceptedFileAudio { .. })
|
||||
@@ -389,7 +393,7 @@ fn review_original(
|
||||
| RolloutItem::TokenUsageRecord(_)
|
||||
| RolloutItem::WorldState(_)
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::EventMsg(_)
|
||||
| RolloutItem::EventMsg { .. }
|
||||
| RolloutItem::RealtimeItem(_) => false,
|
||||
};
|
||||
if !include {
|
||||
|
||||
@@ -228,20 +228,28 @@ fn source_model_items(items: &[RolloutItem]) -> Option<Vec<SourceModelItem<'_>>>
|
||||
append_start_index: append_start_index.take().unwrap_or(index),
|
||||
});
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(_)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(_),
|
||||
..
|
||||
} => {
|
||||
append_start_index = Some(index);
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(_)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(_),
|
||||
..
|
||||
} => {
|
||||
append_start_index.get_or_insert(index);
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::AgentMessage(event))
|
||||
if event.message != EXTERNAL_SESSION_IMPORTED_MARKER =>
|
||||
{
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::AgentMessage(event),
|
||||
..
|
||||
} if event.message != EXTERNAL_SESSION_IMPORTED_MARKER => {
|
||||
append_start_index = Some(index);
|
||||
}
|
||||
RolloutItem::EventMsg(
|
||||
EventMsg::ContextCompacted(_) | EventMsg::ThreadRolledBack(_),
|
||||
)
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ContextCompacted(_) | EventMsg::ThreadRolledBack(_),
|
||||
..
|
||||
}
|
||||
| RolloutItem::InterAgentCommunication(_)
|
||||
| RolloutItem::Compacted(_)
|
||||
| RolloutItem::TurnContext(_)
|
||||
@@ -249,7 +257,7 @@ fn source_model_items(items: &[RolloutItem]) -> Option<Vec<SourceModelItem<'_>>>
|
||||
| RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::WorldState(_) => return None,
|
||||
RolloutItem::EventMsg(_) => {}
|
||||
RolloutItem::EventMsg { .. } => {}
|
||||
}
|
||||
}
|
||||
Some(model_items)
|
||||
@@ -267,14 +275,15 @@ fn history_model_items(items: &[RolloutItem]) -> Option<Vec<&ResponseItem>> {
|
||||
| RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SecurityRiskScore(_) => {}
|
||||
RolloutItem::ResponseItem(response_item) => model_items.push(&response_item.item),
|
||||
RolloutItem::EventMsg(
|
||||
EventMsg::ContextCompacted(_) | EventMsg::ThreadRolledBack(_),
|
||||
)
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ContextCompacted(_) | EventMsg::ThreadRolledBack(_),
|
||||
..
|
||||
}
|
||||
| RolloutItem::InterAgentCommunication(_)
|
||||
| RolloutItem::Compacted(_)
|
||||
| RolloutItem::TurnContext(_)
|
||||
| RolloutItem::WorldState(_) => return None,
|
||||
RolloutItem::EventMsg(_) => {}
|
||||
RolloutItem::EventMsg { .. } => {}
|
||||
}
|
||||
}
|
||||
Some(model_items)
|
||||
@@ -283,7 +292,7 @@ fn history_model_items(items: &[RolloutItem]) -> Option<Vec<&ResponseItem>> {
|
||||
fn is_import_marker(item: &RolloutItem) -> bool {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::AgentMessage(event))
|
||||
RolloutItem::EventMsg { event: EventMsg::AgentMessage(event), .. }
|
||||
if event.message == EXTERNAL_SESSION_IMPORTED_MARKER
|
||||
)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ fn returns_the_missing_suffix_from_its_visible_boundary() {
|
||||
|
||||
assert!(matches!(
|
||||
suffix.first(),
|
||||
Some(RolloutItem::EventMsg(EventMsg::AgentMessage(event)))
|
||||
Some(RolloutItem::EventMsg { event: EventMsg::AgentMessage(event), .. })
|
||||
if event.message == "late answer"
|
||||
));
|
||||
assert_eq!(
|
||||
@@ -36,7 +36,7 @@ fn returns_the_missing_suffix_from_its_visible_boundary() {
|
||||
);
|
||||
assert!(!suffix.iter().any(|item| matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::AgentMessage(event))
|
||||
RolloutItem::EventMsg { event: EventMsg::AgentMessage(event), .. }
|
||||
if event.message == EXTERNAL_SESSION_IMPORTED_MARKER
|
||||
)));
|
||||
}
|
||||
@@ -59,7 +59,11 @@ fn requires_a_strict_nonempty_model_prefix() {
|
||||
|
||||
let mut metadata_changed = history.clone();
|
||||
for item in &mut metadata_changed {
|
||||
if let RolloutItem::EventMsg(EventMsg::TurnStarted(event)) = item {
|
||||
if let RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} = item
|
||||
{
|
||||
event.turn_id = "different-turn-id".to_string();
|
||||
event.started_at = Some(9_999);
|
||||
}
|
||||
|
||||
@@ -312,7 +312,10 @@ mod tests {
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)) => Some(event),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnComplete(event),
|
||||
..
|
||||
} => Some(event),
|
||||
_ => None,
|
||||
});
|
||||
assert_eq!(
|
||||
@@ -356,8 +359,14 @@ mod tests {
|
||||
.rollout_items
|
||||
.iter()
|
||||
.filter(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(event)) => event.message == request,
|
||||
RolloutItem::EventMsg(EventMsg::AgentMessage(event)) => event.message == answer,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(event),
|
||||
..
|
||||
} => event.message == request,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::AgentMessage(event),
|
||||
..
|
||||
} => event.message == answer,
|
||||
_ => false,
|
||||
})
|
||||
.count();
|
||||
@@ -446,7 +455,10 @@ mod tests {
|
||||
.expect("load")
|
||||
.expect("session");
|
||||
let imported_user_message = imported.rollout_items.iter().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(event)) => Some(event.message.as_str()),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(event),
|
||||
..
|
||||
} => Some(event.message.as_str()),
|
||||
_ => None,
|
||||
});
|
||||
|
||||
@@ -541,7 +553,10 @@ mod tests {
|
||||
.rollout_items
|
||||
.iter()
|
||||
.find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::TokenCount(event)) => event.info.clone(),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TokenCount(event),
|
||||
..
|
||||
} => event.info.clone(),
|
||||
_ => None,
|
||||
})
|
||||
.expect("token count event");
|
||||
|
||||
@@ -76,6 +76,6 @@ pub fn resume_multi_agent_version(item: &RolloutItem) -> Option<MultiAgentVersio
|
||||
| RolloutItem::RetainedContext(_)
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::RealtimeItem(_)
|
||||
| RolloutItem::EventMsg(_) => None,
|
||||
| RolloutItem::EventMsg { .. } => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,12 +439,36 @@ pub enum RolloutItem {
|
||||
WorldState(WorldStateItem),
|
||||
SecurityRiskScore(SecurityRiskScore),
|
||||
RetainedContext(RetainedContextEvent),
|
||||
EventMsg(EventMsg),
|
||||
/// A protocol event and optional metadata owned by rollout storage.
|
||||
EventMsg {
|
||||
event: EventMsg,
|
||||
metadata: Option<RolloutEventMetadata>,
|
||||
},
|
||||
/// Sparse, model-invisible facts used to reconstruct realtime presentation.
|
||||
RealtimeItem(RealtimeItem),
|
||||
}
|
||||
|
||||
impl RolloutItem {
|
||||
/// Constructs a rollout event without host metadata.
|
||||
#[allow(
|
||||
non_snake_case,
|
||||
reason = "preserve the existing event constructor syntax"
|
||||
)]
|
||||
pub fn EventMsg(event: EventMsg) -> Self {
|
||||
Self::EventMsg {
|
||||
event,
|
||||
metadata: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the protocol event carried by this rollout item.
|
||||
pub fn event_msg(&self) -> Option<&EventMsg> {
|
||||
match self {
|
||||
Self::EventMsg { event, .. } => Some(event),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the handoff ID only when the rollout item is a valid acceptance receipt.
|
||||
pub fn realtime_handoff_id(&self) -> Option<&str> {
|
||||
match self {
|
||||
@@ -494,6 +518,13 @@ impl RolloutItem {
|
||||
}
|
||||
}
|
||||
|
||||
/// Host-only data saved with a rollout event to support recovery.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RolloutEventMetadata {
|
||||
/// Exact audio file identities rejected by the provider for the failed turn.
|
||||
pub rejected_audio_file_ids: Vec<String>,
|
||||
}
|
||||
|
||||
impl Serialize for RolloutItem {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -787,11 +818,10 @@ impl InitialHistory {
|
||||
return None;
|
||||
};
|
||||
resumed.history.iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
if event.thread_id == Some(resumed.conversation_id) =>
|
||||
{
|
||||
Some(&event.thread_settings)
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} if event.thread_id == Some(resumed.conversation_id) => Some(&event.thread_settings),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
@@ -847,7 +877,10 @@ pub fn latest_dynamic_tools(items: &[RolloutItem]) -> Option<&[DynamicToolSpec]>
|
||||
/// selection; a missing field must not resurrect a selection from an older turn.
|
||||
pub fn latest_disabled_plugin_ids(items: &[RolloutItem], thread_id: ThreadId) -> Option<&[String]> {
|
||||
if let Some(ids) = items.iter().rev().find_map(|item| {
|
||||
if let RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) = item
|
||||
if let RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} = item
|
||||
&& event.thread_id == Some(thread_id)
|
||||
{
|
||||
Some(event.thread_settings.disabled_plugin_ids.as_slice())
|
||||
|
||||
@@ -59,7 +59,7 @@ pub fn next_model_id_ordinals(records: &[RolloutItem]) -> (u64, u64) {
|
||||
| RolloutItem::WorldState(_)
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::RetainedContext(_)
|
||||
| RolloutItem::EventMsg(_)
|
||||
| RolloutItem::EventMsg { .. }
|
||||
| RolloutItem::RealtimeItem(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,16 +202,15 @@ impl MessageRetention {
|
||||
/// Recover the latest owned settings even when replay begins at a compaction.
|
||||
pub fn saved(items: &[RolloutItem], thread_id: ThreadId) -> Option<Self> {
|
||||
items.iter().rev().find_map(|item| match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
if event.thread_id == Some(thread_id) =>
|
||||
{
|
||||
Some(
|
||||
event
|
||||
.thread_settings
|
||||
.guardian_retention
|
||||
.map(|policy| Self { thread_id, policy }),
|
||||
)
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} if event.thread_id == Some(thread_id) => Some(
|
||||
event
|
||||
.thread_settings
|
||||
.guardian_retention
|
||||
.map(|policy| Self { thread_id, policy }),
|
||||
),
|
||||
RolloutItem::Compacted(item) => item
|
||||
.retained_context
|
||||
.as_ref()?
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
|
||||
use super::CodexHarnessMetadata;
|
||||
use super::CompactedItem;
|
||||
@@ -8,6 +9,7 @@ use super::McpResourceOriginCheckpoint;
|
||||
use super::RealtimeItem;
|
||||
use super::ResponseItem;
|
||||
use super::ResponseItemEnvelope;
|
||||
use super::RolloutEventMetadata;
|
||||
use super::RolloutItem;
|
||||
use super::SecurityRiskScore;
|
||||
use super::SessionMetaLine;
|
||||
@@ -27,7 +29,17 @@ use codex_protocol::protocol::SandboxPolicy;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Deserializer;
|
||||
use serde::Serialize;
|
||||
use serde::Serializer;
|
||||
use serde::de::DeserializeSeed;
|
||||
use serde::de::Error as _;
|
||||
use serde::de::MapAccess;
|
||||
use serde::de::Visitor;
|
||||
use serde::de::value::MapAccessDeserializer;
|
||||
use serde::de::value::StringDeserializer;
|
||||
use serde::ser::Error as _;
|
||||
use serde_json::Value;
|
||||
|
||||
const CODE_MODE_DELIVERY_COMPLETE: &str = "codex:code-mode-delivery:v1:complete";
|
||||
const CODE_MODE_DELIVERY_INCOMPLETE: &str = "codex:code-mode-delivery:v1:incomplete:";
|
||||
@@ -74,13 +86,118 @@ pub(super) enum RolloutItemWire<'a> {
|
||||
payload: Cow<'a, SecurityRiskScore>,
|
||||
},
|
||||
EventMsg {
|
||||
payload: Cow<'a, EventMsg>,
|
||||
#[schemars(with = "EventMsg")]
|
||||
payload: RolloutEventPayload<'a>,
|
||||
},
|
||||
RealtimeItem {
|
||||
payload: Cow<'a, RealtimeItem>,
|
||||
},
|
||||
}
|
||||
|
||||
/// Encodes protocol events and legacy audio rejection metadata in the rollout format.
|
||||
pub(super) struct RolloutEventPayload<'a> {
|
||||
event: Cow<'a, EventMsg>,
|
||||
rejected_audio_file_ids: Cow<'a, [String]>,
|
||||
}
|
||||
|
||||
impl Serialize for RolloutEventPayload<'_> {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
if self.rejected_audio_file_ids.is_empty() {
|
||||
return self.event.serialize(serializer);
|
||||
}
|
||||
if !matches!(self.event.as_ref(), EventMsg::TurnComplete(event) if event.error.is_some()) {
|
||||
return Err(S::Error::custom("audio rejection requires a failed turn"));
|
||||
}
|
||||
// Keep the original rollout format readable during downgrade.
|
||||
let mut payload = serde_json::to_value(&self.event).map_err(S::Error::custom)?;
|
||||
let error = payload["error"]
|
||||
.as_object_mut()
|
||||
.ok_or_else(|| S::Error::custom("audio rejection requires a failed turn"))?;
|
||||
error.insert(
|
||||
"rejected_audio_file_ids".to_owned(),
|
||||
serde_json::to_value(&self.rejected_audio_file_ids).map_err(S::Error::custom)?,
|
||||
);
|
||||
payload.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for RolloutEventPayload<'_> {
|
||||
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||
deserializer.deserialize_map(RolloutEventVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct RolloutEventVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for RolloutEventVisitor {
|
||||
type Value = RolloutEventPayload<'static>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter.write_str("a rollout event payload")
|
||||
}
|
||||
|
||||
fn visit_map<A: MapAccess<'de>>(self, map: A) -> Result<Self::Value, A::Error> {
|
||||
let mut map = RolloutEventMap {
|
||||
map,
|
||||
error_field: false,
|
||||
rejected_audio_file_ids: None,
|
||||
};
|
||||
let event = EventMsg::deserialize(MapAccessDeserializer::new(&mut map))?;
|
||||
let rejected_audio_file_ids = if matches!(&event, EventMsg::TurnComplete(_)) {
|
||||
map.rejected_audio_file_ids
|
||||
.map(serde_json::from_value)
|
||||
.transpose()
|
||||
.map_err(A::Error::custom)?
|
||||
.unwrap_or_default()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
Ok(RolloutEventPayload {
|
||||
event: Cow::Owned(event),
|
||||
rejected_audio_file_ids: Cow::Owned(rejected_audio_file_ids),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Forward the original event fields to Serde and inspect only the legacy error.
|
||||
struct RolloutEventMap<A> {
|
||||
map: A,
|
||||
error_field: bool,
|
||||
rejected_audio_file_ids: Option<Value>,
|
||||
}
|
||||
|
||||
impl<'de, A: MapAccess<'de>> MapAccess<'de> for RolloutEventMap<A> {
|
||||
type Error = A::Error;
|
||||
|
||||
fn next_key_seed<K: DeserializeSeed<'de>>(
|
||||
&mut self,
|
||||
seed: K,
|
||||
) -> Result<Option<K::Value>, Self::Error> {
|
||||
let Some(key) = self.map.next_key::<String>()? else {
|
||||
return Ok(None);
|
||||
};
|
||||
self.error_field = key == "error";
|
||||
seed.deserialize(StringDeserializer::new(key)).map(Some)
|
||||
}
|
||||
|
||||
fn next_value_seed<V: DeserializeSeed<'de>>(
|
||||
&mut self,
|
||||
seed: V,
|
||||
) -> Result<V::Value, Self::Error> {
|
||||
if self.error_field {
|
||||
let error: Value = self.map.next_value()?;
|
||||
self.rejected_audio_file_ids = error.get("rejected_audio_file_ids").cloned();
|
||||
seed.deserialize(error).map_err(Self::Error::custom)
|
||||
} else {
|
||||
self.map.next_value_seed(seed)
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> Option<usize> {
|
||||
self.map.size_hint()
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_turn_context<S>(context: &TurnContextItem, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
@@ -270,8 +387,15 @@ impl<'a> From<&'a RolloutItem> for RolloutItemWire<'a> {
|
||||
RolloutItem::SecurityRiskScore(payload) => Self::SecurityRiskScore {
|
||||
payload: Cow::Borrowed(payload),
|
||||
},
|
||||
RolloutItem::EventMsg(payload) => Self::EventMsg {
|
||||
payload: Cow::Borrowed(payload),
|
||||
RolloutItem::EventMsg { event, metadata } => Self::EventMsg {
|
||||
payload: RolloutEventPayload {
|
||||
event: Cow::Borrowed(event),
|
||||
rejected_audio_file_ids: Cow::Borrowed(
|
||||
metadata
|
||||
.as_ref()
|
||||
.map_or(&[], |metadata| metadata.rejected_audio_file_ids.as_slice()),
|
||||
),
|
||||
},
|
||||
},
|
||||
RolloutItem::RealtimeItem(payload) => Self::RealtimeItem {
|
||||
payload: Cow::Borrowed(payload),
|
||||
@@ -360,7 +484,14 @@ impl From<RolloutItemWire<'_>> for RolloutItem {
|
||||
RolloutItemWire::SecurityRiskScore { payload } => {
|
||||
Self::SecurityRiskScore(payload.into_owned())
|
||||
}
|
||||
RolloutItemWire::EventMsg { payload } => Self::EventMsg(payload.into_owned()),
|
||||
RolloutItemWire::EventMsg { payload } => Self::EventMsg {
|
||||
event: payload.event.into_owned(),
|
||||
metadata: (!payload.rejected_audio_file_ids.is_empty()).then(|| {
|
||||
RolloutEventMetadata {
|
||||
rejected_audio_file_ids: payload.rejected_audio_file_ids.into_owned(),
|
||||
}
|
||||
}),
|
||||
},
|
||||
RolloutItemWire::RealtimeItem { payload } => Self::RealtimeItem(payload.into_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,40 @@ use serde_json::json;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn legacy_audio_rejection_survives_rollout_rewriting_without_exposing_ids_in_events() -> Result<()>
|
||||
{
|
||||
let wire = json!({
|
||||
"type": "event_msg",
|
||||
"payload": {
|
||||
"type": "task_complete",
|
||||
"turn_id": "turn-1",
|
||||
"last_agent_message": null,
|
||||
"error": {
|
||||
"message": "Invalid recording",
|
||||
"codex_error_info": "bad_request",
|
||||
"rejected_audio_file_ids": ["file_audio"]
|
||||
}
|
||||
}
|
||||
});
|
||||
let item: RolloutItem = serde_json::from_value(wire.clone())?;
|
||||
assert!(matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg {
|
||||
metadata: Some(_),
|
||||
..
|
||||
}
|
||||
));
|
||||
assert_eq!(serde_json::to_value(&item)?, wire);
|
||||
let mut expected_event = wire["payload"].clone();
|
||||
expected_event["error"]
|
||||
.as_object_mut()
|
||||
.expect("turn error object")
|
||||
.remove("rejected_audio_file_ids");
|
||||
assert_eq!(serde_json::to_value(item.event_msg())?, expected_event);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepted_realtime_input_projects_from_the_canonical_response_item() -> Result<()> {
|
||||
let mut item: ResponseItem = serde_json::from_value(json!({
|
||||
|
||||
@@ -423,7 +423,7 @@ mod job {
|
||||
| RolloutItem::WorldState(_)
|
||||
| RolloutItem::RetainedContext(_)
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::EventMsg(_) => None,
|
||||
| RolloutItem::EventMsg { .. } => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let serialized = serde_json::to_string(&filtered).map_err(|err| {
|
||||
|
||||
@@ -122,7 +122,7 @@ pub(crate) fn serialize_tiered_input(
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::TokenUsageRecord(_)
|
||||
| RolloutItem::RetainedContext(_)
|
||||
| RolloutItem::EventMsg(_) => None,
|
||||
| RolloutItem::EventMsg { .. } => None,
|
||||
};
|
||||
let Some(mut item) = item else { continue };
|
||||
if let ResponseItem::Message { content, .. } = &mut item {
|
||||
|
||||
@@ -651,7 +651,6 @@ impl CodexErr {
|
||||
ErrorEvent {
|
||||
message,
|
||||
codex_error_info: Some(self.to_codex_protocol_error()),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
misalignment: match &self.details {
|
||||
CodexErrorDetails::MisalignmentPolicyViolation { misalignment, .. } => {
|
||||
misalignment.clone()
|
||||
|
||||
@@ -2393,11 +2393,6 @@ pub struct ErrorEvent {
|
||||
pub message: String,
|
||||
#[serde(default)]
|
||||
pub codex_error_info: Option<CodexErrorInfo>,
|
||||
/// Host-only file identities proven rejected against the submitted request.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
#[schemars(skip)]
|
||||
#[ts(skip)]
|
||||
pub rejected_audio_file_ids: Vec<String>,
|
||||
/// Sensitive explanation and steering are delivered live but never enter rollout storage.
|
||||
#[serde(skip)]
|
||||
#[schemars(skip)]
|
||||
@@ -6373,7 +6368,6 @@ mod tests {
|
||||
misalignment: None,
|
||||
message: "rollback failed".into(),
|
||||
codex_error_info: Some(CodexErrorInfo::ThreadRollbackFailed),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
};
|
||||
assert!(!event.affects_turn_status());
|
||||
}
|
||||
@@ -6386,7 +6380,6 @@ mod tests {
|
||||
codex_error_info: Some(CodexErrorInfo::ActiveTurnNotSteerable {
|
||||
turn_kind: NonSteerableTurnKind::Review,
|
||||
}),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
};
|
||||
assert!(!event.affects_turn_status());
|
||||
}
|
||||
@@ -6397,7 +6390,6 @@ mod tests {
|
||||
misalignment: None,
|
||||
message: "generic".into(),
|
||||
codex_error_info: Some(CodexErrorInfo::Other),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
};
|
||||
assert!(event.affects_turn_status());
|
||||
}
|
||||
@@ -6407,7 +6399,6 @@ mod tests {
|
||||
let event = ErrorEvent {
|
||||
message: "This request violated the misalignment policy.".to_string(),
|
||||
codex_error_info: Some(CodexErrorInfo::MisalignmentPolicyViolation),
|
||||
rejected_audio_file_ids: Vec::new(),
|
||||
misalignment: Some(MisalignmentErrorDetails {
|
||||
error_type: Some("unauthorized_data_transfer".to_string()),
|
||||
detailed_explanation: Some("Sensitive customer explanation".to_string()),
|
||||
@@ -6436,22 +6427,6 @@ mod tests {
|
||||
assert!(!debug.contains("sensitive-review-target"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejected_audio_identity_round_trips_for_host_recovery() {
|
||||
let event = ErrorEvent {
|
||||
message: "invalid recording".to_string(),
|
||||
codex_error_info: Some(CodexErrorInfo::BadRequest),
|
||||
rejected_audio_file_ids: vec!["file_audio".to_string()],
|
||||
misalignment: None,
|
||||
};
|
||||
|
||||
let serialized = serde_json::to_value(&event).expect("serialize error event");
|
||||
assert_eq!(serialized["rejected_audio_file_ids"], json!(["file_audio"]));
|
||||
let restored: ErrorEvent =
|
||||
serde_json::from_value(serialized).expect("deserialize error event");
|
||||
assert_eq!(restored.rejected_audio_file_ids, vec!["file_audio"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn realtime_conversation_started_event_uses_realtime_session_id() {
|
||||
let event = RealtimeConversationStartedEvent {
|
||||
|
||||
@@ -1061,7 +1061,7 @@ fn read_head_summary(
|
||||
RolloutItem::Compacted(_) => {
|
||||
// Not included in `head`; skip.
|
||||
}
|
||||
RolloutItem::EventMsg(ev) => {
|
||||
RolloutItem::EventMsg { event: ev, .. } => {
|
||||
if let Some(preview) = event_msg_preview(&ev) {
|
||||
// Legacy rollouts persist UserMessage while paginated rollouts persist
|
||||
// ItemCompleted(UserMessage), so summaries must recognize both formats.
|
||||
@@ -1133,7 +1133,7 @@ pub async fn read_head_for_summary(path: &Path) -> io::Result<Vec<serde_json::Va
|
||||
| RolloutItem::RetainedContext(_)
|
||||
| RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::EventMsg(_) => {}
|
||||
| RolloutItem::EventMsg { .. } => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1228,7 +1228,7 @@ pub async fn read_session_meta_line(path: &Path) -> io::Result<SessionMetaLine>
|
||||
| RolloutItem::RetainedContext(_)
|
||||
| RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::EventMsg(_) => {}
|
||||
| RolloutItem::EventMsg { .. } => {}
|
||||
}
|
||||
}
|
||||
Err(io::Error::other(MetadataReadError {
|
||||
|
||||
@@ -86,7 +86,7 @@ pub fn builder_from_items(
|
||||
| RolloutItem::RetainedContext(_)
|
||||
| RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::EventMsg(_) => None,
|
||||
| RolloutItem::EventMsg { .. } => None,
|
||||
}) && let Some(builder) = builder_from_session_meta(session_meta, rollout_path)
|
||||
{
|
||||
return Some(builder);
|
||||
@@ -184,7 +184,7 @@ pub async fn extract_metadata_from_rollout(
|
||||
| RolloutItem::RetainedContext(_)
|
||||
| RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::EventMsg(_) => None,
|
||||
| RolloutItem::EventMsg { .. } => None,
|
||||
}),
|
||||
parse_errors,
|
||||
})
|
||||
|
||||
@@ -168,8 +168,8 @@ fn update_turn_measurements(
|
||||
) -> TurnMeasurementUpdate {
|
||||
let mut update = TurnMeasurementUpdate::default();
|
||||
for (item, item_measurement) in items.iter().zip(&measurement.items) {
|
||||
match item {
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(_)) => {
|
||||
match item.event_msg() {
|
||||
Some(EventMsg::TurnStarted(_)) => {
|
||||
if state.active.take().is_some() {
|
||||
update.boundary_errors.push("event.turn_started");
|
||||
}
|
||||
@@ -177,7 +177,7 @@ fn update_turn_measurements(
|
||||
add_item_to_turn(&mut totals, item_measurement);
|
||||
state.active = Some(totals);
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(_)) => {
|
||||
Some(EventMsg::TurnComplete(_)) => {
|
||||
finish_turn(
|
||||
state,
|
||||
item_measurement,
|
||||
@@ -186,7 +186,7 @@ fn update_turn_measurements(
|
||||
&mut update,
|
||||
);
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(_)) => {
|
||||
Some(EventMsg::TurnAborted(_)) => {
|
||||
finish_turn(
|
||||
state,
|
||||
item_measurement,
|
||||
@@ -289,10 +289,15 @@ fn rollout_item_type(item: &RolloutItem) -> String {
|
||||
"realtime.session_input_saved".to_string()
|
||||
}
|
||||
},
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} => {
|
||||
format!("event.item_completed.{}", turn_item_type(&event.item))
|
||||
}
|
||||
RolloutItem::EventMsg(event) => format!("event.{event}"),
|
||||
RolloutItem::EventMsg { event, .. } => {
|
||||
format!("event.{event}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,12 +30,16 @@ pub fn persisted_rollout_item(
|
||||
}
|
||||
RolloutItem::InterAgentCommunication(_)
|
||||
| RolloutItem::InterAgentCommunicationMetadata { .. } => Some(Cow::Borrowed(item)),
|
||||
RolloutItem::EventMsg(ev) => {
|
||||
persisted_event_msg(ev, history_mode).map(|event| match event {
|
||||
Cow::Borrowed(_) => Cow::Borrowed(item),
|
||||
Cow::Owned(event) => Cow::Owned(RolloutItem::EventMsg(event)),
|
||||
})
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: ev,
|
||||
metadata,
|
||||
} => persisted_event_msg(ev, history_mode).map(|event| match event {
|
||||
Cow::Borrowed(_) => Cow::Borrowed(item),
|
||||
Cow::Owned(event) => Cow::Owned(RolloutItem::EventMsg {
|
||||
event,
|
||||
metadata: metadata.clone(),
|
||||
}),
|
||||
}),
|
||||
RolloutItem::RealtimeItem(_) => {
|
||||
matches!(history_mode, ThreadHistoryMode::Paginated).then_some(Cow::Borrowed(item))
|
||||
}
|
||||
|
||||
@@ -2212,7 +2212,7 @@ async fn resume_candidate_matches_cwd(
|
||||
| RolloutItem::TokenUsageRecord(_)
|
||||
| RolloutItem::RetainedContext(_)
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::EventMsg(_) => None,
|
||||
| RolloutItem::EventMsg { .. } => None,
|
||||
})
|
||||
{
|
||||
return cwd_matches(latest_turn_context_cwd.as_path(), cwd);
|
||||
|
||||
@@ -461,7 +461,11 @@ async fn load_rollout_items_preserves_legacy_guardian_assessment_lines() -> std:
|
||||
assert_eq!(loaded_thread_id, Some(thread_id));
|
||||
assert_eq!(parse_errors, 0);
|
||||
assert_eq!(items.len(), 2);
|
||||
let RolloutItem::EventMsg(EventMsg::GuardianAssessment(assessment)) = &items[1] else {
|
||||
let RolloutItem::EventMsg {
|
||||
event: EventMsg::GuardianAssessment(assessment),
|
||||
..
|
||||
} = &items[1]
|
||||
else {
|
||||
panic!("expected guardian assessment rollout item");
|
||||
};
|
||||
assert_eq!(assessment.id, "guardian-1");
|
||||
|
||||
@@ -324,7 +324,10 @@ fn content_match_snippet(jsonl_line: &str, search_term: &Regex) -> Option<String
|
||||
|
||||
fn conversation_text_from_item(item: &RolloutItem) -> Option<String> {
|
||||
match item {
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(user)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(user),
|
||||
..
|
||||
} => {
|
||||
let text = strip_user_message_prefix(user.message.as_str());
|
||||
if text.is_empty() {
|
||||
None
|
||||
@@ -332,7 +335,10 @@ fn conversation_text_from_item(item: &RolloutItem) -> Option<String> {
|
||||
Some(text.to_string())
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::AgentMessage(agent)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::AgentMessage(agent),
|
||||
..
|
||||
} => {
|
||||
if agent.message.trim().is_empty() {
|
||||
None
|
||||
} else {
|
||||
@@ -357,7 +363,7 @@ fn conversation_text_from_item(item: &RolloutItem) -> Option<String> {
|
||||
RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SessionMeta(_)
|
||||
| RolloutItem::TurnContext(_)
|
||||
| RolloutItem::EventMsg(_)
|
||||
| RolloutItem::EventMsg { .. }
|
||||
| RolloutItem::ResponseItem(_)
|
||||
| RolloutItem::InterAgentCommunication(_)
|
||||
| RolloutItem::InterAgentCommunicationMetadata { .. }
|
||||
|
||||
@@ -33,7 +33,9 @@ pub fn apply_rollout_item(
|
||||
match item {
|
||||
RolloutItem::SessionMeta(meta_line) => apply_session_meta_from_item(metadata, meta_line),
|
||||
RolloutItem::TurnContext(turn_ctx) => apply_turn_context(metadata, turn_ctx),
|
||||
RolloutItem::EventMsg(event) => apply_event_msg(metadata, event),
|
||||
RolloutItem::EventMsg { event, .. } => {
|
||||
apply_event_msg(metadata, event);
|
||||
}
|
||||
RolloutItem::ResponseItem(item) => apply_response_item(metadata, &item.item),
|
||||
RolloutItem::InterAgentCommunication(_)
|
||||
| RolloutItem::InterAgentCommunicationMetadata { .. } => {}
|
||||
@@ -54,21 +56,25 @@ pub fn apply_rollout_item(
|
||||
pub fn rollout_item_affects_thread_metadata(item: &RolloutItem) -> bool {
|
||||
match item {
|
||||
RolloutItem::SessionMeta(_) | RolloutItem::TurnContext(_) => true,
|
||||
RolloutItem::EventMsg(
|
||||
EventMsg::TokenCount(_)
|
||||
| EventMsg::UserMessage(_)
|
||||
| EventMsg::ThreadGoalUpdated(_)
|
||||
| EventMsg::ThreadSettingsApplied(_),
|
||||
) => true,
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event))
|
||||
if matches!(
|
||||
event.item,
|
||||
TurnItem::UserMessage(_) | TurnItem::FunctionCallOutput(_)
|
||||
) =>
|
||||
RolloutItem::EventMsg {
|
||||
event:
|
||||
EventMsg::TokenCount(_)
|
||||
| EventMsg::UserMessage(_)
|
||||
| EventMsg::ThreadGoalUpdated(_)
|
||||
| EventMsg::ThreadSettingsApplied(_),
|
||||
..
|
||||
} => true,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} if matches!(
|
||||
event.item,
|
||||
TurnItem::UserMessage(_) | TurnItem::FunctionCallOutput(_)
|
||||
) =>
|
||||
{
|
||||
true
|
||||
}
|
||||
RolloutItem::EventMsg(_)
|
||||
RolloutItem::EventMsg { .. }
|
||||
| RolloutItem::ResponseItem(_)
|
||||
| RolloutItem::InterAgentCommunication(_)
|
||||
| RolloutItem::InterAgentCommunicationMetadata { .. }
|
||||
|
||||
@@ -1559,7 +1559,7 @@ pub(super) fn extract_memory_mode(items: &[RolloutItem]) -> Option<String> {
|
||||
| RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SecurityRiskScore(_)
|
||||
| RolloutItem::TokenUsageRecord(_)
|
||||
| RolloutItem::EventMsg(_) => None,
|
||||
| RolloutItem::EventMsg { .. } => None,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2274,7 +2274,7 @@ mod tests {
|
||||
assert!(history.items.iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(event)) if event.message == "external history item"
|
||||
RolloutItem::EventMsg { event: EventMsg::UserMessage(event), .. } if event.message == "external history item"
|
||||
)
|
||||
}));
|
||||
}
|
||||
@@ -2317,7 +2317,7 @@ mod tests {
|
||||
assert!(thread.history.expect("history").items.iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(event)) if event.message == "Hello from user"
|
||||
RolloutItem::EventMsg { event: EventMsg::UserMessage(event), .. } if event.message == "Hello from user"
|
||||
)
|
||||
}));
|
||||
|
||||
@@ -2408,7 +2408,7 @@ mod tests {
|
||||
assert!(history.items.iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(event)) if event.message == "archived live history item"
|
||||
RolloutItem::EventMsg { event: EventMsg::UserMessage(event), .. } if event.message == "archived live history item"
|
||||
)
|
||||
}));
|
||||
}
|
||||
@@ -2454,7 +2454,13 @@ mod tests {
|
||||
.expect("history")
|
||||
.items
|
||||
.iter()
|
||||
.filter(|item| matches!(item, RolloutItem::EventMsg(EventMsg::UserMessage(_))))
|
||||
.filter(|item| matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(_),
|
||||
..
|
||||
}
|
||||
))
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
@@ -2581,14 +2587,14 @@ mod tests {
|
||||
assert!(items.iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event))
|
||||
RolloutItem::EventMsg { event: EventMsg::ItemCompleted(event), .. }
|
||||
if event.turn_id == "turn-1"
|
||||
)
|
||||
}));
|
||||
assert!(!items.iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(event))
|
||||
RolloutItem::EventMsg { event: EventMsg::UserMessage(event), .. }
|
||||
if event.message == "legacy event should not persist"
|
||||
)
|
||||
}));
|
||||
@@ -2656,7 +2662,7 @@ mod tests {
|
||||
assert!(items.iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(event)) if event.message == expected
|
||||
RolloutItem::EventMsg { event: EventMsg::UserMessage(event), .. } if event.message == expected
|
||||
)
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -95,9 +95,15 @@ async fn attached_history_start(path: &Path, start: u64) -> std::io::Result<u64>
|
||||
};
|
||||
match line.item {
|
||||
RolloutItem::SessionMeta(_)
|
||||
| RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(_))
|
||||
| RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(_),
|
||||
..
|
||||
}
|
||||
| RolloutItem::ResponseItem(_) => {}
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(_)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnAborted(_),
|
||||
..
|
||||
} => {
|
||||
return Ok(line.ordinal.map_or(start, |n| n.saturating_add(1)));
|
||||
}
|
||||
_ => break,
|
||||
|
||||
@@ -1001,7 +1001,10 @@ impl LocalThreadStore {
|
||||
if plan.is_none()
|
||||
&& matches!(
|
||||
&line.item,
|
||||
RolloutItem::EventMsg(codex_protocol::protocol::EventMsg::ThreadRolledBack(_))
|
||||
RolloutItem::EventMsg {
|
||||
event: codex_protocol::protocol::EventMsg::ThreadRolledBack(_),
|
||||
..
|
||||
}
|
||||
)
|
||||
{
|
||||
return Ok(CanonicalizationAttempt::NeedsRollbackPlan);
|
||||
|
||||
@@ -113,7 +113,8 @@ impl LegacyRolloutCanonicalizer {
|
||||
.ok_or_else(|| migration_error("legacy rollout line index overflow"))?;
|
||||
let timestamp = line.timestamp;
|
||||
let bytes_before = self.bytes_written;
|
||||
match line.item {
|
||||
let item = line.item;
|
||||
match item {
|
||||
RolloutItem::SessionMeta(_) => return Ok(0),
|
||||
RolloutItem::ResponseItem(response) => {
|
||||
if matches!(&response.item, ResponseItem::Other) {
|
||||
@@ -136,12 +137,18 @@ impl LegacyRolloutCanonicalizer {
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(_)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadRolledBack(_),
|
||||
..
|
||||
} => {
|
||||
return Err(migration_error(
|
||||
"rollback marker reached canonical writer without a rollback plan",
|
||||
));
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} => {
|
||||
self.finish_implicit_turn(writer, ×tamp).await?;
|
||||
self.known_turn_ids.insert(event.turn_id.clone());
|
||||
self.active_turn = Some(ActiveTurn {
|
||||
@@ -157,7 +164,10 @@ impl LegacyRolloutCanonicalizer {
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnComplete(ref event),
|
||||
..
|
||||
} => {
|
||||
self.reasoning = None;
|
||||
if self
|
||||
.active_turn
|
||||
@@ -166,14 +176,12 @@ impl LegacyRolloutCanonicalizer {
|
||||
{
|
||||
self.active_turn = None;
|
||||
}
|
||||
self.write_item(
|
||||
writer,
|
||||
×tamp,
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)),
|
||||
)
|
||||
.await?;
|
||||
self.write_item(writer, ×tamp, item).await?;
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(mut event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnAborted(mut event),
|
||||
..
|
||||
} => {
|
||||
if event.turn_id.is_none() {
|
||||
event.turn_id = self.active_turn.as_ref().map(|turn| turn.id.clone());
|
||||
}
|
||||
@@ -192,7 +200,10 @@ impl LegacyRolloutCanonicalizer {
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(event),
|
||||
..
|
||||
} => {
|
||||
if self
|
||||
.active_turn
|
||||
.as_ref()
|
||||
@@ -208,7 +219,10 @@ impl LegacyRolloutCanonicalizer {
|
||||
self.reasoning = None;
|
||||
self.write_completed_item(writer, ×tamp, item).await?;
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::AgentReasoning(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::AgentReasoning(event),
|
||||
..
|
||||
} => {
|
||||
self.write_reasoning(
|
||||
writer,
|
||||
×tamp,
|
||||
@@ -218,7 +232,10 @@ impl LegacyRolloutCanonicalizer {
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::AgentReasoningRawContent(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::AgentReasoningRawContent(event),
|
||||
..
|
||||
} => {
|
||||
self.write_reasoning(
|
||||
writer,
|
||||
×tamp,
|
||||
@@ -228,7 +245,10 @@ impl LegacyRolloutCanonicalizer {
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(mut event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(mut event),
|
||||
..
|
||||
} => {
|
||||
event.thread_id = self.thread_id;
|
||||
self.reasoning = None;
|
||||
self.write_item(
|
||||
@@ -238,7 +258,7 @@ impl LegacyRolloutCanonicalizer {
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
RolloutItem::EventMsg(event) => {
|
||||
RolloutItem::EventMsg { event, .. } => {
|
||||
if let Some((item, turn_id)) =
|
||||
legacy_event::completed_item(&event, &mut || self.next_item_id())?
|
||||
{
|
||||
|
||||
@@ -47,7 +47,10 @@ fn parses_legacy_numeric_event_payloads_through_value() {
|
||||
.expect("keep legacy token count");
|
||||
assert!(matches!(
|
||||
parsed.item,
|
||||
RolloutItem::EventMsg(EventMsg::TokenCount(_))
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TokenCount(_),
|
||||
..
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
@@ -76,7 +79,10 @@ fn normalizes_legacy_rate_limit_reset_timestamps() {
|
||||
.expect("keep legacy token count");
|
||||
assert!(matches!(
|
||||
parsed.item,
|
||||
RolloutItem::EventMsg(EventMsg::TokenCount(_))
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TokenCount(_),
|
||||
..
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
@@ -155,7 +161,10 @@ fn normalizes_legacy_review_entry_prompt() {
|
||||
.expect("keep legacy review entry");
|
||||
assert!(matches!(
|
||||
parsed.item,
|
||||
RolloutItem::EventMsg(EventMsg::EnteredReviewMode(_))
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::EnteredReviewMode(_),
|
||||
..
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
@@ -187,7 +196,10 @@ fn normalizes_legacy_plain_command_cwd() {
|
||||
.expect("keep legacy command");
|
||||
assert!(matches!(
|
||||
parsed.item,
|
||||
RolloutItem::EventMsg(EventMsg::ExecCommandEnd(_))
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ExecCommandEnd(_),
|
||||
..
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,10 @@ impl RollbackPlan {
|
||||
.ok_or_else(|| migration_error("rollback plan is shorter than source replay"))?;
|
||||
if matches!(
|
||||
&line.item,
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(_))
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadRolledBack(_),
|
||||
..
|
||||
}
|
||||
) {
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -142,11 +145,13 @@ impl RollbackPlanner {
|
||||
self.record_boundaries
|
||||
.push(self.boundary_stack.last().copied());
|
||||
let paired_user_boundary = match (&self.pending_user_response, &line.item) {
|
||||
(Some(pending), RolloutItem::EventMsg(EventMsg::UserMessage(event)))
|
||||
if user_response_matches_event(&pending.content, event) =>
|
||||
{
|
||||
Some(pending.boundary)
|
||||
}
|
||||
(
|
||||
Some(pending),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(event),
|
||||
..
|
||||
},
|
||||
) if user_response_matches_event(&pending.content, event) => Some(pending.boundary),
|
||||
_ => None,
|
||||
};
|
||||
let paired_delivery_boundary = match (&self.pending_delivery_boundary, &line.item) {
|
||||
@@ -164,9 +169,10 @@ impl RollbackPlanner {
|
||||
RolloutItem::DynamicToolsUpdated { .. } | RolloutItem::SessionMeta(_) => {
|
||||
self.record_boundaries[index] = None
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event))
|
||||
if event.thread_id.is_some() =>
|
||||
{
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} if event.thread_id.is_some() => {
|
||||
self.record_boundaries[index] = None;
|
||||
}
|
||||
RolloutItem::ResponseItem(response) => {
|
||||
@@ -221,22 +227,34 @@ impl RollbackPlanner {
|
||||
);
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(rollback)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadRolledBack(rollback),
|
||||
..
|
||||
} => {
|
||||
self.apply_rollback(rollback.num_turns)?;
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} => {
|
||||
self.active_turn_id = Some(event.turn_id.clone());
|
||||
self.pending_turn_records.clear();
|
||||
self.pending_turn_records.push(index);
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnComplete(event),
|
||||
..
|
||||
} => {
|
||||
self.assign_targeted_record(index, Some(event.turn_id.as_str()));
|
||||
if self.active_turn_id.as_deref() == Some(event.turn_id.as_str()) {
|
||||
self.active_turn_id = None;
|
||||
self.pending_turn_records.clear();
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnAborted(event),
|
||||
..
|
||||
} => {
|
||||
self.assign_targeted_record(index, event.turn_id.as_deref());
|
||||
if event
|
||||
.turn_id
|
||||
@@ -247,14 +265,20 @@ impl RollbackPlanner {
|
||||
self.pending_turn_records.clear();
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(_)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(_),
|
||||
..
|
||||
} => {
|
||||
let boundary = paired_user_boundary.unwrap_or_else(|| self.start_boundary(index));
|
||||
self.record_boundaries[index] = Some(boundary);
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} => {
|
||||
self.assign_targeted_record(index, Some(event.turn_id.as_str()));
|
||||
}
|
||||
RolloutItem::EventMsg(event) => {
|
||||
RolloutItem::EventMsg { event, .. } => {
|
||||
self.assign_targeted_record(index, explicit_event_turn_id(event));
|
||||
}
|
||||
RolloutItem::InterAgentCommunication(_) => {
|
||||
|
||||
@@ -53,20 +53,27 @@ impl ModelReplayPlanner {
|
||||
record_index,
|
||||
has_replacement_history: compacted.replacement_history.is_some(),
|
||||
},
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(rollback)) => {
|
||||
ReplayRecord::Rollback(rollback.num_turns)
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event)) => {
|
||||
ReplayRecord::TurnStarted(event.turn_id.clone())
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)) => {
|
||||
ReplayRecord::TurnComplete(event.turn_id.clone())
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(event)) => {
|
||||
ReplayRecord::TurnAborted(event.turn_id.clone())
|
||||
}
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadRolledBack(rollback),
|
||||
..
|
||||
} => ReplayRecord::Rollback(rollback.num_turns),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} => ReplayRecord::TurnStarted(event.turn_id.clone()),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnComplete(event),
|
||||
..
|
||||
} => ReplayRecord::TurnComplete(event.turn_id.clone()),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnAborted(event),
|
||||
..
|
||||
} => ReplayRecord::TurnAborted(event.turn_id.clone()),
|
||||
RolloutItem::TurnContext(context) => ReplayRecord::TurnContext(context.turn_id.clone()),
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(_))
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(_),
|
||||
..
|
||||
}
|
||||
| RolloutItem::InterAgentCommunication(_) => ReplayRecord::UserBoundary,
|
||||
RolloutItem::ResponseItem(response) if rollback::counts_as_boundary(response) => {
|
||||
ReplayRecord::UserBoundary
|
||||
@@ -74,7 +81,7 @@ impl ModelReplayPlanner {
|
||||
RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SessionMeta(_)
|
||||
| RolloutItem::ResponseItem(_)
|
||||
| RolloutItem::EventMsg(_)
|
||||
| RolloutItem::EventMsg { .. }
|
||||
| RolloutItem::InterAgentCommunicationMetadata { .. }
|
||||
| RolloutItem::RealtimeItem(_)
|
||||
| RolloutItem::TokenUsageRecord(_)
|
||||
|
||||
@@ -384,15 +384,25 @@ async fn migration_publishes_canonical_projected_history_and_is_idempotent() {
|
||||
assert_eq!(
|
||||
lines
|
||||
.iter()
|
||||
.filter(|line| matches!(line.item, RolloutItem::EventMsg(EventMsg::ItemCompleted(_))))
|
||||
.filter(|line| matches!(
|
||||
line.item,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(_),
|
||||
..
|
||||
}
|
||||
))
|
||||
.count(),
|
||||
2
|
||||
);
|
||||
let user_item = lines.iter().find_map(|line| match &line.item {
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(ItemCompletedEvent {
|
||||
item: TurnItem::UserMessage(item),
|
||||
RolloutItem::EventMsg {
|
||||
event:
|
||||
EventMsg::ItemCompleted(ItemCompletedEvent {
|
||||
item: TurnItem::UserMessage(item),
|
||||
..
|
||||
}),
|
||||
..
|
||||
})) => Some(item),
|
||||
} => Some(item),
|
||||
_ => None,
|
||||
});
|
||||
let expected_content = vec![
|
||||
@@ -602,7 +612,10 @@ async fn migration_preserves_image_generation_failure_metadata() {
|
||||
let migrated_item = read_rollout(&path)
|
||||
.into_iter()
|
||||
.find_map(|line| match line.item {
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event)) => Some(event.item),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} => Some(event.item),
|
||||
_ => None,
|
||||
})
|
||||
.expect("migrated image completion");
|
||||
@@ -671,7 +684,10 @@ async fn migration_preserves_image_generation_input_observations() {
|
||||
let migrated_item = read_rollout(&path)
|
||||
.into_iter()
|
||||
.find_map(|line| match line.item {
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event)) => Some(event.item),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} => Some(event.item),
|
||||
_ => None,
|
||||
})
|
||||
.expect("migrated image completion");
|
||||
@@ -721,7 +737,10 @@ async fn migration_keeps_late_completions_in_their_original_turn() {
|
||||
let started_turn_ids = read_rollout(&path)
|
||||
.into_iter()
|
||||
.filter_map(|line| match line.item {
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event)) => Some(event.turn_id),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} => Some(event.turn_id),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@@ -845,7 +864,13 @@ async fn migration_preserves_valid_final_record_without_newline() {
|
||||
assert_eq!(
|
||||
read_rollout(&path)
|
||||
.iter()
|
||||
.filter(|line| matches!(line.item, RolloutItem::EventMsg(EventMsg::ItemCompleted(_))))
|
||||
.filter(|line| matches!(
|
||||
line.item,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(_),
|
||||
..
|
||||
}
|
||||
))
|
||||
.count(),
|
||||
2
|
||||
);
|
||||
@@ -890,7 +915,10 @@ async fn migration_applies_historical_rollbacks_before_sqlite_projection() {
|
||||
let lines = read_rollout(&path);
|
||||
assert!(!lines.iter().any(|line| matches!(
|
||||
line.item,
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(_))
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadRolledBack(_),
|
||||
..
|
||||
}
|
||||
)));
|
||||
let turns = list_active_summary_turns(&store, thread_id).await;
|
||||
assert_eq!(
|
||||
@@ -1179,26 +1207,26 @@ async fn migration_keeps_late_completions_for_surviving_turns_across_rollback()
|
||||
let lines = read_rollout(&path);
|
||||
assert!(!lines.iter().any(|line| matches!(
|
||||
&line.item,
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event))
|
||||
RolloutItem::EventMsg { event: EventMsg::ItemCompleted(event), .. }
|
||||
if event.item.id() == "call-remove"
|
||||
)));
|
||||
assert!(lines.iter().any(|line| matches!(
|
||||
&line.item,
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event))
|
||||
RolloutItem::EventMsg { event: EventMsg::ItemCompleted(event), .. }
|
||||
if event.turn_id == "old" && event.item.id() == "call-old"
|
||||
)));
|
||||
assert!(lines.iter().any(|line| matches!(
|
||||
&line.item,
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event))
|
||||
RolloutItem::EventMsg { event: EventMsg::ItemCompleted(event), .. }
|
||||
if event.turn_id == "old" && event.item.id() == "reason-old"
|
||||
)));
|
||||
assert!(lines.iter().any(|line| matches!(
|
||||
&line.item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)) if event.turn_id == "old"
|
||||
RolloutItem::EventMsg { event: EventMsg::TurnComplete(event), .. } if event.turn_id == "old"
|
||||
)));
|
||||
assert!(!lines.iter().any(|line| matches!(
|
||||
&line.item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)) if event.turn_id == "remove"
|
||||
RolloutItem::EventMsg { event: EventMsg::TurnComplete(event), .. } if event.turn_id == "remove"
|
||||
)));
|
||||
let turns = store
|
||||
.list_turns(ListTurnsParams {
|
||||
@@ -2166,7 +2194,10 @@ async fn migration_applies_cumulative_and_overflowing_rollbacks() {
|
||||
assert_eq!(turns.turns.len(), 1);
|
||||
assert!(!read_rollout(&path).iter().any(|line| matches!(
|
||||
line.item,
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(_))
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadRolledBack(_),
|
||||
..
|
||||
}
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -2399,7 +2430,13 @@ async fn migration_keeps_small_uncompacted_subagent_replay_as_prefix() {
|
||||
assert_eq!(
|
||||
lines
|
||||
.iter()
|
||||
.filter(|line| matches!(line.item, RolloutItem::EventMsg(EventMsg::ItemCompleted(_))))
|
||||
.filter(|line| matches!(
|
||||
line.item,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(_),
|
||||
..
|
||||
}
|
||||
))
|
||||
.count(),
|
||||
2
|
||||
);
|
||||
|
||||
@@ -1130,7 +1130,7 @@ async fn active_turn_stores_only_its_start_position() {
|
||||
})
|
||||
);
|
||||
assert!(prepared.model_context.iter().any(|item| {
|
||||
matches!(item, RolloutItem::EventMsg(EventMsg::TurnStarted(event)) if event.turn_id == "turn-1")
|
||||
matches!(item, RolloutItem::EventMsg { event: EventMsg::TurnStarted(event), .. } if event.turn_id == "turn-1")
|
||||
}));
|
||||
// Another store may fork the persisted prefix while this store keeps the source writer open.
|
||||
let other_store = projection_store(home.path()).await;
|
||||
@@ -2733,7 +2733,7 @@ async fn sqlite_failure_does_not_fail_durable_jsonl_write() {
|
||||
assert!(items.iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event))
|
||||
RolloutItem::EventMsg { event: EventMsg::TurnStarted(event), .. }
|
||||
if event.turn_id == "turn-1"
|
||||
)
|
||||
}));
|
||||
@@ -3198,7 +3198,11 @@ fn turn_started(turn_id: &str) -> RolloutItem {
|
||||
|
||||
fn turn_started_with_root(turn_id: &str, root_turn_id: &str) -> RolloutItem {
|
||||
let mut item = turn_started(turn_id);
|
||||
if let RolloutItem::EventMsg(EventMsg::TurnStarted(event)) = &mut item {
|
||||
if let RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(event),
|
||||
..
|
||||
} = &mut item
|
||||
{
|
||||
event.root_turn_id = Some(root_turn_id.to_string());
|
||||
}
|
||||
item
|
||||
|
||||
@@ -189,9 +189,15 @@ impl ThreadMetadataSync {
|
||||
let affects_metadata = items
|
||||
.iter()
|
||||
.any(codex_state::rollout_item_affects_thread_metadata);
|
||||
let advances_recency = items
|
||||
.iter()
|
||||
.any(|item| matches!(item, RolloutItem::EventMsg(EventMsg::TurnStarted(_))));
|
||||
let advances_recency = items.iter().any(|item| {
|
||||
matches!(
|
||||
item,
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TurnStarted(_),
|
||||
..
|
||||
}
|
||||
)
|
||||
});
|
||||
let mut update = if affects_metadata {
|
||||
self.observe_items(items)?
|
||||
} else {
|
||||
@@ -299,10 +305,16 @@ impl ThreadMetadataSync {
|
||||
update.approval_mode = Some(turn_ctx.approval_policy);
|
||||
update.permission_profile = Some(turn_ctx.permission_profile.clone());
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(user)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(user),
|
||||
..
|
||||
} => {
|
||||
self.observe_user_message(user, &mut update);
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ItemCompleted(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ItemCompleted(event),
|
||||
..
|
||||
} => {
|
||||
if let TurnItem::UserMessage(user) = &event.item
|
||||
&& (!self.first_user_message_seen || !self.preview_seen || !self.title_seen)
|
||||
{
|
||||
@@ -318,12 +330,18 @@ impl ThreadMetadataSync {
|
||||
update.preview = Some(preview);
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TokenCount(token_count)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::TokenCount(token_count),
|
||||
..
|
||||
} => {
|
||||
if let Some(info) = token_count.info.as_ref() {
|
||||
update.token_usage = Some(info.total_token_usage.clone());
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ThreadGoalUpdated(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadGoalUpdated(event),
|
||||
..
|
||||
} => {
|
||||
if !self.preview_seen {
|
||||
let objective = event.goal.objective.trim();
|
||||
if !objective.is_empty() {
|
||||
@@ -332,7 +350,10 @@ impl ThreadMetadataSync {
|
||||
}
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} => {
|
||||
let settings = &event.thread_settings;
|
||||
self.cwd_seen = true;
|
||||
update.model = Some(settings.model.clone());
|
||||
@@ -344,7 +365,7 @@ impl ThreadMetadataSync {
|
||||
}
|
||||
RolloutItem::DynamicToolsUpdated { .. }
|
||||
| RolloutItem::SessionMeta(_)
|
||||
| RolloutItem::EventMsg(_)
|
||||
| RolloutItem::EventMsg { .. }
|
||||
| RolloutItem::ResponseItem(_)
|
||||
| RolloutItem::InterAgentCommunication(_)
|
||||
| RolloutItem::InterAgentCommunicationMetadata { .. }
|
||||
@@ -794,7 +815,11 @@ mod tests {
|
||||
assert_eq!(update.patch.approval_mode, Some(AskForApproval::Never));
|
||||
assert_eq!(update.patch.permission_profile, Some(permission_profile));
|
||||
|
||||
let RolloutItem::EventMsg(EventMsg::ThreadSettingsApplied(event)) = &mut item else {
|
||||
let RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadSettingsApplied(event),
|
||||
..
|
||||
} = &mut item
|
||||
else {
|
||||
panic!("thread settings applied item");
|
||||
};
|
||||
event.thread_settings.reasoning_effort = None;
|
||||
|
||||
@@ -44,7 +44,10 @@ pub(super) async fn side_context_checkpoint(path: Option<&Path>) -> io::Result<O
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(codex_protocol::protocol::EventMsg::TurnStarted(_)) => break,
|
||||
RolloutItem::EventMsg {
|
||||
event: codex_protocol::protocol::EventMsg::TurnStarted(_),
|
||||
..
|
||||
} => break,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,8 +171,14 @@ fn scan_legacy_transcript_preview(
|
||||
continue;
|
||||
};
|
||||
match line.item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(_)) => return Ok(None),
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(message)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::ThreadRolledBack(_),
|
||||
..
|
||||
} => return Ok(None),
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::UserMessage(message),
|
||||
..
|
||||
} => {
|
||||
append_transcript_preview_text(
|
||||
&mut lines,
|
||||
TranscriptPreviewSpeaker::User,
|
||||
@@ -181,7 +187,10 @@ fn scan_legacy_transcript_preview(
|
||||
inline_visualization_context,
|
||||
);
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::AgentMessage(message)) => {
|
||||
RolloutItem::EventMsg {
|
||||
event: EventMsg::AgentMessage(message),
|
||||
..
|
||||
} => {
|
||||
append_transcript_preview_text(
|
||||
&mut lines,
|
||||
TranscriptPreviewSpeaker::Assistant,
|
||||
|
||||
Reference in New Issue
Block a user