From 292d12bed42ee3747b33bf32d828c953917890b2 Mon Sep 17 00:00:00 2001 From: Teknium Date: Sat, 21 Mar 2026 10:47:44 -0700 Subject: [PATCH] fix: case-insensitive model family matching + compressor init logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two fixes for local model context detection: 1. Hardcoded DEFAULT_CONTEXT_LENGTHS matching was case-sensitive. 'qwen' didn't match 'Qwen3.5-9B-Q4_K_M.gguf' because of the capital Q. Now uses model.lower() for comparison. 2. Added compressor initialization logging showing the detected context_length, threshold, model, provider, and base_url. This makes turn-1 compression bugs diagnosable from logs — previously there was no log of what context length was detected. --- agent/context_compressor.py | 8 ++++++++ agent/model_metadata.py | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/agent/context_compressor.py b/agent/context_compressor.py index d81de947..5f4ea4a3 100644 --- a/agent/context_compressor.py +++ b/agent/context_compressor.py @@ -93,6 +93,14 @@ class ContextCompressor: ) self.threshold_tokens = int(self.context_length * threshold_percent) self.compression_count = 0 + + if not quiet_mode: + logger.info( + "Context compressor initialized: model=%s context_length=%d " + "threshold=%d (%.0f%%) provider=%s base_url=%s", + model, self.context_length, self.threshold_tokens, + threshold_percent * 100, provider or "none", base_url or "none", + ) self._context_probed = False # True after a step-down from context error self.last_prompt_tokens = 0 diff --git a/agent/model_metadata.py b/agent/model_metadata.py index e3636b6f..ca651fce 100644 --- a/agent/model_metadata.py +++ b/agent/model_metadata.py @@ -855,10 +855,11 @@ def get_model_context_length( # Only check `default_model in model` (is the key a substring of the input). # The reverse (`model in default_model`) causes shorter names like # "claude-sonnet-4" to incorrectly match "claude-sonnet-4-6" and return 1M. + model_lower = model.lower() for default_model, length in sorted( DEFAULT_CONTEXT_LENGTHS.items(), key=lambda x: len(x[0]), reverse=True ): - if default_model in model: + if default_model in model_lower: return length # 9. Query local server as last resort