Define real user predicate independent of keep policy

This commit is contained in:
Charles Cunningham
2026-02-17 19:03:04 -08:00
parent d53b588309
commit 52e6a54a6d
+20 -12
View File
@@ -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),