Bug Description
The context compression system fails when attempting to generate summaries, resulting in warnings like:
WARNING: Failed to generate context summary: Expecting value: line 631 column 1 (char 3465)
WARNING: Failed to generate context summary: Expecting value: line 823 column 1 (char 4521)
This issue occurs when the auxiliary LLM provider returns a non-JSON response (plain text, HTML error page, or malformed JSON) instead of a valid JSON response. The OpenAI-compatible client attempts to parse the response as JSON, raising a json.JSONDecodeError that propagates to the _generate_summary method.
Steps to Reproduce
- Configure an auxiliary model that may return non-JSON responses (e.g., misconfigured endpoint, rate-limited provider, or provider returning HTML error pages)
- Run a conversation long enough to trigger context compression
- Observe the warning messages in the logs
- Note that the compression fails and middle conversation turns are dropped without a summary
Expected Behavior
- Context compression should succeed by falling back to the main model when the auxiliary model returns invalid JSON
- The system should log detailed diagnostics about the error
- The agent should preserve as much conversational context as possible
- No data loss should occur due to compression failures
Actual Behavior
- Context compression fails completely
- The system enters a 60-second cooldown period
- Middle conversation turns are dropped without a summary
- No detailed diagnostics are logged about the provider or error position
- The agent loses conversational context
Affected Component
Agent Core (conversation loop, context compression, memory)
Messaging Platform (if gateway-related)
No response
Debug Report
Debug report uploaded:
Report https://paste.rs/qeLV4
agent.log https://dpaste.com/3UXBRZUPF
gateway.log https://dpaste.com/2KX4JLVCZ
Operating System
macOs 26.3.1
Python Version
3.14.3
Hermes Version
0.13.0
Additional Logs / Traceback (optional)
Root Cause Analysis (optional)
The root cause is that the _generate_summary method in agent/context_compressor.py did not explicitly handle json.JSONDecodeError exceptions. When the auxiliary LLM provider returns a non-JSON response, the JSON parsing fails, but the existing error handling only covered:
- Model not found errors (404, 503)
- Timeout errors
- Transient errors (rate limits, network issues)
The JSON decode error was caught by the generic except Exception block, which:
- Did not log provider details or error position
- Did not attempt fallback to the main model
- Entered a 60-second cooldown period
- Returned
None, causing the middle turns to be dropped
This resulted in context compression failures and potential data loss when providers returned invalid responses.
Proposed Fix (optional)
No response
Are you willing to submit a PR for this?
Bug Description
The context compression system fails when attempting to generate summaries, resulting in warnings like:
This issue occurs when the auxiliary LLM provider returns a non-JSON response (plain text, HTML error page, or malformed JSON) instead of a valid JSON response. The OpenAI-compatible client attempts to parse the response as JSON, raising a
json.JSONDecodeErrorthat propagates to the_generate_summarymethod.Steps to Reproduce
Expected Behavior
Actual Behavior
Affected Component
Agent Core (conversation loop, context compression, memory)
Messaging Platform (if gateway-related)
No response
Debug Report
Operating System
macOs 26.3.1
Python Version
3.14.3
Hermes Version
0.13.0
Additional Logs / Traceback (optional)
Root Cause Analysis (optional)
The root cause is that the
_generate_summarymethod inagent/context_compressor.pydid not explicitly handlejson.JSONDecodeErrorexceptions. When the auxiliary LLM provider returns a non-JSON response, the JSON parsing fails, but the existing error handling only covered:The JSON decode error was caught by the generic
except Exceptionblock, which:None, causing the middle turns to be droppedThis resulted in context compression failures and potential data loss when providers returned invalid responses.
Proposed Fix (optional)
No response
Are you willing to submit a PR for this?