Skip to content

Overflow compaction produces incomplete summaries in tool-heavy sessions #20246

@jphpeete

Description

@jphpeete

When a session primarily uses tool-based interactions (e.g. the question tool) rather than direct user messages, overflow compaction produces a summary that only covers the beginning of the conversation.

Steps to reproduce:

  1. Start a session and send one message
  2. Interact extensively through tool calls (question tool, etc.) — the model loops many times creating assistant messages, but no new user messages are created
  3. Hit the provider's context limit (e.g. 200K tokens on GitHub Copilot) so overflow compaction triggers

Expected: The summary covers the full session including all tool interactions.

Actual: The summary only covers the very beginning of the session. All tool interaction context from after the initial user message is lost.

Root cause:
The replay-point search in processCompaction (packages/opencode/src/session/compaction.ts) walks backward looking exclusively for role === "user" messages. In sessions where interactions happen through tool responses (stored as tool parts on assistant messages), user messages are rare. The search skips over all assistant turns and lands on the initial user message, causing messages.slice(0, i) to either produce an empty array (triggering the fallback) or a tiny prefix of the session.

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions