{"record":{"id":"8fbaa35067113aa0","repo":"siyuan-note/siyuan","slug":"agent-context-cannot-be-compacted-enough-persist","errorCode":null,"errorMessage":"agent context cannot be compacted enough: persist compaction: %v","messagePattern":"agent context cannot be compacted enough: persist compaction: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/agent/agent.go","lineNumber":883,"sourceCode":"\t\t\t\tif summaryErr != nil {\n\t\t\t\t\treturn false, summaryErr\n\t\t\t\t}\n\t\t\t\tnextCompaction, compactionStateErr = newRuntimeProtocolSummaryCompaction(\n\t\t\t\t\tsessionEntries, selectedEntryCount, summary, protocol)\n\t\t\t}\n\t\t\tif compactionStateErr != nil {\n\t\t\t\treturn false, fmt.Errorf(\n\t\t\t\t\t\"%w: build runtime state: %v\", errContextCannotBeCompacted, compactionStateErr)\n\t\t\t}\n\t\t\tnextMessages := checkpointMessagesToOpenAIWithSummary(\n\t\t\t\tselectedCheckpointMsgs, language, capabilities, nextCompaction)\n\t\t\testimatedNextMessages, _ := projectImageMessages(nextMessages)\n\t\t\tif estimateProtocolRequestTokens(model, protocol, estimatedNextMessages, selectedCheckpointMsgs,\n\t\t\t\tnextCompaction, requestTools) > inputBudget {\n\t\t\t\treturn false, fmt.Errorf(\"%w: compacted context still exceeds the input budget\", errContextCannotBeCompacted)\n\t\t\t}\n\t\t\tif err := saveRuntimeCompaction(sessionID, nextCompaction); err != nil {\n\t\t\t\treturn false, fmt.Errorf(\"%w: persist compaction: %v\", errContextCannotBeCompacted, err)\n\t\t\t}\n\t\t\tcompaction = nextCompaction\n\t\t\tcheckpointMsgs = selectedCheckpointMsgs\n\t\t\tmessages = nextMessages\n\t\t\treturn true, nil\n\t\t}\n\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase <-ctx.Done():\n\t\t\t\treturn\n\t\t\tdefault:\n\t\t\t}\n\n\t\t\troundID := fmt.Sprintf(\"%s_%d\", turn.TurnID, modelRound)\n\t\t\tif modelRound == 0 {\n\t\t\t\tsendCriticalEvent(ctx, ch, AgentEvent{Type: \"thinking\", Reasoning: \"analyzing\", RoundID: roundID})\n\t\t\t} else {","sourceCodeStart":865,"sourceCodeEnd":901,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/agent/agent.go#L865-L901","documentation":"This wraps errContextCannotBeCompacted with the underlying persistence failure when saveRuntimeCompaction cannot store the newly computed compaction state for the session. The compaction itself was valid (it fit the budget), but the runtime could not be saved, so the compaction cannot proceed safely.","triggerScenarios":"Inside the compaction loop, after the token check passes, saveRuntimeCompaction(sessionID, nextCompaction) returns a non-nil error (e.g. storage/IO or serialization failure for the session's runtime state), producing \"persist compaction: <cause>\".","commonSituations":"Disk full or unwritable workspace data directory; corrupted or locked session state store; session removed concurrently by another process; database write failure while persisting compaction.","solutions":["Inspect the wrapped cause (%v) to identify the storage failure","Check disk space and write permissions on the workspace data directory","Verify the session still exists and is not locked/being modified concurrently","Retry the request; if persistence keeps failing, start a new session","Check application logs around saveRuntimeCompaction for the underlying error"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if errors.Is(err, errContextCannotBeCompacted) && strings.Contains(err.Error(), \"persist compaction\") {\n    log.Warnf(\"compaction persistence failed: %v\", err)\n    // retry later or fall back to a new session\n}","preventionTips":["Ensure the workspace data directory has free space and write permission","Avoid deleting or moving session state while the agent is running","Monitor storage-layer errors in logs proactively"],"tags":["agent","persistence","compaction","storage"],"backgroundTag":"database-write-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}