siyuan-note/siyuan · error

agent compaction summary is empty

Error message

agent compaction summary is empty

What it means

errCompactionSummaryEmpty is returned by createProtocolCompactionSummary when the streaming summary request completed but produced no non-whitespace summary text after trimming. An empty summary would corrupt the compacted context, so the compaction aborts with this sentinel error.

Source

Thrown at kernel/agent/compaction.go:42

	"errors"
	"fmt"
	"io"
	"strings"
	"time"

	"github.com/sashabaranov/go-openai"
	"github.com/siyuan-note/siyuan/kernel/util"
)

const (
	compactionVersion          = 1
	compactionSummaryMinTokens = 256
	compactionSummaryMaxTokens = 2048
	compactionSummaryOverhead  = 128
)

var errContextCannotBeCompacted = errors.New("agent context cannot be compacted enough")
var errCompactionSummaryEmpty = errors.New("agent compaction summary is empty")

func isContextOverflow(err error) bool {
	msg := err.Error()
	return strings.Contains(msg, "context_length_exceeded") ||
		strings.Contains(msg, "maximum context length") ||
		strings.Contains(msg, "reduce the length") ||
		strings.Contains(msg, "too many tokens") ||
		strings.Contains(msg, "input is too long") ||
		strings.Contains(msg, "exceeds the context window") ||
		strings.Contains(msg, "超出上下文") ||
		strings.Contains(msg, "上下文长度")
}

func cloneRuntimeCompaction(compaction *runtimeCompaction) *runtimeCompaction {
	if compaction == nil {
		return nil
	}
	cloned := *compaction

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Retry the compaction — transient empty completions often succeed on a second attempt
  2. Check compactionSummaryMaxTokens (2048) is not set too low in configuration and that the summary model supports content output
  3. Switch the summary/compaction model to a standard chat model that returns delta.Content
  4. Review the summary prompt for constraints that may cause the model to produce no text
Defensive patterns

Strategy: retry

Try / catch

summary, err := createCompactionSummary(ctx, ...)
if errors.Is(err, errCompactionSummaryEmpty) { summary, err = createCompactionSummary(ctx, ...) } // retry once with a different model/prompt if still empty

Prevention

When it happens

Trigger: The summary model streams a response whose accumulated choice delta content is empty or whitespace-only (e.g. the model emits only reasoning/tool tokens, or returns an empty completion) — checked at compaction.go:240 before returning the summary.

Common situations: A model that puts output in a non-content field (e.g. reasoning models with empty delta.Content); a misconfigured summary prompt that the model answers with nothing; a provider hiccup returning empty choices; very low max completion tokens truncating output to nothing.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/2f25f5c8e7e79b8c. Report an issue: GitHub.