vxcontrol/pentagi · error

summarization failed: %w

Error message

summarization failed: %w

What it means

GenerateSummary builds a text prompt from human/AI messages and delegates the actual summarization to a caller-supplied handler (typically an LLM call). If that handler returns an error it is wrapped as "summarization failed: %w". The error means the summarization backend (LLM provider) failed — rate limit, timeout, auth, or context-too-long — not that the chain-summary logic itself is wrong.

Source

Thrown at backend/pkg/csum/chain_summary.go:802

	handler tools.SummarizeHandler,
	humanMessages []llms.MessageContent,
	aiMessages []llms.MessageContent,
) (string, error) {
	if handler == nil {
		return "", fmt.Errorf("summarizer handler cannot be nil")
	}

	if len(humanMessages) == 0 && len(aiMessages) == 0 {
		return "", fmt.Errorf("cannot summarize empty message list")
	}

	// Convert messages to text format optimized for summarization
	text := messagesToPrompt(humanMessages, aiMessages)

	// Generate the summary using provided summarizer handler
	summary, err := handler(ctx, text)
	if err != nil {
		return "", fmt.Errorf("summarization failed: %w", err)
	}

	return summary, nil
}

// messagesToPrompt converts a slice of messages to a text representation
func messagesToPrompt(humanMessages []llms.MessageContent, aiMessages []llms.MessageContent) string {
	var buffer strings.Builder

	humanMessagesText := humanMessagesToText(humanMessages)
	aiMessagesText := aiMessagesToText(aiMessages)

	// case 0: no messages
	if len(humanMessages) == 0 && len(aiMessages) == 0 {
		return "nothing to summarize"
	}

	// case 1: use human messages as a context for ai messages

View on GitHub (pinned to ea665308ba)

Solutions

  1. Unwrap the error and check the provider failure: fix API keys/quota if 401/429.
  2. Retry with backoff for transient (429/5xx/network) failures — the handler is usually retryable.
  3. Reduce input size: chunk messages into smaller sections or use a larger-context model for summarization.
  4. Verify the provider configuration (base URL, model name) in settings/env.
  5. Check ctx deadlines; increase timeout if large summaries are being truncated.

Example fix

// before
summary, err := handler(ctx, text)
if err != nil { return "", err }
// after
summary, err := handler(ctx, text)
if err != nil {
    if errors.Is(err, context.DeadlineExceeded) {
        tctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
        defer cancel()
        return handler(tctx, truncateText(text, maxChunk))
    }
    return "", fmt.Errorf("summarization failed: %w", err)
}
Defensive patterns

Strategy: retry

Validate before calling

if handler == nil {
    return "", fmt.Errorf("no summarizer configured")
}
if err := ctx.Err(); err != nil {
    return "", err
}
if len(text) > maxSummarizationChars {
    text = truncateText(text, maxSummarizationChars) // avoid context-window overflow
}

Type guard

func isRetryableSummaryError(err error) bool {
    var apiErr *openai.Error // or provider-specific error type
    if errors.As(err, &apiErr) {
        return apiErr.HTTPStatusCode == 429 || apiErr.HTTPStatusCode >= 500
    }
    return errors.Is(err, context.DeadlineExceeded) || errors.Is(err, io.ErrUnexpectedEOF)
}

Try / catch

summary, err := GenerateSummary(ctx, humanMsgs, aiMsgs, handler)
if err != nil {
    if isRetryableSummaryError(err) {
        summary, err = retryWithBackoff(3, func() (string, error) {
            return GenerateSummary(ctx, humanMsgs, aiMsgs, handler)
        })
    }
    if err != nil {
        return fallbackSummary(text) // extractive stub instead of failing the chain
    }
}

Prevention

When it happens

Trigger: The injected summarizer handler (LLM invocation) fails during getTaskPrimaryAgentChainSummary, summarizeLastSection, or summarizeQAPairs: provider API returns 401/429/5xx, the request exceeds the model's context window, network timeout, or ctx cancellation.

Common situations: Expired or missing LLM API key; provider rate limits during long-running flows with big message chains; model context window too small for the accumulated messages; transient network failures to the provider endpoint.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/efac70e49b965bd9. Report an issue: GitHub.