{"record":{"id":"7377eaf70686112e","repo":"siyuan-note/siyuan","slug":"response-compaction-returned-no-output","errorCode":null,"errorMessage":"response compaction returned no output","messagePattern":"response compaction returned no output","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai_completion.go","lineNumber":154,"sourceCode":"}\n\nfunc CompactOpenAIResponse(ctx context.Context, client *openai.Client, request openai.ChatCompletionRequest,\n\tresponseInput []any) ([]json.RawMessage, *openai.ResponseUsage, error) {\n\tresponseRequest := openai.CompactResponseRequest{\n\t\tModel:        request.Model,\n\t\tInput:        responseInput,\n\t\tInstructions: firstSystemMessage(request.Messages),\n\t}\n\tcompaction, err := client.CompactResponse(ctx, responseRequest)\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\toutput, err := MarshalOpenAIResponseOutput(compaction.Output)\n\tif err != nil {\n\t\treturn nil, compaction.Usage, err\n\t}\n\tif len(output) == 0 {\n\t\treturn nil, compaction.Usage, errors.New(\"response compaction returned no output\")\n\t}\n\treturn output, compaction.Usage, nil\n}\n\nfunc MarshalOpenAIResponseOutput(output []any) ([]json.RawMessage, error) {\n\tif len(output) == 0 {\n\t\treturn nil, nil\n\t}\n\tret := make([]json.RawMessage, 0, len(output))\n\tfor _, item := range output {\n\t\tdata, err := json.Marshal(item)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tret = append(ret, json.RawMessage(data))\n\t}\n\treturn ret, nil\n}","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/util/openai_completion.go#L136-L172","documentation":"CompactOpenAIResponse marshals the compaction result's Output array via MarshalOpenAIResponseOutput; when the marshaled output slice is empty, there is nothing to compact into a prompt and the function fails with this error. The API contract expects a compaction to always produce at least one output item.","triggerScenarios":"Calling createResponseCompaction/CompactOpenAIResponse when the provider's compaction response carries an empty (or nil) Output array despite returning success.","commonSituations":"Provider-side quirk where a compaction request returns an empty output list; a model that refused or produced nothing; API drift where output items moved to a different field (e.g. encrypted_content / compacted representation); filtering removed all output items before this check.","solutions":["Log compaction.Output before marshaling to see whether the provider returned anything at all","Retry the compaction request — a transient empty generation often succeeds on retry","Verify the response API version matches the struct field names (Output vs newer compaction fields)","Handle the empty case upstream by skipping compaction for that turn instead of failing the conversation"],"exampleFix":"// before: assume compaction always yields output\noutput, usage, err := CompactOpenAIResponse(ctx, req)\n// after: tolerate an empty compaction\noutput, usage, err := CompactOpenAIResponse(ctx, req)\nif errors.Is(err, errEmptyCompactionOutput) { return fallbackToOriginalHistory(ctx, req) }","handlingStrategy":"try-catch","validationCode":"// pre-check the compaction payload before calling\nif len(compactionOutput) == 0 {\n    return errors.New(\"provider returned an empty compaction output\")\n}","typeGuard":null,"tryCatchPattern":"output, usage, err := CompactOpenAIResponse(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"returned no output\") {\n    return fallbackToOriginalHistory(ctx, req), usage, nil // skip compaction this turn\n}","preventionTips":["Retry compaction once before giving up — empty outputs are often transient","Log the raw compaction response when output is empty","Keep the OpenAI Go SDK version aligned with the provider's response API"],"tags":["api","compaction","empty-response"],"backgroundTag":"empty-api-response","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}