From 52e6a54a6d8c4834669adac5f7ccec1e0bf9cc08 Mon Sep 17 00:00:00 2001 From: Charles Cunningham Date: Tue, 17 Feb 2026 19:03:04 -0800 Subject: [PATCH] Define real user predicate independent of keep policy --- codex-rs/core/src/compact.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/codex-rs/core/src/compact.rs b/codex-rs/core/src/compact.rs index 618794586d..31203ba37b 100644 --- a/codex-rs/core/src/compact.rs +++ b/codex-rs/core/src/compact.rs @@ -308,17 +308,7 @@ async fn run_compact_task_inner( // TODO(ccunningham): Truncate user shell-command records before preserving them // in incoming compaction items so they cannot cause repeated context-window // overflows across pre-turn compaction attempts. - (should_keep_compacted_history_item(item) - || matches!( - item, - ResponseItem::Message { role, content, .. } - if role == "user" - && matches!( - content.as_slice(), - [ContentItem::InputText { text }] - if is_user_shell_command_text(text) - ) - )) + (should_keep_compacted_history_item(item) || is_user_shell_command_record(item)) && !is_summary_user_message_item(item) }) .cloned() @@ -449,7 +439,10 @@ pub(crate) fn process_compacted_history( } fn is_real_user_message(item: &ResponseItem) -> bool { - should_keep_compacted_history_item(item) && !is_summary_user_message_item(item) + matches!( + crate::event_mapping::parse_turn_item(item), + Some(TurnItem::UserMessage(user_message)) if !is_summary_message(&user_message.message()) + ) } fn is_summary_user_message_item(item: &ResponseItem) -> bool { @@ -459,6 +452,18 @@ fn is_summary_user_message_item(item: &ResponseItem) -> bool { ) } +fn is_user_shell_command_record(item: &ResponseItem) -> bool { + matches!( + item, + ResponseItem::Message { role, content, .. } + if role == "user" + && matches!( + content.as_slice(), + [ContentItem::InputText { text }] if is_user_shell_command_text(text) + ) + ) +} + /// Returns whether an item from remote compaction output should be preserved. /// /// Called while processing the model-provided compacted transcript, before we @@ -481,6 +486,9 @@ fn should_keep_compacted_history_item(item: &ResponseItem) -> bool { if role != "user" { return true; } + if is_user_shell_command_record(item) { + return false; + } matches!( crate::event_mapping::parse_turn_item(item),