The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(compressor): pin custom_providers threading at the get_model_context_length seam
kshitijk4poored063034ad74
diff --git a/agent/context_compressor.py b/agent/context_compressor.pyindex eb1a314cc1f..6ce48ffcdf5 100644--- a/agent/context_compressor.py+++ b/agent/context_compressor.py@@ -2270,9 +2270,9 @@ class ContextCompressor(SummaryDispatchMixin, MicroCompactionMixin, ContextEnginself.model, self.base_url, self.api_key, self.provider, self.api_mode = model, base_url, api_key, provider, api_mode# "lean" = small clamped tail + verbatim-user summary section; "legacy" = 0.20*window tail.self.tail_mode = tail_mode if tail_mode in ("legacy", "lean") else "lean"- # Per-model context_length overrides live in custom_providers; without them the deferred- # resolution below falls back to the hardcoded family catalog (#83324).- self.custom_providers = list(custom_providers) if custom_providers else None+ # Per-model context_length overrides live in custom_providers; without them deferred+ # resolution falls back to the hardcoded family catalog (#83324).+ self.custom_providers = custom_providers or None# Per-model overrides (longest substring match wins); floor applied on top.self.model_thresholds = model_thresholds or {}# Raw config value, before override/floor; fallback when switching to a model with no override.diff --git a/tests/agent/test_context_compressor_custom_providers.py b/tests/agent/test_context_compressor_custom_providers.pynew file mode 100644index 00000000000..7110ddadd46--- /dev/null+++ b/tests/agent/test_context_compressor_custom_providers.py@@ -0,0 +1,21 @@+"""Per-model ``context_length`` overrides from custom_providers reach the compressor's deferred resolution (#83324)."""++from unittest.mock import patch++from agent.context_compressor import ContextCompressor+++def test_compressor_threads_custom_providers_into_context_length_resolution():+ providers = [{"name": "p1", "models": {"m": {"context_length": 99999}}}]+ captured = {}++ def fake_resolve(model, **kwargs):+ captured.update(kwargs)+ return 99999++ with patch("agent.context_compressor.get_model_context_length", side_effect=fake_resolve):+ comp = ContextCompressor(model="m", base_url="https://x.example.com/v1", api_key="k", provider="custom",+ custom_providers=providers)+ assert comp.context_length == 99999++ assert captured["custom_providers"] == providersdiff --git a/tests/test_compressor_custom_providers.py b/tests/test_compressor_custom_providers.pydeleted file mode 100644index 9a04177b269..00000000000--- a/tests/test_compressor_custom_providers.py+++ /dev/null@@ -1,62 +0,0 @@-"""Regression tests for custom_providers context-length threading (#83324)."""--from agent.context_compressor import ContextCompressor-from agent.model_metadata import get_model_context_length---def test_custom_providers_override_wins_over_catalog(monkeypatch, tmp_path):- """A per-model context_length in custom_providers must beat the hardcoded- catalog default for the same model (the #15779 / #83324 gap)."""- providers = [- {- "name": "myproxy",- "base_url": "https://proxy.example.com/v1",- "api_key": "sk-test",- "models": [- {"model": "kimi-k2", "context_length": 262144},- ],- }- ]- ctx = get_model_context_length(- "kimi-k2",- base_url="https://proxy.example.com/v1",- api_key="sk-test",- provider="custom",- custom_providers=providers,- )- assert ctx == 262144---def test_compressor_threads_custom_providers(tmp_path, monkeypatch):- """ContextCompressor must pass its custom_providers snapshot into- _resolve_context_length so per-model overrides apply."""- captured = {}-- def fake_resolve(self):- from agent import model_metadata-- captured["custom_providers"] = self.custom_providers- self._resolved_context_length = model_metadata.get_model_context_length(- self.model,- base_url=self.base_url,- api_key=self.api_key,- config_context_length=self._config_context_length,- provider=self.provider,- custom_providers=self.custom_providers,- )- return self._resolved_context_length-- monkeypatch.setattr(ContextCompressor, "_resolve_context_length", fake_resolve)-- providers = [{"name": "p1"}]- comp = ContextCompressor(- model="m",- base_url="https://x.example.com/v1",- api_key="k",- provider="custom",- custom_providers=providers,- )- # Caller mutates the list after construction — compressor view must not change.- providers.append({"name": "p2"})- comp.context_length- assert captured["custom_providers"] == [{"name": "p1"}]