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:
ioanbudea-OAI
2026-11-24 16:14:00 +00:00
committed by copyberry
parent cba3c40cf7
commit 77acaa207f
91 changed files with 1025 additions and 513 deletions
+12 -3
View File
@@ -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
);
+5 -1
View File
@@ -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<_>>();
+4 -3
View File
@@ -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"
+4 -1
View File
@@ -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,
+4 -2
View File
@@ -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);
+8 -8
View File
@@ -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>(());
}
+4 -1
View File
@@ -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())
+1 -1
View File
@@ -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?;
+12 -7
View File
@@ -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)
}
+4 -5
View File
@@ -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<_>>();