The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(compression): one effective-cap helper; drop dead _config_threshold_percent fallback
kshitijk4poor94e8a255df55
diff --git a/agent/context_compressor.py b/agent/context_compressor.pyindex 707d571e396..f711b6291c3 100644--- a/agent/context_compressor.py+++ b/agent/context_compressor.py@@ -2499,14 +2499,19 @@ class ContextCompressor(SummaryDispatchMixin, MicroCompactionMixin, ContextEngintrigger math lives, shared by ``update_model`` and the switch guard's preview so the number theguard quotes is the number the compressor installs (#83450). Excludes the auxiliary-summariserceiling, which the feasibility probe re-derives per runtime."""- config_percent = getattr(self, "_config_threshold_percent", self.threshold_percent)- base_percent = resolve_model_threshold(model, self.model_thresholds, config_percent, provider)+ base_percent = resolve_model_threshold(model, self.model_thresholds, self._config_threshold_percent, provider)effective_percent = self._effective_threshold_percent(context_length, base_percent)threshold = self._compute_threshold_tokens(context_length, effective_percent, self.max_tokens)- if self.threshold_tokens_cap is not None and self.threshold_tokens_cap > 0:- threshold = min(threshold, self.threshold_tokens_cap, context_length)+ cap = self._effective_threshold_cap(context_length)+ if cap is not None:+ threshold = min(threshold, cap)return base_percent, effective_percent, threshold+ def _effective_threshold_cap(self, context_length: int) -> int | None:+ """The configured ``threshold_tokens`` cap clamped to the window; None when no cap is configured."""+ cap = self.threshold_tokens_cap+ return min(cap, context_length) if cap is not None and cap > 0 else None+def preview_threshold_tokens(self, model: str, context_length: int, provider: str = "") -> int:"""The trigger ``update_model`` would install, without mutating state."""return self._derive_trigger(model, context_length, provider)[2]@@ -2581,10 +2586,9 @@ class ContextCompressor(SummaryDispatchMixin, MicroCompactionMixin, ContextEngindef _apply_threshold_tokens_cap(self) -> None:"""Clamp threshold_tokens to the configured cap (itself clamped to the context length) and to theauxiliary summariser's window when the feasibility probe installed one."""- if self.threshold_tokens_cap is not None and self.threshold_tokens_cap > 0:- _effective_cap = min(self.threshold_tokens_cap, self.context_length)- if _effective_cap < self.threshold_tokens:- self.threshold_tokens = _effective_cap+ cap = self._effective_threshold_cap(self.context_length)+ if cap is not None and cap < self.threshold_tokens:+ self.threshold_tokens = cap# Durable, so every recomputation honours it rather than a one-time assignment (#114707)._aux_ceiling = getattr(self, "_aux_context_ceiling", None)if isinstance(_aux_ceiling, int) and 0 < _aux_ceiling < self.threshold_tokens: