{"record":{"id":"4d813fad503001bf","repo":"siyuan-note/siyuan","slug":"w-no-input-budget-remains","errorCode":null,"errorMessage":"%w: no input budget remains","messagePattern":"%w: no input budget remains","errorType":"error_code","errorClass":"errContextCannotBeCompacted","httpStatus":null,"severity":"error","filePath":"kernel/agent/agent.go","lineNumber":768,"sourceCode":"\t\t}\n\t\tcompactionErrorMessage := func(err error) string {\n\t\t\tif errors.Is(err, errContextCannotBeCompacted) || isContextOverflow(err) {\n\t\t\t\treturn kernelModel.Conf.Language(352)\n\t\t\t}\n\t\t\trequestMessages, _ := projectImageMessages(messages)\n\t\t\treturn getAgentRequestErrorMessage(err, requestMessages)\n\t\t}\n\n\t\tcompactContext := func(requestTools []openai.Tool, force bool) (bool, error) {\n\t\t\tif contextLimit <= 0 {\n\t\t\t\tif !force {\n\t\t\t\t\treturn false, nil\n\t\t\t\t}\n\t\t\t\treturn false, fmt.Errorf(\"%w: model context length is unknown\", errContextCannotBeCompacted)\n\t\t\t}\n\t\t\tinputBudget := contextInputBudget(contextLimit, maxCompletionTokens)\n\t\t\tif inputBudget <= 0 {\n\t\t\t\treturn false, fmt.Errorf(\"%w: no input budget remains\", errContextCannotBeCompacted)\n\t\t\t}\n\t\t\testimatedMessages, _ := projectImageMessages(messages)\n\t\t\tif !force && estimateProtocolRequestTokens(model, protocol, estimatedMessages, checkpointMsgs,\n\t\t\t\tcompaction, requestTools) <= inputBudget {\n\t\t\t\treturn false, nil\n\t\t\t}\n\n\t\t\tcoveredEntryCount := 0\n\t\t\tpreviousSummary := \"\"\n\t\t\tif compaction != nil {\n\t\t\t\tcoveredEntryCount = compaction.CoveredEntryCount\n\t\t\t\tpreviousSummary = compaction.Summary\n\t\t\t}\n\t\t\tcandidates := compactionCandidateEntryCounts(sessionEntries, coveredEntryCount, userEntryID)\n\t\t\tif len(candidates) == 0 {\n\t\t\t\treturn false, fmt.Errorf(\"%w: the current turn is too large\", errContextCannotBeCompacted)\n\t\t\t}\n\t\t\ttail, ok := currentTurnTail(checkpointMsgs, userEntryID, userMessage)","sourceCodeStart":750,"sourceCodeEnd":786,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/agent/agent.go#L750-L786","documentation":"compactContext computes inputBudget = contextInputBudget(contextLimit, maxCompletionTokens). If the budget is <= 0 — the reserved completion tokens are not smaller than the model's context limit — there is no room for any input, so it returns errContextCannotBeCompacted wrapped with \"no input budget remains\". Compaction cannot help because even a minimal context would not fit.","triggerScenarios":"maxCompletionTokens >= contextLimit in the agent configuration, so contextInputBudget yields a non-positive budget. Typically a model with a small context window combined with a large max-completion-token setting.","commonSituations":"Pointing the agent at a model with a small context (e.g. 4k) while the completion limit is configured at or above that; misconfigured provider defaults where maxCompletionTokens is inherited from a larger model.","solutions":["Lower the max completion tokens setting so it is well below the model context limit, leaving room for input","Switch to a model with a larger context window","Review contextInputBudget configuration so the budget stays positive"],"exampleFix":"// before\nmaxCompletionTokens = 32768 // with contextLimit = 16384 -> budget <= 0\n// after\nmaxCompletionTokens = 4096 // well below the 16384-token context limit","handlingStrategy":"validation","validationCode":"budget := contextInputBudget(contextLimit, maxCompletionTokens)\nif budget <= 0 {\n    return fmt.Errorf(\"invalid config: maxCompletionTokens (%d) must be smaller than contextLimit (%d)\",\n        maxCompletionTokens, contextLimit)\n}","typeGuard":null,"tryCatchPattern":"if err := agent.Run(ctx, input); errors.Is(err, errContextCannotBeCompacted) &&\n    strings.Contains(err.Error(), \"no input budget remains\") {\n    // lower maxCompletionTokens or raise contextLimit, then retry\n}","preventionTips":["Keep maxCompletionTokens to roughly 25-50% of the model's context limit","Validate completion-token config against context limit when saving AI settings","Match small-context models with small completion budgets","Re-check settings after switching providers/models"],"tags":["agent","compaction","context-window","token-budget"],"backgroundTag":"value-out-of-range","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"}