Skip to content

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

Closed as not planned

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

Activity

  1. added 2 commits that reference this issue on Jun 30, 2026
    c752d15
    b91d82b
  2. EvolveAegis commented on Aug 1, 2026

    @EvolveAegis

    Confirming this is still reproducible on current main (packages/core/src/session/compaction.ts:148). Adding one observation about the recent tail that may help with the fix:

    When the straddling message is split, the recent array starts with splitSuffix — the tail fragment of the split message, without its role prefix (e.g. [User]:). So the first thing the model sees in the retained context is a mid-message fragment, not a complete message.

    The fix should ensure the straddling message goes entirely to one side (head or recent), or that the split happens at a message boundary rather than mid-message.

  3. github-actions commented on Oct 1, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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