diff --git a/codex-rs/core/src/compact.rs b/codex-rs/core/src/compact.rs index 59332d66d2..781c578cd6 100644 --- a/codex-rs/core/src/compact.rs +++ b/codex-rs/core/src/compact.rs @@ -519,36 +519,14 @@ pub(crate) fn build_compacted_history( user_messages, summary_text, COMPACT_USER_MESSAGE_MAX_TOKENS, - CompactedHistoryMessageIds::New, ) } -pub(crate) fn rebuild_legacy_compacted_history( - initial_context: Vec, - user_messages: &[String], - summary_text: &str, -) -> Vec { - build_compacted_history_with_limit( - initial_context, - user_messages, - summary_text, - COMPACT_USER_MESSAGE_MAX_TOKENS, - CompactedHistoryMessageIds::Missing, - ) -} - -#[derive(Clone, Copy)] -enum CompactedHistoryMessageIds { - New, - Missing, -} - fn build_compacted_history_with_limit( mut history: Vec, user_messages: &[String], summary_text: &str, max_tokens: usize, - message_ids: CompactedHistoryMessageIds, ) -> Vec { let mut selected_messages: Vec = Vec::new(); if max_tokens > 0 { @@ -571,7 +549,7 @@ fn build_compacted_history_with_limit( } for message in &selected_messages { - history.push(compacted_user_message(message.clone(), message_ids)); + history.push(compacted_user_message(message.clone())); } let summary_text = if summary_text.is_empty() { @@ -580,22 +558,14 @@ fn build_compacted_history_with_limit( summary_text.to_string() }; - history.push(compacted_user_message(summary_text, message_ids)); + history.push(compacted_user_message(summary_text)); history } -fn compacted_user_message(text: String, message_ids: CompactedHistoryMessageIds) -> ResponseItem { +fn compacted_user_message(text: String) -> ResponseItem { let content = vec![ContentItem::InputText { text }]; - match message_ids { - CompactedHistoryMessageIds::New => ResponseItem::new_message("user", content), - CompactedHistoryMessageIds::Missing => ResponseItem::Message { - id: None, - role: "user".to_string(), - content, - phase: None, - }, - } + ResponseItem::new_message("user", content) } async fn drain_to_completed( diff --git a/codex-rs/core/src/compact_tests.rs b/codex-rs/core/src/compact_tests.rs index bc3f32e181..7c698b1329 100644 --- a/codex-rs/core/src/compact_tests.rs +++ b/codex-rs/core/src/compact_tests.rs @@ -162,7 +162,6 @@ fn build_token_limited_compacted_history_truncates_overlong_user_messages() { std::slice::from_ref(&big), "SUMMARY", max_tokens, - super::CompactedHistoryMessageIds::New, ); assert_eq!(history.len(), 2); diff --git a/codex-rs/core/src/session/rollout_reconstruction.rs b/codex-rs/core/src/session/rollout_reconstruction.rs index 4012d1be61..9e57d5a9d9 100644 --- a/codex-rs/core/src/session/rollout_reconstruction.rs +++ b/codex-rs/core/src/session/rollout_reconstruction.rs @@ -254,16 +254,17 @@ impl Session { history.replace(replacement_history.clone()); } else { saw_legacy_compaction_without_replacement_history = true; - // Legacy rollouts without `replacement_history` should rebuild the - // historical TurnContext at the correct insertion point from persisted - // `TurnContextItem`s. These are rare enough that we currently just clear - // `reference_context_item`, reinject canonical context at the end of the - // resumed conversation, and accept the temporary out-of-distribution - // prompt shape. + // Legacy rollouts without `replacement_history` rebuild fresh compacted + // replacement messages from the historical user-message text and summary. + // They should also rebuild the historical TurnContext at the correct + // insertion point from persisted `TurnContextItem`s. These are rare enough + // that we currently just clear `reference_context_item`, reinject canonical + // context at the end of the resumed conversation, and accept the temporary + // out-of-distribution prompt shape. // TODO(ccunningham): if we drop support for None replacement_history compaction items, // we can get rid of this second loop entirely and just build `history` directly in the first loop. let user_messages = collect_user_messages(history.raw_items()); - let rebuilt = compact::rebuild_legacy_compacted_history( + let rebuilt = compact::build_compacted_history( Vec::new(), &user_messages, &compacted.message,