siyuan-note/siyuan · error
compaction summary request failed: %w
Error message
compaction summary request failed: %w
What it means
Wraps the error from createProtocolStreamWithRetry when the initial compaction summary chat-completion request (streaming, with usage) could not be established after maxRetries attempts. The wrapper identifies the failure as occurring during the summary request phase, before any stream data was received.
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 8641553a1f)
Solutions
- Inspect the wrapped cause (%w) for the concrete network/API error
- Verify the provider API key and base URL in the AI configuration
- Check network connectivity and proxy settings; retry after connectivity is restored
- Increase maxRetries or requestTimeout if the provider is intermittently slow
Example fix
// before: wrong endpoint baseURL = "https://api.exmaple.com/v1" // after baseURL = "https://api.example.com/v1"
Defensive patterns
Strategy: retry
Validate before calling
if conf.APIKey == "" || conf.BaseURL == "" { return errors.New("AI provider key and base URL must be configured before compaction") } Try / catch
var nerr net.Error
if errors.As(err, &nerr) && nerr.Timeout() { /* retry with backoff */ }
if strings.Contains(err.Error(), "401") { /* prompt user to fix API key */ } Prevention
- Validate API key and base URL in settings before long agent sessions
- Configure sensible retry/timeout values for the provider
- Monitor provider status pages; surface connectivity checks at startup
When it happens
Trigger: Calling createCompactionSummary when the underlying LLM HTTP request fails: connection refused, DNS failure, TLS errors, authentication rejection, timeouts exhausted across createProtocolStreamWithRetry retries, or an invalid request body rejected by the API.
Common situations: API endpoint down or unreachable; expired/invalid API key; proxy or firewall blocking the provider; network outage on a mobile/desktop client; wrong base URL configured for the provider.
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
- compaction summary stream failed: %w
- model stream idle timeout
- agent context cannot be compacted enough
- agent compaction summary is empty
- host has no public IP:
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/ad4888a97838d304.
Report an issue: GitHub.