forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Collapse Compaction - preserves recent context while summarizing older messages #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ryanwyler
wants to merge
14
commits into
dev
Choose a base branch
from
feature/collapse-compaction-1.1
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
081bb72 to
209abc8
Compare
481303a to
9a3d5bb
Compare
…dStyle fall back to document.documentElement (anomalyco#9054)
…ith a package manager (anomalyco#9092)
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
9a3d5bb to
b3e33bb
Compare
5ddbfd5 to
18bef8c
Compare
Adds a new 'collapse' compaction method that preserves recent context while summarizing older messages, with intelligent merging of historical summaries. - Selective compression: only compresses oldest 65% of tokens - Historical summary merging: includes previous summaries for context continuity - Breakpoint insertion: places summary at correct position in timeline - TUI toggle: switch between standard/collapse via command palette New file compaction-collapse.ts contains all collapse logic for easy rebasing. Config options: - compaction.method: 'standard' | 'collapse' - compaction.trigger: overflow threshold (default 0.85) - compaction.extractRatio: fraction to extract (default 0.65) - compaction.recentRatio: recent context reference (default 0.15) - compaction.summaryMaxTokens: target summary size (default 10000) - compaction.previousSummaries: history to merge (default 3)
Adds insertTriggers config option to allow compaction methods to control whether they create trigger messages. Standard compaction needs triggers (default: true), but collapse compaction creates its own breakpoint messages and should skip triggers (default: false). This fixes the infinite loop bug where collapse compaction would: 1. Insert breakpoint at timestamp T 2. Create trigger at same timestamp T 3. filterCompacted() would stop at breakpoint 4. Exclude messages after breakpoint with updated token counts 5. Loop would see old token count and trigger again With this fix, collapse compaction directly calls process() without creating triggers, preventing timestamp collisions and ensuring the loop sees the correct post-compaction token counts. Resolves: Infinite compaction loop in ses_43534dcd4ffedAJydNtU3YLQ9S
6a3d42a to
7a421ce
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new "collapse" compaction mode that preserves recent context while summarizing older messages, with intelligent merging of historical summaries across multiple compaction cycles.
The problem: Standard compaction compresses the entire conversation into a tiny summary, causing massive context loss (100% -> 3%). The AI forgets everything. Additionally, when multiple compactions occur, each new summary only knows about messages since the last compaction - historical context from earlier summaries is permanently lost.
The solution: Collapse compaction addresses both problems:
Selective compression - Only compresses OLD, stale messages while keeping recent work pristine:
Historical summary merging - When generating a new summary, includes up to N previous compaction summaries in the prompt, instructing the LLM to merge and consolidate all historical context. This creates a "rolling summary" that carries forward critical knowledge across unlimited compaction cycles:
Changes (v1.1 - Modular Rebase)
This version refactors the collapse logic into a self-contained module for easier future rebasing:
compaction-collapse.tscompaction.tsconfig.tsid/id.tsinsert()function for breakpoint IDsmessage-v2.tsindex.tsxsidebar.tsxtypes.gen.tsKey architectural decision: Bulk of feature (~530 lines) is in
compaction-collapse.tswith minimal touchpoints in existing files. This makes future rebases much easier - just bolt the module back on.Configuration
{ "compaction": { "method": "collapse", "trigger": 0.85, "extractRatio": 0.65, "recentRatio": 0.15, "summaryMaxTokens": 10000, "previousSummaries": 3 } }Default method remains "standard" - users can opt-in to collapse via config or TUI toggle (Ctrl+P -> "Use collapse compaction").
Related
fix/queued-request-processingTesting
compaction.methodto"collapse"in config or toggle via TUI