fix: getattr-guard min_tail_user_messages for __new__ test doubles

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).
This commit is contained in:
Teknium 2026-07-23 13:10:02 -07:00
parent d43cc2ca80
commit d0d116be2e

View file

@ -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