From d0d116be2e038a57cf5ec34979c767f1f8d1fbc4 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 23 Jul 2026 13:10:02 -0700 Subject: [PATCH] fix: getattr-guard min_tail_user_messages for __new__ test doubles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bare ContextCompressor.__new__ doubles (test_compress_focus, cross_session_guard, image_tokens, pre_compress_memory_context) skip __init__ and lack the attribute — the documented compression-path test-double pitfall. Guard with getattr default 1 + int type pin (bool excluded). --- agent/context_compressor.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/agent/context_compressor.py b/agent/context_compressor.py index 249678f5745..65684ced454 100644 --- a/agent/context_compressor.py +++ b/agent/context_compressor.py @@ -4751,9 +4751,13 @@ This compaction should PRIORITISE preserving all information related to the focu # single-anchor pipeline — the single-user anchor already ran above, # and re-invoking it here could re-trigger the causal-coupling # forward push (#22523) after the assistant anchor adjusted the cut. - if self.min_tail_user_messages > 1: + # getattr-guarded: bare ``ContextCompressor.__new__`` test doubles + # (and plugin engines) skip __init__, so the attribute may be absent + # (see the compression-path test-double pitfall). + _min_tail_users = getattr(self, "min_tail_user_messages", 1) + if isinstance(_min_tail_users, int) and not isinstance(_min_tail_users, bool) and _min_tail_users > 1: cut_idx = self._ensure_last_n_user_messages_in_tail( - messages, cut_idx, head_end, self.min_tail_user_messages, + messages, cut_idx, head_end, _min_tail_users, ) # The floor guarantees forward progress — compression must always claim