[BUG] /compact command fails with empty summary from API

Resolved 💬 3 comments Opened Nov 6, 2025 by pinion05 Closed Nov 9, 2025

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

The /compact command completely fails and throws an error when the AI API fails to generate a valid summary from the conversation context. This happens consistently when using the minimax m2 model
via https://api.minimax.io/anthropic**, especially with long conversations (60K+ tokens) where the summarization API response is empty, null, or contains insufficient text content.

Error Message:
``
Failed to generate conversation summary - response did not contain valid text content
``

This causes the compaction process to abort completely, preventing users from compacting their conversations and continuing their work.

Related Issues:
This appears similar to issue #820, where /compact failures occurred under specific model configurations.

What Should Happen?

The /compact command should gracefully handle cases where the API returns empty or invalid summary content. Instead of failing completely, it should:

  1. Continue with a fallback summary that includes basic information (token count, context summary)
  2. Preserve the session state and allow users to continue working
  3. Log the incident but not interrupt the workflow

Error Messages/Logs

Error: Failed to generate conversation summary - response did not contain valid text content at kpA (/path/to/cli.js:1616)


Event Logged: `tengu_compact_failed` with reason: "no_summary"

Steps to Reproduce

  1. Configure Claude Code to use minimax m2 model via https://api.minimax.io/anthropic
  2. Engage in a conversation that reaches the long context threshold (60,000+ tokens)
  3. User runs the /compact command
  4. The summarization API fails to generate valid text content (likely due to context complexity)
  5. The Xm() function returns null because the response is empty or too short
  6. Error is thrown and compaction fails

Claude Model

Other

Is this a regression?

No, this never worked

Last Working Version

_No response_

Claude Code Version

2.0.33

Platform

Other

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Windows Terminal

Additional Information

This bug occurs in the kpA() function (conversation compaction) at line ~1616 in cli.js. When the API response for summarization is empty or contains less than 10 characters of valid text, the Xm()
function returns null.

Previous Code (Broken):
``javascript
let N = Xm(U);
if(!N) throw Error("Failed to generate conversation summary - response did not contain valid text content");
``

Proposed Fix:
``javascript
let N = Xm(U);
if(!N || (N.trim && N.trim().length < 10)) {
N = N || "Conversation summary: User and assistant exchanged messages. Total context: ~" + Z + " tokens. Key topics discussed and solutions explored.";
} else if(N.startsWith(sX))
``

This bug appears to occur due to insufficient coverage for special models like m2 where max output token length and context window length are the same. Such models may struggle with generating
summaries for very long conversations, leading to:

  • API responses with no text content
  • Partial/incomplete responses
  • Streaming interruptions
  • Content filtering issues

Why This Happens:
Long conversations (60K+ tokens) overwhelm the summarization process. Even with large context windows (200K+), the AI struggles to generate coherent summaries for very long inputs, especially models with
unique output constraints like minimax m2.

Test Results:

I have successfully applied this code change and am using it without any issues. The fix works as follows:

  • When API returns empty response, the hardcoded fallback summary is used instead, and /compact completes successfully
  • Compression proceeds without errors even in long conversations, maintaining the session
  • The fallback summary includes token count information, which is useful for debugging
  • It doesn't affect compatibility with other models and doesn't interfere with existing functionality

Impact of Fix:

  • Graceful degradation: Uses fallback summary instead of crashing
  • Better UX: Users can continue working even when API has issues
  • Context preservation: Token count and basic info retained
  • No breaking changes: Maintains backward compatibility

Recommended Improvements:
While the current fix provides graceful fallback, ideally we could add:

  1. Retry mechanism for failed summarization
  2. Progressive summarization (chunk-based)
  3. Quality scoring before accepting summary
  4. Special handling for models with unique token constraints

https://github.com/user-attachments/assets/dd979397-e587-4a5a-b186-0292324555ef

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗