{"record":{"id":"ad4888a97838d304","repo":"siyuan-note/siyuan","slug":"compaction-summary-request-failed-w","errorCode":null,"errorMessage":"compaction summary request failed: %w","messagePattern":"compaction summary request failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/agent/compaction.go","lineNumber":208,"sourceCode":"func createProtocolCompactionSummary(ctx context.Context, client *openai.Client, protocol, model, source string,\n\tmaxTokens, maxRetries int, requestTimeout, streamIdleTimeout time.Duration,\n\tch chan<- AgentEvent) (summary string, promptTokens, completionTokens int, err error) {\n\tif maxTokens < compactionSummaryMinTokens {\n\t\treturn \"\", 0, 0, errContextCannotBeCompacted\n\t}\n\n\trequest := openai.ChatCompletionRequest{\n\t\tModel:               model,\n\t\tMessages:            compactionSummaryMessages(source),\n\t\tMaxCompletionTokens: maxTokens,\n\t\tTemperature:         1,\n\t\tStream:              true,\n\t\tStreamOptions:       &openai.StreamOptions{IncludeUsage: true},\n\t}\n\tstream, firstResponse, cancel, err := createProtocolStreamWithRetry(\n\t\tctx, client, protocol, request, nil, maxRetries, requestTimeout, streamIdleTimeout, delayForCategory, ch)\n\tif err != nil {\n\t\treturn \"\", 0, 0, fmt.Errorf(\"compaction summary request failed: %w\", err)\n\t}\n\tdefer stream.Close()\n\tdefer cancel()\n\n\tvar summaryBuilder strings.Builder\n\tfirstResponsePending := true\n\tfor {\n\t\tresponse := firstResponse\n\t\tvar receiveErr error\n\t\tif firstResponsePending {\n\t\t\tfirstResponsePending = false\n\t\t} else {\n\t\t\tresponse, receiveErr = recvStreamWithIdleTimeout(stream, streamIdleTimeout, cancel)\n\t\t}\n\t\tif receiveErr != nil {\n\t\t\tif errors.Is(receiveErr, io.EOF) {\n\t\t\t\tbreak\n\t\t\t}","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/agent/compaction.go#L190-L226","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the wrapped %w cause to identify the transport/HTTP-level failure","Verify the model provider endpoint, API key, and network connectivity from the kernel host","Retry compaction later — it is retried internally up to maxRetries, so transient outages may self-heal","If the provider is persistently down, reduce session history or run compaction when connectivity is restored"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// preflight: verify provider reachability\nresp, err := http.Get(providerHealthURL)\nif err != nil || resp.StatusCode != 200 { /* provider unreachable */ }","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if errors.Is(err, context.DeadlineExceeded) { /* timeout path */ }\n    var apiErr *openai.APIError\n    if errors.As(err, &apiErr) { /* inspect status code */ }\n}","preventionTips":["Monitor provider API keys and quota before long agent sessions","Configure a reachable, reliable provider endpoint in settings","Retry compaction after transient network failures; failures are already retried internally"],"tags":["go","network","llm","streaming"],"backgroundTag":"api-request-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}