From 97cd0d98f16fea173d4fb496ffd012de9288e1b0 Mon Sep 17 00:00:00 2001 From: John Lussier Date: Sat, 11 Jul 2026 10:13:34 -0700 Subject: [PATCH] test(compression): cover leading and input-text blanks --- agent/context_compressor.py | 4 +++- .../test_compressor_actionable_tail_anchor.py | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/agent/context_compressor.py b/agent/context_compressor.py index ed6de9cdd3fe..393f53e2946a 100644 --- a/agent/context_compressor.py +++ b/agent/context_compressor.py @@ -2880,7 +2880,7 @@ This compaction should PRIORITISE preserving all information related to the focu if part.strip(): return False continue - if isinstance(part, dict) and part.get("type") == "text": + if isinstance(part, dict) and part.get("type") in {"text", "input_text"}: text = part.get("text") if isinstance(text, str) and not text.strip(): continue @@ -2911,6 +2911,8 @@ This compaction should PRIORITISE preserving all information related to the focu placeholder for a transcript still being assembled. """ indices: set[int] = set() + if user_idx < 0: + return indices idx = user_idx + 1 while idx < len(messages) and cls._is_blank_user_turn(messages[idx]): indices.add(idx) diff --git a/tests/agent/test_compressor_actionable_tail_anchor.py b/tests/agent/test_compressor_actionable_tail_anchor.py index a2dc74b5c60e..bcbc21433e8b 100644 --- a/tests/agent/test_compressor_actionable_tail_anchor.py +++ b/tests/agent/test_compressor_actionable_tail_anchor.py @@ -70,7 +70,14 @@ def _assert_no_adjacent_user_roles(messages: list[dict]) -> None: @pytest.mark.parametrize( "blank", - ["", " \n\t", None, [], [{"type": "text", "text": " "}]], + [ + "", + " \n\t", + None, + [], + [{"type": "text", "text": " "}], + [{"type": "input_text", "text": " "}], + ], ) def test_blank_echo_does_not_displace_async_completion(compressor, blank): completion = "[ASYNC DELEGATION BATCH COMPLETE — deleg_current]\nnew result" @@ -86,6 +93,16 @@ def test_blank_echo_does_not_displace_async_completion(compressor, blank): assert compressor._find_last_user_message_idx(messages, head_end=1) == 3 +def test_leading_blank_without_actionable_user_is_not_removed(compressor): + messages = [ + {"role": "user", "content": ""}, + {"role": "assistant", "content": "visible reply"}, + ] + + assert compressor._find_last_user_message_idx(messages, 0) == -1 + assert compressor._blank_echo_indices_after(messages, -1) == set() + + def test_image_only_user_turn_survives_compaction(compressor): image_content = [ {