siyuan-note/siyuan · error

compaction summary request failed

Error message

compaction summary request failed: %w

What it means

createProtocolCompactionSummary sends a streaming request to the model provider to summarize conversation history for compaction. If establishing the stream via createProtocolStreamWithRetry fails after retries (or times out), the failure is wrapped as 'compaction summary request failed' with the underlying cause.

Solutions

  1. Read the wrapped %w cause to identify the transport/HTTP-level failure
  2. Verify the model provider endpoint, API key, and network connectivity from the kernel host
  3. Retry compaction later — it is retried internally up to maxRetries, so transient outages may self-heal
  4. If the provider is persistently down, reduce session history or run compaction when connectivity is restored
Defensive patterns

Strategy: retry

Validate before calling

// preflight: verify provider reachability
resp, err := http.Get(providerHealthURL)
if err != nil || resp.StatusCode != 200 { /* provider unreachable */ }

Try / catch

if err != nil {
    if errors.Is(err, context.DeadlineExceeded) { /* timeout path */ }
    var apiErr *openai.APIError
    if errors.As(err, &apiErr) { /* inspect status code */ }
}

Prevention

When it happens

Trigger: The model API is unreachable, returns a non-2xx error, the API key is invalid, the request times out, or retry attempts are exhausted when starting the compaction summary stream.

Common situations: Network outages or proxy misconfiguration in the kernel host; expired or missing model provider API keys; provider rate limiting during long sessions; provider endpoint misconfigured in settings.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/ad4888a97838d304. Report an issue: GitHub.

Appendix: source

Thrown at kernel/agent/compaction.go:208

func createProtocolCompactionSummary(ctx context.Context, client *openai.Client, protocol, model, source string,
	maxTokens, maxRetries int, requestTimeout, streamIdleTimeout time.Duration,
	ch chan<- AgentEvent) (summary string, promptTokens, completionTokens int, err error) {
	if maxTokens < compactionSummaryMinTokens {
		return "", 0, 0, errContextCannotBeCompacted
	}

	request := openai.ChatCompletionRequest{
		Model:               model,
		Messages:            compactionSummaryMessages(source),
		MaxCompletionTokens: maxTokens,
		Temperature:         1,
		Stream:              true,
		StreamOptions:       &openai.StreamOptions{IncludeUsage: true},
	}
	stream, firstResponse, cancel, err := createProtocolStreamWithRetry(
		ctx, client, protocol, request, nil, maxRetries, requestTimeout, streamIdleTimeout, delayForCategory, ch)
	if err != nil {
		return "", 0, 0, fmt.Errorf("compaction summary request failed: %w", err)
	}
	defer stream.Close()
	defer cancel()

	var summaryBuilder strings.Builder
	firstResponsePending := true
	for {
		response := firstResponse
		var receiveErr error
		if firstResponsePending {
			firstResponsePending = false
		} else {
			response, receiveErr = recvStreamWithIdleTimeout(stream, streamIdleTimeout, cancel)
		}
		if receiveErr != nil {
			if errors.Is(receiveErr, io.EOF) {
				break
			}

View on GitHub (pinned to 9f775e8a12)