Problem
Automatic context compression can currently commit a destructive compaction even when the LLM summary could not be generated. In that failure mode, the compressor inserts a static "summary unavailable" marker and drops the middle turns anyway.
That is unsafe for long-running conversations: the visible transcript may still look recoverable, but the model-facing context can lose recent work while retaining an old protected head. This can make the agent drift back to stale topics after auto-compaction.
Expected behavior
If summary generation fails, compression should not discard the middle turns. The compressor should record the failure so callers can surface a warning, but it should leave the original context intact.
Proposed fix
- Return the original message list when summary generation returns no summary.
- Keep
_last_summary_fallback_used, _last_summary_dropped_count, and _last_summary_error populated so UI/gateway callers can warn the user.
- Do not increment
compression_count on failed compression.
- Update tests that previously expected static fallback truncation.
Verification
A focused regression PR will include tests covering the failed-summary path and related compressor/gateway compression paths.
Problem
Automatic context compression can currently commit a destructive compaction even when the LLM summary could not be generated. In that failure mode, the compressor inserts a static "summary unavailable" marker and drops the middle turns anyway.
That is unsafe for long-running conversations: the visible transcript may still look recoverable, but the model-facing context can lose recent work while retaining an old protected head. This can make the agent drift back to stale topics after auto-compaction.
Expected behavior
If summary generation fails, compression should not discard the middle turns. The compressor should record the failure so callers can surface a warning, but it should leave the original context intact.
Proposed fix
_last_summary_fallback_used,_last_summary_dropped_count, and_last_summary_errorpopulated so UI/gateway callers can warn the user.compression_counton failed compression.Verification
A focused regression PR will include tests covering the failed-summary path and related compressor/gateway compression paths.