anomalyco / anomalyco/opencode
Compaction produces empty summary for Kimi K3-256K since v1.18.15 — conversation history silently dropped
@nexxeln is already working on this.
Since Aug 10, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Summary
Since v1.18.15, compaction produces empty summaries for Kimi K3-256K (kimi-for-coding/k3-256k): the compaction assistant message contains only a reasoning part and no text part (0 text parts, ~40-60 output tokens), then finishes with reason: stop. The conversation history is then replaced by an empty summary, silently dropping all context.
Other models (gpt-5.x, k2p7, deepseek-v4) compact normally on the same session — this is specific to k3-256k (a reasoning model).
Regression Window
- v1.18.13 / v1.18.14: compaction works (structured output summary,
## Objectivetext part present) - v1.18.15: compaction starts degrading (summary text becomes non-summary content, or empty)
- v1.18.16: fully broken —
output=41~60,0 text parts
The compaction.ts file is identical between 1.18.15 and 1.18.16, and identical between 1.18.13 and 1.18.14. The change was introduced in v1.18.15 ("Repeated compaction now keeps earlier tool-call history in summaries instead of dropping orphaned results").
Root Cause (from code diff v1.18.14 → v1.18.15)
packages/opencode/src/session/compaction.ts, in SessionCompaction.process:
Before (v1.18.14):
const modelMessages = yield* MessageV2.toModelMessagesEffect(msgs, model, {
stripMedia: true,
toolOutputMaxChars: TOOL_OUTPUT_MAX_CHARS,
})
...
messages: [
...modelMessages, // structured history: system/user/assistant roles + tool result blocks
{ role: "user", content: [{ type: "text", text: nextPrompt }] }, // prompt as separate user msg
]
After (v1.18.15+):
const conversation = msgs.map(serialize).filter(Boolean).join("\n\n") // NEW: flatten to plain text
...
messages: [{
role: "user",
content: [{ type: "text", text: [nextPrompt, "The following is the conversation history:", conversation].join("\n\n") }]
}]
A new serialize() helper flattens the whole history into one big plain-text string ([User]: ..., [Assistant]: ..., [Assistant tool call]: ..., [Tool result]: ...) and merges the compaction prompt into a single user message with no role structure.
Why k3-256k breaks
k3-256k is a reasoning model. Given a huge wall of unstructured plain text (11万+ tokens in the failing case), it enters reasoning mode and starts analyzing the content as if it were a coding task instead of summarizing the conversation — the reasoning part in the failing compaction says e.g.:
"The first occurrence (with
mapped ||preceding) was in classifyPostgresPayment; the second in classifyPaymentReversal (memory)..."
Then it emits reason: stop without ever producing a summary text part. opencode marks the message summary: true, treats compaction as complete, and swaps in an empty summary — all prior context is lost. Stronger-following models (gpt-5.x, k2p7, deepseek) still produce ## Objective summaries despite the format change, which is why this looks model-specific.
Repro
- Use
kimi-for-coding/k3-256k(any variant) in a long session. - Trigger compaction (auto at ~131k tokens, or manually:
POST /session/{id}/summarizewith{"providerID":"kimi-for-coding","modelID":"k3-256k"}). - Compaction assistant message has
reasoningpart only,0text parts,output≈40-60. - History is replaced with empty summary — context lost.
Verified on v1.18.16 both via auto-compaction and manual /summarize on a 42万-token session.
Suggested Fix
Restore the structured message format for the compaction prompt (use MessageV2.toModelMessagesEffect output as separate role-typed messages, with nextPrompt as a standalone trailing user message), or keep serialize() only as a fallback for models that cannot consume structured tool results. At minimum, detect empty summaries (no text part) and fail compaction instead of silently discarding history.
Environment
- opencode v1.18.16 (also affected: v1.18.15)
- macOS arm64
- provider: kimi-for-coding / k3-256k
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.