siyuan-note/siyuan · error

response compaction returned no output

Error message

response compaction returned no output

What it means

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.

Solutions

  1. Verify the compaction request targets a model that supports the Responses API and returns non-empty output (test with curl)
  2. Log compaction.Output raw JSON to check whether the field is named differently (API version drift)
  3. Enable/inspect provider content-filter reasons if output is being suppressed
  4. Retry the compaction; treat persistent empty outputs as a provider configuration problem

Example fix

// before
output, err := MarshalOpenAIResponseOutput(compaction.Output) // len 0 -> error
// after
if len(compaction.Output) == 0 {
    return nil, compaction.Usage, fmt.Errorf("compaction model %s returned empty output; check model/API version", compactionModel)
}
output, err := MarshalOpenAIResponseOutput(compaction.Output)
Defensive patterns

Strategy: validation

Validate before calling

if len(compaction.Output) == 0 {
    return nil, usage, errors.New("compaction produced no output")
}

Try / catch

if err != nil {
    if strings.Contains(err.Error(), "returned no output") {
        // retry once, then fall back to storing the original response
    }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "empty response", "returned no data", "empty embeddings": what HTTP 200-with-empty-body errors mean across libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/7377eaf70686112e. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/openai_completion.go:154

}

func CompactOpenAIResponse(ctx context.Context, client *openai.Client, request openai.ChatCompletionRequest,
	responseInput []any) ([]json.RawMessage, *openai.ResponseUsage, error) {
	responseRequest := openai.CompactResponseRequest{
		Model:        request.Model,
		Input:        responseInput,
		Instructions: firstSystemMessage(request.Messages),
	}
	compaction, err := client.CompactResponse(ctx, responseRequest)
	if err != nil {
		return nil, nil, err
	}
	output, err := MarshalOpenAIResponseOutput(compaction.Output)
	if err != nil {
		return nil, compaction.Usage, err
	}
	if len(output) == 0 {
		return nil, compaction.Usage, errors.New("response compaction returned no output")
	}
	return output, compaction.Usage, nil
}

func MarshalOpenAIResponseOutput(output []any) ([]json.RawMessage, error) {
	if len(output) == 0 {
		return nil, nil
	}
	ret := make([]json.RawMessage, 0, len(output))
	for _, item := range output {
		data, err := json.Marshal(item)
		if err != nil {
			return nil, err
		}
		ret = append(ret, json.RawMessage(data))
	}
	return ret, nil
}

View on GitHub (pinned to 9f775e8a12)