From 045b28733e09ba4c349f77675eafafab5bbeff60 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 18 Apr 2026 16:00:45 +0530 Subject: [PATCH] fix(compression): resolve missing config attribute in feasibility check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 4a9c3565 added a reference to `self.config` in `_check_compression_model_feasibility()` to pass the user-configured `auxiliary.compression.context_length` to `get_model_context_length()`. However, `AIAgent` never stores the loaded config dict as an instance attribute — the config is loaded into a local variable `_agent_cfg` in `__init__()` and discarded after init. This causes an `AttributeError: 'AIAgent' object has no attribute 'config'` on every session start when compression is enabled, caught by the try/except and logged as a non-fatal DEBUG message. Fix: store the loaded config as `self._config` in `__init__()` and update the reference in the feasibility check to use `self._config`. --- run_agent.py | 3 ++- tests/run_agent/test_compression_feasibility.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/run_agent.py b/run_agent.py index 8e1fbfed1..685b8372f 100644 --- a/run_agent.py +++ b/run_agent.py @@ -1271,6 +1271,7 @@ class AIAgent: _agent_cfg = _load_agent_config() except Exception: _agent_cfg = {} + self._config = _agent_cfg # stored for later use (e.g. compression feasibility check) # Persistent memory (MEMORY.md + USER.md) -- loaded from disk self._memory_store = None @@ -2003,7 +2004,7 @@ class AIAgent: # get_model_context_length() falls through to the 128K default, # ignoring the explicit config value. Pass it as the highest- # priority hint so the configured value is always respected. - _aux_cfg = (self.config or {}).get("auxiliary", {}).get("compression", {}) + _aux_cfg = (self._config or {}).get("auxiliary", {}).get("compression", {}) _aux_context_config = _aux_cfg.get("context_length") if isinstance(_aux_cfg, dict) else None if _aux_context_config is not None: try: diff --git a/tests/run_agent/test_compression_feasibility.py b/tests/run_agent/test_compression_feasibility.py index 0756fcda6..f0db50de4 100644 --- a/tests/run_agent/test_compression_feasibility.py +++ b/tests/run_agent/test_compression_feasibility.py @@ -38,7 +38,7 @@ def _make_agent( agent.status_callback = None agent.tool_progress_callback = None agent._compression_warning = None - agent.config = None + agent._config = None compressor = MagicMock(spec=ContextCompressor) compressor.context_length = main_context @@ -138,7 +138,7 @@ def test_feasibility_check_passes_config_context_length(mock_get_client, mock_ct get_model_context_length so custom endpoints that lack /models still report the correct context window (fixes #8499).""" agent = _make_agent(main_context=200_000, threshold_percent=0.85) - agent.config = { + agent._config = { "auxiliary": { "compression": { "context_length": 1_000_000, @@ -166,7 +166,7 @@ def test_feasibility_check_passes_config_context_length(mock_get_client, mock_ct def test_feasibility_check_ignores_invalid_context_length(mock_get_client, mock_ctx_len): """Non-integer context_length in config is silently ignored.""" agent = _make_agent(main_context=200_000, threshold_percent=0.50) - agent.config = { + agent._config = { "auxiliary": { "compression": { "context_length": "not-a-number",