{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/util/openai_completion.go#L136-L172","documentation":"CompactOpenAIResponse calls the OpenAI Responses API to build a compacted summary of a prior response, marshals the returned output items via MarshalOpenAIResponseOutput, and errors if the marshaled output slice is empty. It means the provider reported success but produced zero output items, so there is no compacted content to store.","triggerScenarios":"compaction.Output is an empty/nil []any after a successful compaction API call — the model returned no output items (e.g. response filtered, truncated, or a non-compaction-capable model ignoring the compaction instruction).","commonSituations":"Model or proxy not supporting the Responses compaction input and returning an empty output array; content filtering removing all output; usage of an outdated/incorrect model ID for compaction; API version drift changing the output field name so it parses as empty.","solutions":["Verify the compaction request targets a model that supports the Responses API and returns non-empty output (test with curl)","Log compaction.Output raw JSON to check whether the field is named differently (API version drift)","Enable/inspect provider content-filter reasons if output is being suppressed","Retry the compaction; treat persistent empty outputs as a provider configuration problem"],"exampleFix":"// before\noutput, err := MarshalOpenAIResponseOutput(compaction.Output) // len 0 -> error\n// after\nif len(compaction.Output) == 0 {\n    return nil, compaction.Usage, fmt.Errorf(\"compaction model %s returned empty output; check model/API version\", compactionModel)\n}\noutput, err := MarshalOpenAIResponseOutput(compaction.Output)","handlingStrategy":"validation","validationCode":"if len(compaction.Output) == 0 {\n    return nil, usage, errors.New(\"compaction produced no output\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"returned no output\") {\n        // retry once, then fall back to storing the original response\n    }\n}","preventionTips":["Confirm the compaction model supports the Responses API before enabling the feature","Pin and log the API version; watch for output-shape drift","Fall back to the original (uncompacted) response instead of failing the whole flow"],"tags":["openai","compaction","api-response"],"backgroundTag":"empty-api-response","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"}