Skip to content

test(compress): re-initialise main_runtime attrs in manually-built compressor - #10903

Closed
luigileap wants to merge 1 commit into
NousResearch:mainfrom
luigileap:fix/compress-focus-stubs-model-attrs
Closed

test(compress): re-initialise main_runtime attrs in manually-built compressor#10903
luigileap wants to merge 1 commit into
NousResearch:mainfrom
luigileap:fix/compress-focus-stubs-model-attrs

Conversation

@luigileap

Copy link
Copy Markdown

Problem

tests/agent/test_compress_focus.py::test_focus_topic_injected_into_summary_prompt
and test_no_focus_topic_no_injection fail with:

WARNING  root:context_compressor.py:477 Failed to generate context summary:
'ContextCompressor' object has no attribute 'model'.  Further summary
attempts paused for 600 seconds.

Both tests then report result is None / KeyError: 'messages' because
_generate_summary swallowed the AttributeError in its broad-except
cooldown path.

Root cause

_make_compressor in the test file builds a compressor with
ContextCompressor.__new__(ContextCompressor), bypassing __init__, and
explicitly sets only the attributes the method used to touch (token
budgets, protect counts, the previous-summary cache, etc.).

PR #7910 ("fix(agent): route compression aux through live session
runtime") added a main_runtime dict to the call_llm invocation inside
_generate_summary:

"main_runtime": {
    "model": self.model,
    "provider": self.provider,
    "base_url": self.base_url,
    "api_key": self.api_key,
    "api_mode": self.api_mode,
},

Production sets those attributes in __init__, but the test fixture —
which predates the runtime-aware change — never did. Accessing
self.model raises AttributeError, which the method catches and
converts into a 10-minute cooldown + None return.

Fix

Extend _make_compressor to set the five runtime attributes
(model, provider, base_url, api_key, api_mode) so the fixture
matches the current production surface.

Verification

$ python -m pytest --override-ini="addopts=" -q tests/agent/test_compress_focus.py
....                                                                     [100%]
4 passed in 0.53s

All four tests in the module pass, including the previously failing two.

…mpressor

The `_make_compressor` helper uses `ContextCompressor.__new__` to bypass
`__init__`, so every attribute referenced by the method under test must
be set explicitly.

PR NousResearch#7910 (fix(agent): route compression aux through live session runtime)
added a `main_runtime` dict inside `_generate_summary` that reads
`self.model`, `self.provider`, `self.base_url`, `self.api_key`, and
`self.api_mode`.  The focus-topic regression test bypassed `__init__`,
so those attributes were missing and `_generate_summary` raised
`AttributeError: 'ContextCompressor' object has no attribute 'model'`,
making the test fail with `result is None` (the method returned None
via its broad-exception cooldown path) and `KeyError: 'messages'` on
the captured-prompt assertion.

Initialise the attributes in `_make_compressor` so the test exercises
the real code path.  Same pattern as the prior CLI-interrupt fix that
added missing attributes for a `SomeClass.__new__(SomeClass)` stub.
@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Already fixed on main via #9483 (commit 2558d28). The compressor fixture attributes are now set. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants