fix(compression): resolve missing config attribute in feasibility check

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`.
This commit is contained in:
kshitijk4poor 2026-04-18 16:00:45 +05:30 committed by kshitij
parent 6af04474a3
commit 045b28733e
2 changed files with 5 additions and 4 deletions

View file

@ -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:

View file

@ -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",