From b781a15a42235571d20876c40c8ca32ce000355f Mon Sep 17 00:00:00 2001 From: Charles Cunningham Date: Tue, 17 Feb 2026 19:35:22 -0800 Subject: [PATCH] Keep only user+compaction items in compacted history --- codex-rs/core/src/compact.rs | 1 + codex-rs/core/tests/suite/compact.rs | 5 ----- codex-rs/core/tests/suite/compact_remote.rs | 6 +++++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/codex-rs/core/src/compact.rs b/codex-rs/core/src/compact.rs index 4b18c9de2c..da2a664b3b 100644 --- a/codex-rs/core/src/compact.rs +++ b/codex-rs/core/src/compact.rs @@ -485,6 +485,7 @@ fn should_keep_compacted_history_item(item: &ResponseItem) -> bool { Some(TurnItem::UserMessage(_)) ) } + // Keep compaction records for local/remote history continuity and token accounting. ResponseItem::Compaction { .. } => true, ResponseItem::Reasoning { .. } | ResponseItem::LocalShellCall { .. } diff --git a/codex-rs/core/tests/suite/compact.rs b/codex-rs/core/tests/suite/compact.rs index 17066c3c92..d7051dc245 100644 --- a/codex-rs/core/tests/suite/compact.rs +++ b/codex-rs/core/tests/suite/compact.rs @@ -2961,11 +2961,6 @@ async fn auto_compact_counts_encrypted_reasoning_before_last_user() { "second turn should not include compacted history" ); let third_request_body = requests[2].body_json().to_string(); - assert!( - third_request_body.contains("REMOTE_COMPACT_SUMMARY") - || third_request_body.contains(FINAL_REPLY), - "third turn should include compacted history" - ); assert!( third_request_body.contains("ENCRYPTED_COMPACTION_SUMMARY"), "third turn should include compaction summary item" diff --git a/codex-rs/core/tests/suite/compact_remote.rs b/codex-rs/core/tests/suite/compact_remote.rs index c815adcf76..eab0b6c522 100644 --- a/codex-rs/core/tests/suite/compact_remote.rs +++ b/codex-rs/core/tests/suite/compact_remote.rs @@ -1051,11 +1051,15 @@ async fn remote_compact_persists_replacement_history_in_rollout() -> Result<()> ) }); - if has_compacted_user_summary && has_compaction_item && has_compacted_assistant_note { + if has_compacted_user_summary && has_compaction_item { assert!( !has_permissions_developer_message, "manual remote compact rollout replacement history should not inject permissions context" ); + assert!( + !has_compacted_assistant_note, + "manual remote compact rollout replacement history should drop assistant notes" + ); saw_compacted_history = true; break; }