mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-26 17:38:36 +00:00
fix(context): preserve missing-key compression history
This commit is contained in:
parent
202ad1b8c9
commit
577beeb9b9
8 changed files with 251 additions and 17 deletions
|
|
@ -854,11 +854,19 @@ class TestAuthFailureAborts:
|
|||
def test_quota_classifier_accepts_explicit_provider_signals(self, message):
|
||||
assert _is_summary_access_or_quota_error(Exception(message)) is True
|
||||
|
||||
def test_missing_provider_api_key_is_terminal_access_failure(self):
|
||||
err = RuntimeError(
|
||||
"Provider 'opencode-zen' is set in config.yaml but no API key was "
|
||||
"found. Set the OPENCODE-ZEN_API_KEY environment variable."
|
||||
)
|
||||
assert _is_summary_access_or_quota_error(err) is True
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"message",
|
||||
[
|
||||
"billing portal is temporarily unavailable",
|
||||
"usage limit documentation could not be loaded",
|
||||
"API key documentation was not found",
|
||||
"rate limit exceeded; retry later",
|
||||
"quota exceeded, please retry after the window resets",
|
||||
"request timed out",
|
||||
|
|
@ -905,6 +913,34 @@ class TestAuthFailureAborts:
|
|||
assert c._last_compress_aborted is True
|
||||
assert c._last_summary_fallback_used is False
|
||||
|
||||
def test_missing_provider_api_key_preserves_original_messages(self):
|
||||
"""A configured auxiliary provider without a visible key preserves context."""
|
||||
err = RuntimeError(
|
||||
"Provider 'opencode-zen' is set in config.yaml but no API key was "
|
||||
"found. Set the OPENCODE-ZEN_API_KEY environment variable, or switch "
|
||||
"to a different provider with hermes model."
|
||||
)
|
||||
with patch(
|
||||
"agent.context_compressor.get_model_context_length", return_value=100000
|
||||
):
|
||||
c = ContextCompressor(
|
||||
model="test",
|
||||
quiet_mode=True,
|
||||
protect_first_n=2,
|
||||
protect_last_n=2,
|
||||
abort_on_summary_failure=False,
|
||||
)
|
||||
msgs = self._msgs(12)
|
||||
with patch("agent.context_compressor.call_llm", side_effect=err):
|
||||
result = c.compress(msgs, current_tokens=999999, force=True)
|
||||
|
||||
assert result == msgs
|
||||
assert c._last_summary_error == str(err)
|
||||
assert c._last_summary_auth_failure is True
|
||||
assert c._last_compress_aborted is True
|
||||
assert c._last_summary_fallback_used is False
|
||||
assert c._last_summary_dropped_count == 0
|
||||
|
||||
def test_402_quota_with_retry_uses_existing_fallback(self):
|
||||
"""A reset-window quota remains transient instead of aborting compression."""
|
||||
err = StubProviderError(
|
||||
|
|
|
|||
62
tests/agent/test_manual_compression_feedback.py
Normal file
62
tests/agent/test_manual_compression_feedback.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
"""Behavioral coverage for manual compression status messages."""
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
from agent.manual_compression_feedback import summarize_manual_compression
|
||||
|
||||
|
||||
def _messages(count: int) -> list[dict[str, str]]:
|
||||
return [
|
||||
{"role": "user" if index % 2 == 0 else "assistant", "content": str(index)}
|
||||
for index in range(count)
|
||||
]
|
||||
|
||||
|
||||
def test_aborted_compression_reports_preserved_messages_and_reason():
|
||||
messages = _messages(12)
|
||||
state = SimpleNamespace(
|
||||
_last_compress_aborted=True,
|
||||
_last_summary_fallback_used=False,
|
||||
_last_summary_error=(
|
||||
"Provider 'opencode-zen' is set in config.yaml but no API key was found."
|
||||
),
|
||||
)
|
||||
|
||||
feedback = summarize_manual_compression(
|
||||
messages,
|
||||
list(messages),
|
||||
120_000,
|
||||
120_000,
|
||||
compression_state=state,
|
||||
)
|
||||
|
||||
assert feedback["aborted"] is True
|
||||
assert feedback["fallback_used"] is False
|
||||
assert feedback["headline"] == "Compression aborted: 12 messages preserved"
|
||||
assert "no messages were removed" in feedback["note"]
|
||||
assert "no API key was found" in feedback["note"]
|
||||
|
||||
|
||||
def test_fallback_compression_reports_dropped_message_count():
|
||||
before = _messages(12)
|
||||
after = before[:2] + before[-2:]
|
||||
state = SimpleNamespace(
|
||||
_last_compress_aborted=False,
|
||||
_last_summary_fallback_used=True,
|
||||
_last_summary_dropped_count=8,
|
||||
_last_summary_error="summary provider returned an invalid response",
|
||||
)
|
||||
|
||||
feedback = summarize_manual_compression(
|
||||
before,
|
||||
after,
|
||||
120_000,
|
||||
40_000,
|
||||
compression_state=state,
|
||||
)
|
||||
|
||||
assert feedback["aborted"] is False
|
||||
assert feedback["fallback_used"] is True
|
||||
assert feedback["headline"] == "Compressed with fallback: 12 → 4 messages"
|
||||
assert "removed 8 message(s)" in feedback["note"]
|
||||
assert "invalid response" in feedback["note"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue