From 3759abaf1594bf2d43aba92bb97383c07de7803d Mon Sep 17 00:00:00 2001 From: Charles Cunningham Date: Wed, 18 Feb 2026 00:27:44 -0800 Subject: [PATCH] Inline compact merge item matcher --- codex-rs/core/src/compact_remote.rs | 59 +++++++++++++---------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/codex-rs/core/src/compact_remote.rs b/codex-rs/core/src/compact_remote.rs index 09296043a6..1a8eb88656 100644 --- a/codex-rs/core/src/compact_remote.rs +++ b/codex-rs/core/src/compact_remote.rs @@ -229,43 +229,38 @@ fn remove_incoming_echoes_from_compacted_history( incoming_history_items: &[ResponseItem], ) { for incoming_item in incoming_history_items { - if let Some(index) = new_history.iter().rposition(|candidate| { - response_items_match_for_compaction_merge(candidate, incoming_item) - }) { + if let Some(index) = + new_history + .iter() + .rposition(|candidate| match (candidate, incoming_item) { + ( + ResponseItem::Message { + role: candidate_role, + content: candidate_content, + .. + }, + ResponseItem::Message { + role: incoming_role, + content: incoming_content, + .. + }, + ) => candidate_role == incoming_role && candidate_content == incoming_content, + ( + ResponseItem::Compaction { + encrypted_content: candidate_content, + }, + ResponseItem::Compaction { + encrypted_content: incoming_content, + }, + ) => candidate_content == incoming_content, + _ => candidate == incoming_item, + }) + { new_history.remove(index); } } } -fn response_items_match_for_compaction_merge( - candidate: &ResponseItem, - incoming_item: &ResponseItem, -) -> bool { - match (candidate, incoming_item) { - ( - ResponseItem::Message { - role: candidate_role, - content: candidate_content, - .. - }, - ResponseItem::Message { - role: incoming_role, - content: incoming_content, - .. - }, - ) => candidate_role == incoming_role && candidate_content == incoming_content, - ( - ResponseItem::Compaction { - encrypted_content: candidate_content, - }, - ResponseItem::Compaction { - encrypted_content: incoming_content, - }, - ) => candidate_content == incoming_content, - _ => candidate == incoming_item, - } -} - fn log_remote_compact_failure( turn_context: &TurnContext, auto_compact_callsite: AutoCompactCallsite,