siyuan-note/siyuan · error · errContextCannotBeCompacted
%w: the current turn is too large
Error message
%w: the current turn is too large
What it means
After computing compaction candidates via compactionCandidateEntryCounts(sessionEntries, coveredEntryCount, userEntryID), an empty list means the only uncompacted entry is the current (in-flight) user turn, which cannot be summarized. compactContext then returns errContextCannotBeCompacted wrapped with "the current turn is too large". Compaction needs at least one completed entry beyond the current turn to work with.
Source
Thrown at kernel/agent/agent.go:784
inputBudget := contextInputBudget(contextLimit, maxCompletionTokens)
if inputBudget <= 0 {
return false, fmt.Errorf("%w: no input budget remains", errContextCannotBeCompacted)
}
estimatedMessages, _ := projectImageMessages(messages)
if !force && estimateProtocolRequestTokens(model, protocol, estimatedMessages, checkpointMsgs,
compaction, requestTools) <= inputBudget {
return false, nil
}
coveredEntryCount := 0
previousSummary := ""
if compaction != nil {
coveredEntryCount = compaction.CoveredEntryCount
previousSummary = compaction.Summary
}
candidates := compactionCandidateEntryCounts(sessionEntries, coveredEntryCount, userEntryID)
if len(candidates) == 0 {
return false, fmt.Errorf("%w: the current turn is too large", errContextCannotBeCompacted)
}
tail, ok := currentTurnTail(checkpointMsgs, userEntryID, userMessage)
if !ok {
return false, fmt.Errorf("%w: current user turn not found", errContextCannotBeCompacted)
}
nativeResponsesCompaction := util.IsOpenAIResponsesProtocol(protocol) &&
util.SupportsOpenAIResponsesCompaction(ctx)
// 原生 compact 无法限制输出长度,覆盖所有已完成轮次,避免 opaque window 返回后仍超出预算。
selectedCandidateIndex := len(candidates) - 1
if !nativeResponsesCompaction {
selectedCandidateIndex = sort.Search(len(candidates), func(i int) bool {
candidate := candidates[i]
candidateCheckpointMsgs := checkpointMessagesAfterCompaction(sessionEntries, candidate, tail)
candidateMessages := checkpointMessagesToOpenAIWithSummary(
candidateCheckpointMsgs, language, capabilities, nil)
candidateMessages, _ = projectImageMessages(candidateMessages)
baseTokens := estimateProtocolRequestTokens(model, protocol, candidateMessages,View on GitHub (pinned to 8641553a1f)
Solutions
- Split the large request into multiple smaller user turns
- Reduce the size of attachments/tool outputs (truncate pasted content, limit tool result sizes)
- Start a new agent session instead of continuing a fully-compacted one
- Increase the model's context window
Example fix
// before
agent.Send("here is the full 2MB log: " + hugeLog) // single turn exceeds budget
// after
agent.Send("Here are the relevant log excerpts:")
agent.Send(excerpt) // send a trimmed, focused excerpt instead Defensive patterns
Strategy: validation
Validate before calling
estimatedTurn := estimateProtocolRequestTokens(model, protocol, currentTurnMessages, nil, nil, nil)
if estimatedTurn > contextInputBudget(contextLimit, maxCompletionTokens) {
return fmt.Errorf("current turn (~%d tokens) exceeds input budget (%d); split or trim it",
estimatedTurn, contextInputBudget(contextLimit, maxCompletionTokens))
} Try / catch
if err := agent.Send(ctx, msg); errors.Is(err, errContextCannotBeCompacted) &&
strings.Contains(err.Error(), "the current turn is too large") {
// trim/split the message or start a new session, then retry
} Prevention
- Avoid pasting entire files/logs into one turn; send focused excerpts
- Cap tool output sizes so a single turn cannot balloon
- Start a new session once prior turns are mostly compacted
- Pre-estimate turn size for known-large payloads before sending
When it happens
Trigger: A single user turn (plus its tool results) alone exceeds the input budget: there are no prior session entries to compact away because previous ones are already covered by an existing compaction summary (coveredEntryCount), and the current turn cannot be dropped.
Common situations: Pasting a huge document or attaching many large tool outputs in one message; long-running tool calls in one turn generating enormous content; a session where all earlier turns were already summarized and only the giant current turn remains.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
Related errors
- %w: model context length is unknown
- %w: no input budget remains
- agent context cannot be compacted enough: recent messages ex
- agent context cannot be compacted enough: summary input exce
- agent context cannot be compacted enough: compacted context
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/097433fe4856862a.
Report an issue: GitHub.