Skip to content

Auto-compaction duplicates the boundary message into the summarizer input #33329

Description

@Robin1987China

Description

select in packages/core/src/session/compaction.ts partitions the conversation into head (the text summarized during auto-compaction) and recent (kept verbatim) at a token budget. When the budget boundary lands mid-message, that message is split into a prefix (head) and suffix (recent).

The split branch sets split = index + 1, and split is then used as both the end of head's full-message slice and the start of recent's slice:

  • head = [...conversation.slice(0, split), splitPrefix]slice(0, index + 1) includes the full boundary message, then splitPrefix (a truncated copy of that same message) is appended. The boundary message appears twice in head.
  • recent = [splitSuffix, ...conversation.slice(split)] → correct.

head is the exact text fed to the summarizer, so whenever the keep-budget boundary lands mid-message (common for a large tool result) the boundary message is sent to the summarizer twice — full and truncated. This wastes input tokens on every overflow-triggered compaction, can push the summary prompt past the context limit so compaction silently fails to recover from overflow, and feeds the summarizer a self-contradictory full-vs-truncated copy.

Steps to reproduce

  1. Have a conversation where the keep-budget boundary falls in the middle of a message (e.g. a large tool result).
  2. Trigger auto-compaction.
  3. The summarizer input (head) contains the boundary message in full AND its truncated prefix — duplicated.

Operating System

macOS

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