From 5a3ee3c537b3226fed21ccc733314d775266b2d2 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 22 Jul 2026 07:26:41 -0700 Subject: [PATCH] fix(compression): let handoff-strip supersede the head-copy skip The summary_idx head-copy skip (from #69302) dropped the entire merged handoff message, deleting the genuine prior-tail user content that #47274's _strip_context_summary_handoff_message correctly unwraps. Strip handles both shapes: standalone handoffs drop, merged handoffs keep their real content. Caught by test_recompression_of_current_merged_handoff_preserves_prior_tail_once when both PRs landed together. --- agent/context_compressor.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/agent/context_compressor.py b/agent/context_compressor.py index 8b5e983e6e3..feed9d3aab2 100644 --- a/agent/context_compressor.py +++ b/agent/context_compressor.py @@ -4040,19 +4040,15 @@ This compaction should PRIORITISE preserving all information related to the focu # Phase 4: Assemble compressed message list compressed = [] for i in range(compress_start): - # If an earlier compaction handoff is in the protected head - # (common after resume / in-place compaction), do not carry it - # forward verbatim. It has already been rehydrated into - # _previous_summary above and _generate_summary() will emit the - # updated replacement below. Keeping both makes repeated - # compactions accumulate old summaries and prevents the live prompt - # from actually shrinking. - if ( - summary_idx is not None - and i == summary_idx - and self._is_context_summary_content(messages[i].get("content")) - ): - continue + # An earlier compaction handoff in the protected head (common + # after resume / in-place compaction) must not be carried forward + # verbatim — it is already rehydrated into _previous_summary and + # _generate_summary() emits the updated replacement below. + # _strip_context_summary_handoff_message() handles both shapes: + # standalone handoffs strip to None (dropped), merged handoffs + # unwrap to their genuine prior-tail content (preserved). Do NOT + # short-circuit on summary_idx here: a merged handoff carries real + # user content that a blanket skip would silently delete. msg = _fresh_compaction_message_copy(messages[i]) if i == 0 and msg.get("role") == "system": existing = msg.get("content")