{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/agent/compaction.go#L190-L226","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: wrong endpoint\nbaseURL = \"https://api.exmaple.com/v1\"\n// after\nbaseURL = \"https://api.example.com/v1\"","handlingStrategy":"retry","validationCode":"if conf.APIKey == \"\" || conf.BaseURL == \"\" { return errors.New(\"AI provider key and base URL must be configured before compaction\") }","typeGuard":null,"tryCatchPattern":"var nerr net.Error\nif errors.As(err, &nerr) && nerr.Timeout() { /* retry with backoff */ }\nif strings.Contains(err.Error(), \"401\") { /* prompt user to fix API key */ }","preventionTips":["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"],"tags":["agent","compaction","network","llm","streaming"],"backgroundTag":"api-request-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}