You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compaction currently loses important conversation context and instructions, producing regressions like memory loss after compaction, rules not being followed, and poor continuation in BUILD mode. This epic addresses boundary selection, rules preservation, summary quality, pruning, and observability so conversations remain coherent and safe after compaction.
Problem Statement
Boundary detection uses first prior assistant summary as a hard cut (message-v2.ts:672-680), which can discard too much or wrong context and makes the model forget the current task.
Rules and user constraints (e.g. no git push) are not reliably preserved in the conversational context after compaction.
The current summary prompt is too light to act as a handoff; it lacks detailed structure for continuing work (files, errors/fixes, pending tasks, last action).
Pruning is underutilized and protects the exact region where most tokens accrue (tool calls between last two user turns), leading to premature full compaction instead of selective deletion.
Minimal observability: hard to see which messages/parts are included, and token usage breakdown for tool calls.
Preserve critical context for seamless continuation in BUILD mode.
Keep user rules/constraints alive in the conversation post-compaction.
Reduce token pressure via smarter pruning before resorting to full compaction.
Improve transparency (what was kept/dropped and why).
Non‑Goals
UI redesign of the session view.
Provider-specific tuning beyond ensuring usage accounting and stable headers/options.
Plan / Tasks
Boundary: replace filterCompacted with smarter selection that preserves the last N turns intact (configurable), includes the last assistant message, and then compacts earlier history only.
Rules Preservation: ensure user constraints survive compaction.
Minimal: require the summary to explicitly include a "Rules & Constraints" section capturing active directives (AGENTS.md, permission-sensitive rules, user instructions).
Stretch: introduce a pinned RulesPart to persist constraints across summaries (design spike; may land later).
Summary Prompt: upgrade to a detailed handoff format (primary intent, files touched, code snippets, errors/fixes, pending tasks, current work, rules, optional next step). Use a compact but structured template.
File: packages/opencode/src/session/compaction.ts (user prompt around L169-L178)
Ensure consistency with SystemPrompt.summarize and custom instructions.
Pruning Improvements: make pruning more effective before full compaction.
Revisit PRUNE_PROTECT/PRUNE_MINIMUM and turns-protection strategy; optionally configurable.
Prefer deleting old tool outputs earlier; consider a soft-compaction approach that drops tool call outputs selectively.
Add /status or log output that shows tokens by category (user/assistant/tool/reasoning) to guide tuning.
Summary
Compaction currently loses important conversation context and instructions, producing regressions like memory loss after compaction, rules not being followed, and poor continuation in BUILD mode. This epic addresses boundary selection, rules preservation, summary quality, pruning, and observability so conversations remain coherent and safe after compaction.
Problem Statement
Related Issues
Goals
Non‑Goals
Plan / Tasks
filterCompactedwith smarter selection that preserves the last N turns intact (configurable), includes the last assistant message, and then compacts earlier history only.info.sessionID === input.sessionID(belt-and-suspenders)./statusor log output that shows tokens by category (user/assistant/tool/reasoning) to guide tuning.Definition of Done
Acceptance Tests
git pushwithout permission) and continues coding flows.sessionID.