Skip to content

Compaction produces empty summary for Kimi K3-256K since v1.18.15 — conversation history silently dropped #41571

Description

@Ruifeng-Zhang

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, ## Objective text 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

  1. Use kimi-for-coding/k3-256k (any variant) in a long session.
  2. Trigger compaction (auto at ~131k tokens, or manually: POST /session/{id}/summarize with {"providerID":"kimi-for-coding","modelID":"k3-256k"}).
  3. Compaction assistant message has reasoning part only, 0 text parts, output≈40-60.
  4. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions