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:
@@ -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<_>>();
|
||||
|
||||
Reference in New Issue
Block a user