-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Overflow compaction produces incomplete summaries in tool-heavy sessions #20246
Description
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:
- Start a session and send one message
- Interact extensively through tool calls (question tool, etc.) — the model loops many times creating assistant messages, but no new user messages are created
- 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.