Skip to content

The agent that grows with you

refactor(compression): startup banner uses _effective_threshold_cap; trim comments and tests

kshitijk4poor71a2fe399bbd
diff --git a/agent/agent_init.py b/agent/agent_init.py
index 99f97e4ac49..4d2bb6c993f 100644
--- a/agent/agent_init.py
+++ b/agent/agent_init.py
@@ -1482,9 +1482,8 @@ def _parse_compression_config(agent, _agent_cfg) -> CompressionSettings:
max_attempts = _parse_config_int(cfg.get("max_attempts", 3), 3)
if max_attempts < 1:
max_attempts = 3
- # threshold_tokens: absolute cap (lower of ratio threshold and this); clamped to the
- # window at apply-time. Absent β†’ the shipped default (the merged config always carries it; only a
- # failed config load hands us `{}`); an explicit null is the ratio-only opt-out and stays None.
+ # threshold_tokens: absolute cap (lower of ratio threshold and this); clamped to the window at
+ # apply-time. Explicit null is the ratio-only opt-out and stays None.
threshold_tokens = cfg.get("threshold_tokens", cfg_get(DEFAULT_CONFIG, "compression", "threshold_tokens"))
if threshold_tokens is not None:
threshold_tokens = _positive_int(threshold_tokens)
@@ -2195,7 +2194,8 @@ def _emit_compression_summary(agent, cs):
_pct = getattr(_cc, "threshold_percent", cs.threshold)
_cap = getattr(_cc, "threshold_tokens_cap", None)
# Name the cap only when it is what set the trigger; on small windows the ratio already sits below it.
- _cap_binds = bool(_cap) and _cap > 0 and _cc.threshold_tokens == min(_cap, _cc.context_length)
+ _eff_cap = getattr(_cc, "_effective_threshold_cap", lambda _ctx: None)(_cc.context_length)
+ _cap_binds = _eff_cap is not None and _cc.threshold_tokens == _eff_cap
_cap_note = f" (capped at {_cap:,} tokens)" if _cap_binds else ""
print(f"πŸ“Š Context limit: {_cc.context_length:,} tokens (compress at {int(_pct*100)}% = {_cc.threshold_tokens:,}{_cap_note})")
else:
diff --git a/tests/agent/test_compression_config_defaults.py b/tests/agent/test_compression_config_defaults.py
index 9711d7a923a..140842e63fa 100644
--- a/tests/agent/test_compression_config_defaults.py
+++ b/tests/agent/test_compression_config_defaults.py
@@ -1,7 +1,5 @@
-"""``_parse_compression_config`` promises "Defaults here MUST match DEFAULT_CONFIG" β€” the config-load
-failure path hands it ``{}`` and every key falls back inline. Regression for the one key that did not:
-``threshold_tokens`` fell to None (no cap) while ``threshold`` kept 0.50, so a broken config.yaml
-silently restored the pre-#115986 500K trigger on 1M-window models."""
+"""A failed config load hands ``_parse_compression_config`` ``{}``; every key must fall back to
+DEFAULT_CONFIG, and an explicit ``threshold_tokens: null`` must stay the ratio-only opt-out."""
from types import SimpleNamespace
@@ -16,13 +14,13 @@ def _agent():
@pytest.mark.parametrize(
- ("section", "expected"),
+ ("agent_cfg", "expected"),
[
- ({}, DEFAULT_CONFIG["compression"]["threshold_tokens"]), # absent β†’ shipped default
- ({"threshold_tokens": None}, None), # explicit null β†’ ratio-only opt-out
+ ({}, DEFAULT_CONFIG["compression"]["threshold_tokens"]), # config-load failure β†’ shipped default
+ ({"compression": {"threshold_tokens": None}}, None), # explicit null β†’ ratio-only opt-out
],
)
-def test_absent_threshold_tokens_falls_back_like_every_other_key(section, expected):
- cs = _parse_compression_config(_agent(), {"compression": section} if section else {})
+def test_threshold_tokens_default_and_null_opt_out(agent_cfg, expected):
+ cs = _parse_compression_config(_agent(), agent_cfg)
assert cs.threshold_tokens == expected
assert cs.threshold == DEFAULT_CONFIG["compression"]["threshold"]